filter room info for valid data only

pull/1/head
parent 5a826c04a6
commit 68dbab1cb6

@ -20,6 +20,9 @@ class Room(models.Model):
def __str__(self):
return self.name
def valid_shifts(self):
return self.shift_set.filter(deleted=False)
class Shift(models.Model):
room = models.ForeignKey(Room, on_delete=models.RESTRICT)
@ -68,6 +71,14 @@ class Shift(models.Model):
).count()
)
def valid_registrations(self):
return self.shiftregistration_set.filter(
state__in=[
ShiftRegistration.RegState.REGISTERED,
ShiftRegistration.RegState.CHECKED_IN,
],
)
class Helper(models.Model):
phone = PhoneNumberField(unique=True, editable=False)

@ -12,10 +12,10 @@
</tr>
</thead>
<tbody>
{% for shift in room.shift_set.all|dictsort:"start_at" %}
{% for shift in room.valid_shifts.all|dictsort:"start_at" %}
<tr>
<td>{{ shift.start_at }}</td>
<td>{% for reg in shift.shiftregistration_set.all %}{{ reg.helper.name }}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
<td>{% for reg in shift.valid_registrations.all %}{{ reg.helper.name }}{% if not forloop.last %}, {% endif %}{% endfor %}</td>
</tr>
{% endfor %}
</tbody>

@ -366,5 +366,10 @@ def mark_as_read(request, pk):
def room_view_token(request, token):
tk = get_object_or_404(RoomViewToken, pk=token)
return render(request, "room_registrations.html", {"room": tk.room})
return render(
request,
"room_registrations.html",
{
"room": get_object_or_404(RoomViewToken, pk=token).room,
},
)

Loading…
Cancel
Save