add current shift and my shifts to overview

pull/1/head
parent 400a0e7d12
commit aa8d4e2db4

@ -2,6 +2,18 @@
{% block title %}Freie Schichten{% endblock %} {% block title %}Freie Schichten{% endblock %}
{% block content %} {% block content %}
{% if current_shift %}
<h2>Aktuelle Schicht</h2>
{{current_shift.shift.room.name }} {{current_shift.shift.start_at}}<a href="{%url 'shift' current_shift.shift.id%}">Details</a>
{% endif %}
{% if my_shifts %}
<h2>Meine Schichten</h2>
<ul>
{% for reg in my_shifts %}
<li>{{ reg.shift.room.name }} {{reg.shift.start_at}}<a href="{%url 'shift' reg.shift.id%}">Details</a></li>
{% endfor %}
</ul>
{% endif %}
<h2>Freie Scchichten:</h2> <h2>Freie Scchichten:</h2>
<ul> <ul>
{% for shift in free_shifts %} {% for shift in free_shifts %}

@ -1,8 +1,10 @@
from django.shortcuts import render, redirect, get_object_or_404 from django.shortcuts import render, redirect, get_object_or_404
from .models import Shift, LoginToken, Helper, ShiftRegistration from .models import Shift, LoginToken, Helper, ShiftRegistration
import datetime import datetime
from django.db.models import F, Count, Q from django.db.models import F, Count, Q, ExpressionWrapper
from .forms import RegisterForm, EmptyForm from .forms import RegisterForm, EmptyForm
from django.db.models.fields import DateTimeField
from pprint import pprint
def index(request): def index(request):
if request.session.get('last_seen_shift'): if request.session.get('last_seen_shift'):
@ -14,6 +16,8 @@ def index(request):
if request.session.get('token'): if request.session.get('token'):
helper = LoginToken.objects.get(pk=request.session['token']).helper helper = LoginToken.objects.get(pk=request.session['token']).helper
context['helper'] = helper context['helper'] = helper
context['my_shifts'] = helper.shiftregistration_set.filter(shift__start_at__gt=datetime.datetime.now()).order_by('shift__start_at')
context['current_shift'] = next(iter(helper.shiftregistration_set.annotate(shift_end=ExpressionWrapper(F('shift__start_at')+F('shift__duration'), output_field=DateTimeField())).filter(shift__start_at__lte=datetime.datetime.now(), shift_end__gte=datetime.datetime.now()).order_by('shift__start_at')[:1]), None)
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=datetime.datetime.now(), free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=datetime.datetime.now(),
room__required_helpers__gt=F('reg_count')).order_by('start_at') room__required_helpers__gt=F('reg_count')).order_by('start_at')
if helper: if helper:

Loading…
Cancel
Save