diff --git a/events/forms.py b/events/forms.py index 39d8c70f..b9df8b91 100644 --- a/events/forms.py +++ b/events/forms.py @@ -1275,6 +1275,8 @@ def __init__(self, event, *args, **kwargs): if isinstance(event, Event2019): self.fields['category'].queryset = Category.objects.filter( pk__in=event.serviceinstance_set.values_list('service__category', flat=True)) + if len(self.fields['category'].queryset) == 1: + self.fields['category'].initial = self.fields['category'].queryset.first() def clean(self): super(MKHoursForm, self).clean() @@ -1347,6 +1349,8 @@ def __init__(self, event, *args, **kwargs): if isinstance(event, Event2019): self.fields['category'].queryset = Category.objects.filter( pk__in=event.serviceinstance_set.values_list('service__category', flat=True)) + if len(self.fields['category'].queryset) == 1: + self.fields['category'].initial = self.fields['category'].queryset.first() self.fields['setup_start'].initial = self.fields['setup_start'].prepare_value( self.event.datetime_setup_complete.replace(second=0, microsecond=0) ) @@ -1825,6 +1829,8 @@ def __init__(self, *args, **kwargs): options.append((event.pk, " %s" % event.event_name)) self.fields['event'] = forms.ChoiceField(choices=options, label="Select Event", widget=forms.RadioSelect) + if len(options) == 1: + self.fields['event'].initial = options[0][0] class CrewCheckoutForm(forms.Form): @@ -1884,6 +1890,8 @@ def __init__(self, *args, **kwargs): min_value=0) hour_set.fields.append(Column('hours_%s' % category.name, css_class="mx-2")) hour_set.fields.append(Column('total', css_class="mx-2")) + if len(categories) == 1: + self.fields['hours_%s' % categories[0].name].initial = self.total_hrs def clean(self): cleaned_data = super(CheckoutHoursForm, self).clean() diff --git a/events/views/flow.py b/events/views/flow.py index 90a15f5f..33cd8008 100644 --- a/events/views/flow.py +++ b/events/views/flow.py @@ -1,12 +1,12 @@ import math -from datetime import timedelta +from datetime import datetime, timedelta from decimal import Decimal from django.conf import settings from django.contrib import messages from django.contrib.auth import get_user_model from django.contrib.auth.decorators import login_required, permission_required from django.core.exceptions import PermissionDenied, ValidationError -from django.db.models import Avg, Count +from django.db.models import Avg, Count, Q from django.forms.models import inlineformset_factory from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404, render @@ -461,8 +461,9 @@ def hours_prefill_self(request, id): if not event.ccinstances.exists(): raise PermissionDenied if event.hours.filter(user=request.user).exists(): - messages.add_message(request, messages.ERROR, 'You already have hours for this event.') + messages.add_message(request, messages.ERROR, 'You are already checked in to this event.') return HttpResponseRedirect(reverse('events:detail', args=(event.id,))) + # return HttpResponseRedirect(reverse('events:crew-checkout')) if timezone.now() < min(event.ccinstances.values_list('setup_start', flat=True)): messages.add_message(request, messages.ERROR, 'You cannot use this feature until the event setup has started.') return HttpResponseRedirect(reverse('events:detail', args=(event.id,))) @@ -503,7 +504,7 @@ def checkin(request): if request.user.event_records.filter(active=True).exists(): context['page'] = {"title": "You are already checked into an event", - "body": "Back"} + "body": "Go to Crew Checkout"} return render(request, 'static_page.html', context) if request.method == 'POST': @@ -1085,6 +1086,10 @@ def viewevent(request, id): context['apps'] = apps + context['can_selfcrew'] = request.user.is_lnl & BaseEvent.objects.filter( + Q(closed=False) & Q(cancelled=False), id=event.id, ccinstances__setup_start__lte=timezone.now(), + datetime_end__gte=(timezone.now() - timedelta(hours=3))).exists() + return render(request, 'uglydetail.html', context) diff --git a/site_tmpl/admin.html b/site_tmpl/admin.html index 34558bdd..baff6a75 100644 --- a/site_tmpl/admin.html +++ b/site_tmpl/admin.html @@ -19,16 +19,13 @@ {% if selfcrew_events.exists %}
-

Mark yourself as crew for an ongoing event

+

Select an event to check in

- Check in - Check out - {% comment %} {% for event in selfcrew_events %} {{ event.event_name }} {% endfor %} - {% endcomment %} + Crew Check Out
{% endif %} @@ -48,6 +45,10 @@

Quick Links

{% if request.user.is_superuser %} Admin {% endif %} + {% if selfcrew_events.exists %} + + + {% endif %} diff --git a/site_tmpl/uglydetail.html b/site_tmpl/uglydetail.html index 0e3262ca..968309a6 100644 --- a/site_tmpl/uglydetail.html +++ b/site_tmpl/uglydetail.html @@ -19,6 +19,9 @@

Status: {{ event.status }}

+ {% permission request.user has 'events.view_event_reports' of event %} PDF {% endpermission %}