diff --git a/RIGS/forms.py b/RIGS/forms.py index 59e9eb01..9ff013b5 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -200,7 +200,6 @@ class EventChecklistForm(forms.ModelForm): related_models = { 'venue': models.Venue, - 'power_mic': models.Profile, } class Meta: diff --git a/RIGS/models.py b/RIGS/models.py index df666fad..1ea40818 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -482,6 +482,15 @@ class Event(models.Model, RevisionMixin): else: return bool(self.purchase_order) + @property + def can_check_in(self): + earliest = self.earliest_time + if isinstance(self.earliest_time, datetime.date): + earliest = datetime.datetime.combine(self.start_date, datetime.time(00, 00)) + tz = pytz.timezone(settings.TIME_ZONE) + earliest = tz.localize(earliest) + return not self.dry_hire and earliest <= timezone.now() + objects = EventManager() def get_absolute_url(self): @@ -921,8 +930,11 @@ class EventCheckIn(models.Model): end_time = models.DateTimeField(null=True) def clean(self): - if self.end_time < self.time: - raise ValidationError("May not check out before you've checked in. Please invent time travel and retry.") + sass = " Please invent time travel and retry." + if self.time > timezone.now(): + raise ValidationError("May not check in in the future." + sass) + if self.end_time and self.end_time < self.time: + raise ValidationError("May not check out before you've checked in." + sass) def active(self): return end_time is not None diff --git a/RIGS/templates/event_detail.html b/RIGS/templates/event_detail.html index d1c873d7..c7965434 100644 --- a/RIGS/templates/event_detail.html +++ b/RIGS/templates/event_detail.html @@ -2,6 +2,7 @@ {% load markdown_tags %} {% load button from filters %} +{% load static %} {% block content %}
@@ -53,7 +54,7 @@
- {% if not event.dry_hire %} + {% if event.can_check_in %}
Crew Record
@@ -66,10 +67,10 @@ Start Time Role End Time - + {% if self.request.user.pk is form.event.mic.pk %} Add{% endif %} - + {% for crew in object.crew.all %} {{crew.person}} @@ -81,7 +82,7 @@ {% empty %} - Apparently this event happened by magic... + Apparently this event happened by magic... {% endfor %} diff --git a/RIGS/templates/hs/eventcheckin_form.html b/RIGS/templates/hs/eventcheckin_form.html index 504b6e40..f1640158 100644 --- a/RIGS/templates/hs/eventcheckin_form.html +++ b/RIGS/templates/hs/eventcheckin_form.html @@ -3,14 +3,47 @@ {% load static %} {% load button from filters %} +{% block css %} + {{ block.super }} + + +{% endblock %} + +{% block preload_js %} + {{ block.super }} + + +{% endblock %} + +{% block js %} + {{ block.super }} + + + +{% endblock %} + {% block content %}
{% include 'form_errors.html' %}
+ {% if not request.is_ajax and self.request.user.pk is form.event.mic.pk %} +
+ +
+ +
+
+ {% else %} + {% endif %} {% csrf_token %}
- {% if edit %} + {% if edit or manual %}
diff --git a/RIGS/templates/partials/event_detail_buttons.html b/RIGS/templates/partials/event_detail_buttons.html index 00695818..d70a0623 100644 --- a/RIGS/templates/partials/event_detail_buttons.html +++ b/RIGS/templates/partials/event_detail_buttons.html @@ -50,7 +50,7 @@ Subhire Insurance Form - {% if not event.dry_hire %} + {% if event.can_check_in %} Check In {% endif %} {% endif %} diff --git a/RIGS/urls.py b/RIGS/urls.py index 6a3dd971..a755b0a2 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -107,6 +107,8 @@ urlpatterns = [ name='event_checkout'), path('event//checkin/edit/', permission_required_with_403('RIGS.change_eventcheckin')(views.EventCheckInEdit.as_view()), name='edit_checkin'), + path('event//checkin/add/', permission_required_with_403('RIGS.add_eventcheckin')(views.EventCheckInOverride.as_view()), + name='event_checkin_override'), # Finance path('invoice/', permission_required_with_403('RIGS.view_invoice')(views.InvoiceIndex.as_view()), diff --git a/RIGS/views/hs.py b/RIGS/views/hs.py index 5b48988a..9027fea3 100644 --- a/RIGS/views/hs.py +++ b/RIGS/views/hs.py @@ -244,6 +244,19 @@ class EventCheckIn(generic.CreateView, ModalURLMixin): return context +class EventCheckInOverride(generic.CreateView): + model = models.EventCheckIn + template_name = 'hs/eventcheckin_form.html' + form_class = forms.EditCheckInForm + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['event'] = models.Event.objects.get(pk=self.kwargs.get('pk')) + context['page_title'] = f'Manually add Check In to Event {context["event"].display_id}' + context['manual'] = True + return context + + class EventCheckInEdit(generic.UpdateView, ModalURLMixin): model = models.EventCheckIn template_name = 'hs/eventcheckin_form.html'