diff --git a/RIGS/models.py b/RIGS/models.py index 44dcd0c1..33d06c59 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -261,15 +261,15 @@ class EventManager(models.Manager): 'venue', 'mic') return events + def active_dry_hires(self): + return self.filter(dry_hire=True, start_date__gte=timezone.now(), is_rig=True) + def rig_count(self): - event_count = self.filter( + event_count = self.exclude(status=BaseEvent.CANCELLED).filter( (models.Q(start_date__gte=timezone.now(), end_date__isnull=True, dry_hire=False, - is_rig=True) & ~models.Q( - status=Event.CANCELLED)) | # Starts after with no end - (models.Q(end_date__gte=timezone.now(), dry_hire=False, is_rig=True) & ~models.Q( - status=Event.CANCELLED)) | # Ends after - (models.Q(dry_hire=True, start_date__gte=timezone.now(), is_rig=True) & ~models.Q( - status=Event.CANCELLED)) # Active dry hire + is_rig=True)) | # Starts after with no end + (models.Q(end_date__gte=timezone.now(), dry_hire=False, is_rig=True)) | # Ends after + (models.Q(dry_hire=True, start_date__gte=timezone.now(), is_rig=True)) # Active dry hire ).count() return event_count @@ -602,15 +602,20 @@ class EventAuthorisation(models.Model, RevisionMixin): class SubhireManager(models.Manager): def current_events(self): - events = self.filter( - (models.Q(start_date__gte=timezone.now(), end_date__isnull=True) & ~models.Q( - status=Event.CANCELLED)) | # Starts after with no end - (models.Q(end_date__gte=timezone.now().date()) & ~models.Q( - status=Event.CANCELLED)) # Ends after + events = self.exclude(status=BaseEvent.CANCELLED).filter( + (models.Q(start_date__gte=timezone.now(), end_date__isnull=True)) | # Starts after with no end + (models.Q(end_date__gte=timezone.now().date())) # Ends after ).order_by('start_date', 'end_date', 'start_time', 'end_time').select_related('person', 'organisation') return events + def event_count(self): + event_count = self.exclude(status=BaseEvent.CANCELLED).filter( + (models.Q(start_date__gte=timezone.now(), end_date__isnull=True)) | # Starts after with no end + (models.Q(end_date__gte=timezone.now())) + ).count() + return event_count + @reversion.register class Subhire(BaseEvent): diff --git a/RIGS/templates/dashboards/productions.html b/RIGS/templates/dashboards/productions.html new file mode 100644 index 00000000..631258df --- /dev/null +++ b/RIGS/templates/dashboards/productions.html @@ -0,0 +1,29 @@ +{% extends 'base_rigs.html' %} + +{% load button from filters %} + +{% block content %} +
+
+
+
Upcoming Events
+
{{ rig_count }}
+ +
+
+
+
+
Upcoming Subhire
+
{{ subhire_count }}
+ +
+
+
+
+
Active Dry Hires
+
{{ hire_count }}
+ +
+
+
+{% endblock %} diff --git a/RIGS/urls.py b/RIGS/urls.py index 8331161a..d3fe3be6 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -77,6 +77,10 @@ urlpatterns = [ path('subhire/upcoming', views.SubhireList.as_view(), name='subhire_list'), + # Dashboards + path('dashboard/productions/', views.ProductionsDashboard.as_view(), + name='productions_dashboard'), + # Event H&S path('event/hs/', permission_required_with_403('RIGS.view_riskassessment')(views.HSList.as_view()), name='hs_list'), diff --git a/RIGS/views/__init__.py b/RIGS/views/__init__.py index 8037ac32..fc21f455 100644 --- a/RIGS/views/__init__.py +++ b/RIGS/views/__init__.py @@ -4,3 +4,4 @@ from .hs import * from .ical import * from .rigboard import * from .subhire import * +from .dashboards import * \ No newline at end of file diff --git a/RIGS/views/dashboards.py b/RIGS/views/dashboards.py new file mode 100644 index 00000000..22ae330c --- /dev/null +++ b/RIGS/views/dashboards.py @@ -0,0 +1,14 @@ +from django.views import generic +from RIGS import models + + +class ProductionsDashboard(generic.TemplateView): + template_name = 'dashboards/productions.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['page_title'] = "Productions Dashboard" + context['rig_count'] = models.Event.objects.rig_count() + context['subhire_count'] = models.Subhire.objects.event_count() + context['hire_count'] = models.Event.objects.active_dry_hires().count() + return context \ No newline at end of file