Group shifts by date

pull/1/head
Luca 3 years ago
parent 964de92b9d
commit 6d2d70e0d5

@ -19,11 +19,21 @@
{% endif %} {% endif %}
{% if free_shifts %} {% if free_shifts %}
<h3 class="title">Freie Schichten</h3> <h3 class="title">Freie Schichten</h3>
<div class="breadcrumb has-bullet-separator">
<ul>
{% for day in days %}
<li><a href="#{{ day|date:"Y-m-d" }}">{{ day|date:"l, d.m.Y" }}</a></li>
{% endfor %}
</ul>
</div>
{% for shifts in free_shifts %}
<h5 class="subtitle" id="{{ shifts.0.start_at|date:"Y-m-d" }}">{{ shifts.0.start_at|date:"l, d.m.Y" }}</h5>
<div class="columns is-multiline"> <div class="columns is-multiline">
{% for shift in free_shifts %} {% for shift in shifts %}
{% include "partials/shift_listitem.html" %} {% include "partials/shift_listitem.html" %}
{% endfor %} {% endfor %}
</div> </div>
{% endfor %}
{% else %} {% else %}
<div class="notification"> <div class="notification">
Alle Schichten sind voll. Schau später noch mal vorbei. Alle Schichten sind voll. Schau später noch mal vorbei.

@ -20,9 +20,10 @@ def index(request):
if request.session.get("last_seen_shift"): if request.session.get("last_seen_shift"):
del request.session["last_seen_shift"] del request.session["last_seen_shift"]
# dont show shifts starting in <60 minutes? context = {
# currently only sorts by date "days": Shift.objects.datetimes("start_at", "day"),
context = {} }
if request.helper: if request.helper:
context["my_future_shifts"] = ( context["my_future_shifts"] = (
reg.shift reg.shift
@ -42,29 +43,24 @@ def index(request):
help_wanted = Q(required_helpers__gt=F("reg_count")) | Q(required_helpers=0) & Q( help_wanted = Q(required_helpers__gt=F("reg_count")) | Q(required_helpers=0) & Q(
room__required_helpers__gt=F("reg_count") room__required_helpers__gt=F("reg_count")
) )
# dont show shifts starting in <60 minutes?
# currently only sorts by date
free_shifts = ( free_shifts = (
Shift.with_reg_count() Shift.with_reg_count()
.filter( .filter(
help_wanted, help_wanted,
start_at__date=day.date(),
start_at__gt=timezone.now(), start_at__gt=timezone.now(),
deleted=False, deleted=False,
) )
.order_by("start_at") .order_by("start_at")
for day in Shift.objects.datetimes("start_at", "day")
) )
if request.helper: if request.helper:
free_shifts = ( free_shifts = (day.filter(~Q(shiftregistration__helper=request.helper)) for day in free_shifts)
Shift.with_reg_count()
.filter(
help_wanted,
start_at__gt=timezone.now(),
deleted=False,
)
.filter(~Q(shiftregistration__helper=request.helper))
.order_by("start_at")
)
context["free_shifts"] = free_shifts context["free_shifts"] = list(map(lambda qs: list(qs), filter(lambda qs: qs.exists(), free_shifts)))
return render(request, "shiftlist.html", context) return render(request, "shiftlist.html", context)

Loading…
Cancel
Save