mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-22 07:52:15 +00:00
Better approach to generic list templates + other deduplication
This commit is contained in:
22
RIGS/hs.py
22
RIGS/hs.py
@@ -100,6 +100,11 @@ class EventChecklistDetail(generic.DetailView):
|
||||
model = models.EventChecklist
|
||||
template_name = 'event_checklist_detail.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EventChecklistDetail, self).get_context_data(**kwargs)
|
||||
context['page_title'] = "Event Checklist for Event {} {}".format(self.object.event.display_id, self.object.event.name)
|
||||
return context
|
||||
|
||||
|
||||
class EventChecklistEdit(generic.UpdateView):
|
||||
model = models.EventChecklist
|
||||
@@ -127,18 +132,6 @@ class EventChecklistCreate(generic.CreateView):
|
||||
template_name = 'event_checklist_form.html'
|
||||
form_class = forms.EventChecklistForm
|
||||
|
||||
"""def get(self, *args, **kwargs):
|
||||
epk = kwargs.get('pk')
|
||||
event = models.Event.objects.get(pk=epk)
|
||||
|
||||
# Check if RA exists
|
||||
ra = models.EventChecklist.objects.filter(event=event).first()
|
||||
|
||||
if ra is not None:
|
||||
return HttpResponseRedirect(reverse_lazy('ec_edit', kwargs={'pk': ra.pk}))
|
||||
|
||||
return super(EventChecklistCreate, self).get(self)"""
|
||||
|
||||
def get_form(self, **kwargs):
|
||||
form = super(EventChecklistCreate, self).get_form(**kwargs)
|
||||
epk = self.kwargs.get('pk')
|
||||
@@ -192,3 +185,8 @@ class HSList(generic.ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
return models.Event.objects.all().order_by('-start_date')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(HSList, self).get_context_data(**kwargs)
|
||||
context['page_title'] = 'H&S Overview'
|
||||
return context
|
||||
|
||||
@@ -335,7 +335,10 @@ class Event(models.Model, RevisionMixin):
|
||||
|
||||
@property
|
||||
def display_id(self):
|
||||
return str("N%05d" % self.pk)
|
||||
if self.is_rig:
|
||||
return str("N%05d" % self.pk)
|
||||
else:
|
||||
return self.pk
|
||||
|
||||
# Calculated values
|
||||
"""
|
||||
@@ -670,15 +673,6 @@ class RiskAssessment(models.Model, RevisionMixin):
|
||||
('review_riskassessment', 'Can review Risk Assessments')
|
||||
]
|
||||
|
||||
"""def clean(self):
|
||||
errdict = {}
|
||||
for field in RiskAssessment._meta.fields:
|
||||
if field.__class__ == forms.BooleanField and self.field is None:
|
||||
errdict[field.name] = ["This field is required"]
|
||||
|
||||
if errdict != {}: # If there was an error when validation
|
||||
raise ValidationError(errdict)"""
|
||||
|
||||
@property
|
||||
def activity_feed_string(self):
|
||||
return str(self.event)
|
||||
@@ -760,28 +754,6 @@ class EventChecklist(models.Model, RevisionMixin):
|
||||
('review_eventchecklist', 'Can review Event Checklists')
|
||||
]
|
||||
|
||||
"""def clean(self):
|
||||
errdict = {}
|
||||
|
||||
if self.power_mic is None:
|
||||
errdict["power_mic"] = ["You must select a Power MIC"]
|
||||
|
||||
if self.earthing is None or self.pat is None:
|
||||
errdict['earthing'] = 'Fill out the electrical checks'
|
||||
|
||||
if self.event_size == 0 and (self.rcds is None or self.supply_test is None):
|
||||
errdict['rcds'] = 'Fill out the small event electrical checks'
|
||||
|
||||
if self.event_size == 1:
|
||||
if self.source_rcd is None or self.labelling is None or self.all_rcds_tested is None or self.public_sockets_tested is None:
|
||||
errdict['source_rcd'] = 'Fill out the medium event electrical checks'
|
||||
|
||||
if self.w1_description is None or self.w1_polarity is None or self.w1_voltage is None or self.w1_earth_fault is None:
|
||||
errdict['w1_description'] = 'Fully complete at least the first worst case point'
|
||||
|
||||
if errdict != {}: # If there was an error when validation
|
||||
raise ValidationError(errdict)"""
|
||||
|
||||
@property
|
||||
def activity_feed_string(self):
|
||||
return str(self.event)
|
||||
|
||||
@@ -44,6 +44,7 @@ class RigboardIndex(generic.TemplateView):
|
||||
|
||||
# call out method to get current events
|
||||
context['events'] = models.Event.objects.current_events()
|
||||
context['page_title'] = "Rigboard"
|
||||
return context
|
||||
|
||||
|
||||
@@ -91,6 +92,7 @@ class EventCreate(generic.CreateView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EventCreate, self).get_context_data(**kwargs)
|
||||
context['page_title'] = "New Event"
|
||||
context['edit'] = True
|
||||
context['currentVAT'] = models.VatRate.objects.current_rate()
|
||||
|
||||
@@ -116,6 +118,7 @@ class EventUpdate(generic.UpdateView):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EventUpdate, self).get_context_data(**kwargs)
|
||||
context['page_title'] = "Event {}".format(self.object.display_id)
|
||||
context['edit'] = True
|
||||
|
||||
form = context['form']
|
||||
@@ -170,6 +173,7 @@ class EventDuplicate(EventUpdate):
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EventDuplicate, self).get_context_data(**kwargs)
|
||||
context['page_title'] = "Duplicate of Event {}".format(self.object.display_id)
|
||||
context["duplicate"] = True
|
||||
return context
|
||||
|
||||
@@ -225,6 +229,7 @@ class EventArchive(generic.ListView):
|
||||
context['start'] = self.request.GET.get('start', None)
|
||||
context['end'] = self.request.GET.get('end', datetime.date.today().strftime('%Y-%m-%d'))
|
||||
context['statuses'] = models.Event.EVENT_STATUS_CHOICES
|
||||
context['page_title'] = 'Event Archive'
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
{% extends 'base_rigs.html' %}
|
||||
{% load static %}
|
||||
|
||||
|
||||
{% block title %}Calendar{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
{% extends 'base_rigs.html' %}
|
||||
{% load paginator from filters %}
|
||||
{% load get_list from filters %}
|
||||
{% load button from filters %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Event Archive{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-select.css' %}"/>
|
||||
{% endblock %}
|
||||
@@ -14,50 +13,44 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h2>Event Archive</h2>
|
||||
</div>
|
||||
<div class="col-sm-12 py-2">
|
||||
<form class="form-inline" method="GET">
|
||||
<div class="input-group mx-2">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Start</span>
|
||||
</div>
|
||||
<input type="date" name="start" id="start" value="{{ start|default_if_none:'' }}" placeholder="Start" class="form-control" />
|
||||
<div class="row">
|
||||
<div class="col-sm-12 py-2">
|
||||
<form class="form-inline" method="GET">
|
||||
<div class="input-group mx-2">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Start</span>
|
||||
</div>
|
||||
<div class="input-group mx-2">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">End</span>
|
||||
</div>
|
||||
<input type="date" name="end" id="end" value="{{ end|default_if_none:'' }}" placeholder="End" class="form-control" />
|
||||
<input type="date" name="start" id="start" value="{{ start|default_if_none:'' }}" placeholder="Start" class="form-control" />
|
||||
</div>
|
||||
<div class="input-group mx-2">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">End</span>
|
||||
</div>
|
||||
<div class="input-group mx-2">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Keyword</span>
|
||||
</div>
|
||||
<input type="search" name="q" placeholder="Keyword" value="{{ request.GET.q }}" class="form-control" />
|
||||
<input type="date" name="end" id="end" value="{{ end|default_if_none:'' }}" placeholder="End" class="form-control" />
|
||||
</div>
|
||||
<div class="input-group mx-2">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">Keyword</span>
|
||||
</div>
|
||||
<select class="selectpicker pr-3" multiple data-actions-box="true" data-none-selected-text="Status" data-actions-box="true" id="status" name="status">
|
||||
{% for status in statuses %}
|
||||
<option value="{{status.0}}" {% if status.0|safe in request.GET|get_list:'status' %}selected=""{% endif %}>{{status.1}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<input type="submit" class="btn btn-primary" value="Search"/>
|
||||
</form>
|
||||
</div>
|
||||
<input type="search" name="q" placeholder="Keyword" value="{{ request.GET.q }}" class="form-control" />
|
||||
</div>
|
||||
<select class="selectpicker pr-3" multiple data-actions-box="true" data-none-selected-text="Status" data-actions-box="true" id="status" name="status">
|
||||
{% for status in statuses %}
|
||||
<option value="{{status.0}}" {% if status.0|safe in request.GET|get_list:'status' %}selected=""{% endif %}>{{status.1}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
{% button 'search' %}
|
||||
</form>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% with object_list as events %}
|
||||
{% include 'event_table.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
{% with object_list as events %}
|
||||
{% include 'partials/event_table.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% paginator %}
|
||||
|
||||
{% if is_paginated %}
|
||||
<div class="row justify-content-center pt-3">
|
||||
{% paginator %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
|
||||
{% block title %}Event Checklist for Event N{{ object.event.pk|stringformat:"05d" }} {{ object.event.name }}{% endblock %}
|
||||
{% load help_text from filters %}
|
||||
{% load profile_by_index from filters %}
|
||||
{% load yesnoi from filters %}
|
||||
{% load button from filters %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row py-3">
|
||||
<div class="col-12">
|
||||
<h3>Event Checklist for Event N{{ object.event.pk|stringformat:"05d" }} {{ object.event.name }}</h3>
|
||||
<div class="row">
|
||||
<div class="col-12 text-right">
|
||||
<a href="{% url 'ec_edit' object.pk %}" class="btn btn-warning my-3"><span class="fas fa-edit"></span> <span
|
||||
class="hidden-xs">Edit</span></a>
|
||||
<div class="col-12 text-right my-3">
|
||||
{% button 'edit' url='ec_edit' pk=object.pk %}
|
||||
{% button 'view' url='event_detail' pk=object.pk text="Event" %}
|
||||
{% include 'partials/review_status.html' with perm=perms.RIGS.review_eventchecklist review='ec_review' %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
@@ -22,7 +22,7 @@
|
||||
<dl class="row">
|
||||
<dt class="col-6">{{ object|help_text:'power_mic' }}</dt>
|
||||
<dd class="col-6">
|
||||
{{ object.power_mic.name }}
|
||||
<a href="{% url 'profile_detail' object.power_mic.pk %}">{{ object.power_mic.name }}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
<p>List vehicles and their drivers</p>
|
||||
@@ -230,10 +230,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 text-right">
|
||||
<a href="{% url 'ec_edit' object.pk %}" class="btn btn-warning my-3"><span class="fas fa-edit"></span> <span
|
||||
class="hidden-xs">Edit</span></a>
|
||||
<a href="{% url 'event_detail' object.event.pk %}" class="btn btn-primary"><span class="fas fa-eye"></span> View Event</a>
|
||||
{{ object.review_string|safe }}
|
||||
{% button 'edit' url='ec_edit' pk=object.pk %}
|
||||
{% button 'view' url='event_detail' pk=object.pk text="Event" %}
|
||||
{% include 'partials/review_status.html' with perm=perms.RIGS.review_eventchecklist review='ec_review' %}
|
||||
</div>
|
||||
<div class="col-12 text-right">
|
||||
{% include 'partials/last_edited.html' with target="eventchecklist_history" %}
|
||||
|
||||
@@ -4,12 +4,6 @@
|
||||
{% load static %}
|
||||
{% load multiply from filters %}
|
||||
|
||||
{% block title %}
|
||||
{% if object.pk %}
|
||||
Event {% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %}
|
||||
{% else %}New Event{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
{{ block.super }}
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap-select.css' %}"/>
|
||||
@@ -131,17 +125,6 @@
|
||||
<form class="form-horizontal itemised_form" role="form" method="POST">
|
||||
{% csrf_token %}
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<h2>
|
||||
{% if duplicate %}
|
||||
Duplicate of Event N{{ object.pk|stringformat:"05d" }}
|
||||
{% elif object.pk %}
|
||||
Event N{{ object.pk|stringformat:"05d" }}
|
||||
{% else %}
|
||||
New Event
|
||||
{% endif %}
|
||||
</h2>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
{% include 'form_errors.html' %}
|
||||
</div>
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
{% load paginator from filters %}
|
||||
{% load button from filters %}
|
||||
|
||||
{% block title %}H&S Overview{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="table-responsive">
|
||||
<table class="table mb-0">
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block title %}Organisations{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<h3>Organisations</h3>
|
||||
</div>
|
||||
{% include 'partials/generic_list.html' with edit="organisation_update" detail="organisation_detail" create="organisation_create" union_account=True %}
|
||||
{% endblock %}
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="col-sm-12 py-3">
|
||||
<div class="card">
|
||||
<div class="card-header">Associated Events</div>
|
||||
{% include 'event_table.html' with events=object.latest_events %}
|
||||
{% include 'partials/event_table.html' with events=object.latest_events %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -4,11 +4,7 @@
|
||||
{% button 'view' view object.pk %}
|
||||
{% button 'edit' edit object.pk %}
|
||||
</div>
|
||||
{% if object.reviewed_by %}
|
||||
<span class='badge badge-success py-2'>Reviewed by <a href='{% url 'profile_detail' object.reviewed_by.pk %}'>{{object.reviewed_by}}</a> at {{object.reviewed_at}}</span>
|
||||
{% elif perm %}
|
||||
<a class='btn btn-success my-2' href='{% url review object.pk %}'>Mark Reviewed</a>
|
||||
{% endif %}
|
||||
{% include 'partials/review_status.html' %}
|
||||
{% elif event != None %}
|
||||
<a href="{% url create event.pk %}" class="btn btn-info"><span class="fas fa-paperclip"></span> <span
|
||||
class="hidden-xs">Create</span></a>
|
||||
|
||||
7
RIGS/templates/partials/review_status.html
Normal file
7
RIGS/templates/partials/review_status.html
Normal file
@@ -0,0 +1,7 @@
|
||||
{% if object.reviewed_by %}
|
||||
<span class='badge badge-success py-2'>Reviewed by <a href='{% url 'profile_detail' object.reviewed_by.pk %}'>{{object.reviewed_by}}</a> at {{object.reviewed_at}}</span>
|
||||
{% elif perm %}
|
||||
<a class='btn btn-success my-2' href='{% url review object.pk %}'>Mark Reviewed</a>
|
||||
{% else %}
|
||||
Not reviewed
|
||||
{% endif %}
|
||||
@@ -1,10 +0,0 @@
|
||||
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
|
||||
|
||||
{% block title %}People{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<h3>People</h3>
|
||||
</div>
|
||||
{% include 'partials/generic_list.html' with edit="person_update" detail="person_detail" create="person_create" %}
|
||||
{% endblock %}
|
||||
@@ -1,22 +1,18 @@
|
||||
{% extends 'base_rigs.html' %}
|
||||
{% load button from filters %}
|
||||
|
||||
{% block title %}Rigboard{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Rigboard</h1>
|
||||
|
||||
<div class="row align-items-center justify-content-between py-2">
|
||||
<div class="col-sm-12 col-md">
|
||||
Key: <span class="table-success mr-1 px-2">Ready</span><span class="table-warning mr-1 px-2">Action Required</span><span class="table-danger mr-1 px-2">Needs MIC</span><span class="table-secondary mr-1 px-2">Cancelled</span><span class="table-info px-2">Non-Rig</span>
|
||||
</div>
|
||||
{% if perms.RIGS.add_event %}
|
||||
<div class="col text-right">
|
||||
{% button 'new' 'event_create' None %}
|
||||
{% button 'new' 'event_create' %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% include 'event_table.html' %}
|
||||
{% include 'partials/event_table.html' %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
|
||||
|
||||
{% block title %}Venues{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<h3>Venues</h3>
|
||||
</div>
|
||||
{% include 'partials/generic_list.html' with edit="venue_update" detail="venue_detail" create="venue_create" %}
|
||||
{% endblock %}
|
||||
@@ -188,28 +188,30 @@ def linkornone(attr, namespace, autoescape=True):
|
||||
return "None"
|
||||
|
||||
|
||||
@register.inclusion_tag('button.html')
|
||||
def button(type, url=None, pk=None, clazz=None, icon=None, text=None):
|
||||
@register.inclusion_tag('partials/button.html')
|
||||
def button(type, url=None, pk=None, clazz="", icon=None, text="", id=None, style=None):
|
||||
if type == 'edit':
|
||||
clazz = "btn-warning"
|
||||
clazz += " btn-warning "
|
||||
icon = "fa-edit"
|
||||
text = "Edit"
|
||||
elif type == 'print':
|
||||
clazz = "btn-primary"
|
||||
clazz += " btn-primary "
|
||||
icon = "fa-print"
|
||||
text = "Print"
|
||||
elif type == 'duplicate':
|
||||
clazz = "btn-info"
|
||||
clazz += " btn-info "
|
||||
icon = "fa-copy"
|
||||
text = "Duplicate"
|
||||
elif type == 'view':
|
||||
clazz = "btn-primary"
|
||||
clazz += " btn-primary "
|
||||
icon = "fa-eye"
|
||||
text = "View"
|
||||
text = "View " + text
|
||||
elif type == 'new':
|
||||
clazz = "btn-primary"
|
||||
clazz += " btn-primary "
|
||||
icon = "fa-plus"
|
||||
text = "New"
|
||||
elif type == 'search':
|
||||
return {'submit': True, 'class': 'btn-info', 'icon': 'fa-search', 'text': 'Search', 'id': id, 'style': style}
|
||||
elif type == 'submit':
|
||||
return {'submit': True, 'class': 'btn-primary', 'icon': 'fa-save', 'text': 'Save'}
|
||||
return {'target': url, 'id': pk, 'class': clazz, 'icon': icon, 'text': text}
|
||||
return {'submit': True, 'class': 'btn-primary', 'icon': 'fa-save', 'text': 'Save', 'id': id, 'style': style}
|
||||
return {'target': url, 'pk': pk, 'class': clazz, 'icon': icon, 'text': text, 'id': id, 'style': style}
|
||||
|
||||
@@ -24,9 +24,16 @@ from PyRIGS.views import GenericListView
|
||||
|
||||
|
||||
class PersonList(GenericListView):
|
||||
template_name = 'person_list.html'
|
||||
model = models.Person
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(PersonList, self).get_context_data(**kwargs)
|
||||
context['page_title'] = "People"
|
||||
context['create'] = 'person_create'
|
||||
context['edit'] = 'person_update'
|
||||
context['detail'] = 'person_detail'
|
||||
return context
|
||||
|
||||
|
||||
class PersonDetail(generic.DetailView):
|
||||
template_name = 'person_detail.html'
|
||||
@@ -70,9 +77,15 @@ class PersonUpdate(generic.UpdateView):
|
||||
|
||||
|
||||
class OrganisationList(GenericListView):
|
||||
template_name = 'organisation_list.html'
|
||||
model = models.Organisation
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(OrganisationList, self).get_context_data(**kwargs)
|
||||
context['create'] = 'organisation_create'
|
||||
context['edit'] = 'organisation_update'
|
||||
context['detail'] = 'organisation_detail'
|
||||
context['union_account'] = True
|
||||
return context
|
||||
|
||||
class OrganisationDetail(generic.DetailView):
|
||||
template_name = 'organisation_detail.html'
|
||||
@@ -116,9 +129,15 @@ class OrganisationUpdate(generic.UpdateView):
|
||||
|
||||
|
||||
class VenueList(GenericListView):
|
||||
template_name = "venue_list.html"
|
||||
model = models.Venue
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(VenueList, self).get_context_data(**kwargs)
|
||||
context['create'] = 'venue_create'
|
||||
context['edit'] = 'venue_update'
|
||||
context['detail'] = 'venue_detail'
|
||||
return context
|
||||
|
||||
|
||||
class VenueDetail(generic.DetailView):
|
||||
template_name = 'venue_detail.html'
|
||||
|
||||
Reference in New Issue
Block a user