diff --git a/RIGS/models/events.py b/RIGS/models/events.py index d75f1e7c..151dd606 100644 --- a/RIGS/models/events.py +++ b/RIGS/models/events.py @@ -17,7 +17,30 @@ from .utils import filter_by_pk from .finance import VatRate -class EventManager(models.Manager): +class BaseEventManager(models.Manager): + def event_search(self, q, start, end, status): + filt = Q() + if end: + filt &= Q(start_date__lte=end) + if start: + filt &= Q(start_date__gte=start) + + objects = self.all() + + if q: + objects = self.search(q) + + if len(status) > 0: + filt &= Q(status__in=status) + + qs = objects.filter(filt).order_by('-start_date') + + # Preselect related for efficiency + qs.select_related('person', 'organisation', 'venue', 'mic') + + return qs + +class EventManager(BaseEventManager): def current_events(self): events = self.filter( (models.Q(start_date__gte=timezone.now(), end_date__isnull=True, dry_hire=False) & ~models.Q( @@ -390,7 +413,7 @@ class EventAuthorisation(models.Model, RevisionMixin): return f"{self.event.display_id} (requested by {self.sent_by.initials})" -class SubhireManager(models.Manager): +class SubhireManager(BaseEventManager): def current_events(self): events = self.exclude(status=BaseEvent.CANCELLED).filter( (models.Q(start_date__gte=timezone.now(), end_date__isnull=True)) | # Starts after with no end @@ -406,7 +429,6 @@ class SubhireManager(models.Manager): ).count() return event_count - @reversion.register class Subhire(BaseEvent): insurance_value = models.DecimalField(max_digits=10, decimal_places=2) # TODO Validate if this is over notifiable threshold diff --git a/RIGS/templates/event_archive.html b/RIGS/templates/event_archive.html index ae3c0a1c..899748d3 100644 --- a/RIGS/templates/event_archive.html +++ b/RIGS/templates/event_archive.html @@ -15,36 +15,7 @@ {% endblock %} {% block content %} -
| # | +Dates & Times | +Hire Details | +Associated Event(s) | + {% if perms.RIGS.subhire_finance %} +Insurance Value | + {% endif %} +
|---|---|---|---|---|
| {{ event.display_id }} | + +
+ Start: {{ event.start_date|date:"D d/m/Y" }}
+ {% if event.has_start_time %}
+ {{ event.start_time|date:"H:i" }}
+ {% endif %}
+
+ {% if event.end_date %}
+ + End: {% if event.end_date != event.start_date %}{{ event.end_date|date:"D d/m/Y" }}{% endif %} + {% if event.has_end_time %} + {{ event.end_time|date:"H:i" }} + {% endif %} + + {% endif %} + |
+
+
+ + + {{ event.name }} + +++ Primary Contact: {{ event.person|linked_name }} + {% if event.organisation %} + ({{ event.organisation|linked_name }}) + {% endif %} ++ {% if not event.cancelled and event.description %} +{{ event.description|markdown }} + {% endif %} + {% include 'partials/event_status.html' %} + |
+
+
|
+ {% if perms.RIGS.subhire_finance %}
+ + £{{ event.insurance_value }} + | + {% endif %} +
| No events found | +||||
| + | + | + | Total Value: | +£{{ total_value }} | +