Initial work on productions dashboard

This commit is contained in:
2022-12-16 14:06:06 +00:00
parent eb07990f4c
commit e100f5a1d4
5 changed files with 65 additions and 12 deletions

View File

@@ -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):

View File

@@ -0,0 +1,29 @@
{% extends 'base_rigs.html' %}
{% load button from filters %}
{% block content %}
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-header">Upcoming Events</div>
<div class="card-body">{{ rig_count }}</div>
<div class="card-footer"><a href={% url 'rigboard' %}>View</a></div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">Upcoming Subhire</div>
<div class="card-body">{{ subhire_count }}</div>
<div class="card-footer"><a href={% url 'subhire_list' %}>View</a></div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">Active Dry Hires</div>
<div class="card-body">{{ hire_count }}</div>
<div class="card-footer"><a href={% url 'rigboard' %}>View</a></div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -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'),

View File

@@ -4,3 +4,4 @@ from .hs import *
from .ical import *
from .rigboard import *
from .subhire import *
from .dashboards import *

14
RIGS/views/dashboards.py Normal file
View File

@@ -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