diff --git a/shiftregister/team/admin.py b/shiftregister/team/admin.py index 1c8ba9d..8fdc41e 100644 --- a/shiftregister/team/admin.py +++ b/shiftregister/team/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import IncomingMessage +from .models import IncomingMessage, RoomViewToken # Register your models here. @@ -8,3 +8,9 @@ from .models import IncomingMessage class IncomingMessageAdmin(admin.ModelAdmin): list_display = ("sender", "created_at") readonly_fields = ("id", "sender", "content", "created_at", "read") + + +@admin.register(RoomViewToken) +class RoomViewTokenAdmin(admin.ModelAdmin): + list_display = ("room", "id") + readonly_fields = ("id", "url") diff --git a/shiftregister/team/migrations/0004_roomviewtoken.py b/shiftregister/team/migrations/0004_roomviewtoken.py new file mode 100644 index 0000000..015db92 --- /dev/null +++ b/shiftregister/team/migrations/0004_roomviewtoken.py @@ -0,0 +1,37 @@ +# Generated by Django 4.0.4 on 2023-05-18 15:15 + +from django.db import migrations, models +import django.db.models.deletion +import shiftregister.team.models + + +class Migration(migrations.Migration): + + dependencies = [ + ("app", "0011_room_description"), + ("team", "0003_incomingmessage_read_and_more"), + ] + + operations = [ + migrations.CreateModel( + name="RoomViewToken", + fields=[ + ( + "id", + models.CharField( + default=shiftregister.team.models.gen_token, + editable=False, + max_length=20, + primary_key=True, + serialize=False, + ), + ), + ( + "room", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="app.room" + ), + ), + ], + ), + ] diff --git a/shiftregister/team/models.py b/shiftregister/team/models.py index 7005c1e..8542443 100644 --- a/shiftregister/team/models.py +++ b/shiftregister/team/models.py @@ -1,6 +1,7 @@ from django.db import models from phonenumber_field.modelfields import PhoneNumberField from shiftregister.app.models import * +import secrets # Create your models here. @@ -25,3 +26,23 @@ class IncomingMessage(models.Model): def display_sender(self): helper = self.from_helper() return helper.name if helper else self.sender + + +def gen_token(): + return secrets.token_urlsafe(15) + + +class RoomViewToken(models.Model): + id = models.CharField( + max_length=20, primary_key=True, default=gen_token, editable=False + ) + room = models.ForeignKey(Room, on_delete=models.CASCADE) + + def __str__(self): + return f"{self.room.name} {self.id}" + + def url(self): + return "https://helfen.kntkt.de" + reverse( + "team:room_view_token", + kwargs={"token": self.id}, + ) diff --git a/shiftregister/team/templates/room_registrations.html b/shiftregister/team/templates/room_registrations.html new file mode 100644 index 0000000..2aba3bc --- /dev/null +++ b/shiftregister/team/templates/room_registrations.html @@ -0,0 +1,25 @@ +{% extends "base.html" %} + +{% block everything %} +
+
+

Helfer:innen für {{ room.name }}

+ + + + + + + + +{% for shift in room.shift_set.all|dictsort:"start_at" %} + + + + +{% endfor %} + +
StartzeitHelfer:innen
{{ shift.start_at }}{% for reg in shift.shiftregistration_set.all %}{{ reg.helper.name }}{% if not forloop.last %}, {% endif %}{% endfor %}
+
+
+{% endblock %} \ No newline at end of file diff --git a/shiftregister/team/urls.py b/shiftregister/team/urls.py index ab4b558..add3402 100644 --- a/shiftregister/team/urls.py +++ b/shiftregister/team/urls.py @@ -19,4 +19,5 @@ urlpatterns = [ path("incoming/", views.incoming_messages, name="incoming_messages"), path("incoming/", views.incoming_message, name="incoming_message"), path("incoming/mark_as_read/", views.mark_as_read, name="mark_as_read"), + path("list/", views.room_view_token, name="room_view_token"), ] diff --git a/shiftregister/team/views.py b/shiftregister/team/views.py index 43f55b1..f72f25d 100644 --- a/shiftregister/team/views.py +++ b/shiftregister/team/views.py @@ -3,7 +3,15 @@ from django.contrib.auth.decorators import login_required from django.utils import timezone from django.db.models.fields import DateTimeField from django.db.models import F, Count, Q, ExpressionWrapper, Case, When -from .models import ShiftRegistration, Room, Shift, Helper, Message, IncomingMessage +from .models import ( + ShiftRegistration, + Room, + Shift, + Helper, + Message, + IncomingMessage, + RoomViewToken, +) from django.views.generic import DetailView, ListView from django.views.generic.edit import FormMixin from django.contrib.auth.mixins import LoginRequiredMixin @@ -355,3 +363,8 @@ def mark_as_read(request, pk): IncomingMessage.objects.filter(sender=helper.phone).update(read=True) return redirect("team:helper", pk=pk) + + +def room_view_token(request, token): + tk = get_object_or_404(RoomViewToken, pk=token) + return render(request, "room_registrations.html", {"room": tk.room})