From a95779e04e6677be94424d8592c139002543ba03 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Wed, 16 Feb 2022 15:01:38 +0000 Subject: [PATCH] FEAT: Add ability to generate RA printouts --- PyRIGS/views.py | 56 ++++ RIGS/models.py | 9 +- RIGS/templates/base_print.xml | 139 ++++++++ RIGS/templates/event_checklist_detail.html | 252 --------------- RIGS/templates/event_checklist_form.html | 355 --------------------- RIGS/templates/event_print.xml | 139 +------- RIGS/templates/event_print_page.xml | 4 +- RIGS/templates/hs_list.html | 52 --- RIGS/templates/hs_object_list.html | 59 ---- RIGS/templates/partials/event_status.html | 2 +- RIGS/templates/risk_assessment_detail.html | 167 ---------- RIGS/templates/risk_assessment_form.html | 176 ---------- RIGS/urls.py | 1 + RIGS/views/hs.py | 24 +- RIGS/views/rigboard.py | 55 +--- 15 files changed, 236 insertions(+), 1254 deletions(-) create mode 100644 RIGS/templates/base_print.xml delete mode 100644 RIGS/templates/event_checklist_detail.html delete mode 100644 RIGS/templates/event_checklist_form.html delete mode 100644 RIGS/templates/hs_list.html delete mode 100644 RIGS/templates/hs_object_list.html delete mode 100644 RIGS/templates/risk_assessment_detail.html delete mode 100644 RIGS/templates/risk_assessment_form.html diff --git a/PyRIGS/views.py b/PyRIGS/views.py index 148a4c9b..dcf2d02c 100644 --- a/PyRIGS/views.py +++ b/PyRIGS/views.py @@ -1,8 +1,18 @@ import datetime import operator +import re +import urllib.error +import urllib.parse +import urllib.request + from functools import reduce from itertools import chain +from io import BytesIO +from PyPDF2 import PdfFileMerger, PdfFileReader +from z3c.rml import rml2pdf + +from django.conf import settings from django.contrib.auth.decorators import login_required from django.contrib import messages from django.core import serializers @@ -13,6 +23,8 @@ from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy, reverse, NoReverseMatch from django.views import generic from django.views.decorators.clickjacking import xframe_options_exempt +from django.template.loader import get_template +from django.utils import timezone from RIGS import models from assets import models as asset_models @@ -300,3 +312,47 @@ class OEmbedView(generic.View): } return JsonResponse(data) + + +class PrintView(generic.View): + append_terms = False + + def get_context_data(self, **kwargs): + obj = get_object_or_404(self.model, pk=self.kwargs['pk']) + user_str = f"by {self.request.user.name} " if self.request.user is not None else "" + time = timezone.now().strftime('%d/%m/%Y %H:%I') + object_name = re.sub(r'[^a-zA-Z0-9 \n\.]', '', obj.name) + + context = { + 'object': obj, + 'current_user': self.request.user, + 'object_name': object_name, + 'info_string': f"[Paperwork generated {user_str}on {time} - {obj.current_version_id}]", + } + + return context + + def get(self, request, pk): + template = get_template(self.template_name) + + merger = PdfFileMerger() + + context = self.get_context_data() + + rml = template.render(context) + buffer = rml2pdf.parseString(rml) + merger.append(PdfFileReader(buffer)) + buffer.close() + + if self.append_terms: + terms = urllib.request.urlopen(settings.TERMS_OF_HIRE_URL) + merger.append(BytesIO(terms.read())) + + merged = BytesIO() + merger.write(merged) + + response = HttpResponse(content_type='application/pdf') + f = context['filename'] + response['Content-Disposition'] = f'filename="{f}"' + response.write(merged.getvalue()) + return response diff --git a/RIGS/models.py b/RIGS/models.py index ac9d9e70..afb7c520 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -792,15 +792,22 @@ class RiskAssessment(models.Model, RevisionMixin): else: return self.SMALL[0] + def get_event_size_display(self): + return self.SIZES[self.event_size][1] + " Event" + @property def activity_feed_string(self): return str(self.event) + @property + def name(self): + return str(self) + def get_absolute_url(self): return reverse('ra_detail', kwargs={'pk': self.pk}) def __str__(self): - return f"{self.pk} - {self.event}" + return f"{self.pk} | {self.event}" @reversion.register(follow=['vehicles', 'crew']) diff --git a/RIGS/templates/base_print.xml b/RIGS/templates/base_print.xml new file mode 100644 index 00000000..915d9c43 --- /dev/null +++ b/RIGS/templates/base_print.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {##} + + + + + + {# #} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {% block content %} + {% endblock %} + + + diff --git a/RIGS/templates/event_checklist_detail.html b/RIGS/templates/event_checklist_detail.html deleted file mode 100644 index 98b1c815..00000000 --- a/RIGS/templates/event_checklist_detail.html +++ /dev/null @@ -1,252 +0,0 @@ -{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %} -{% load help_text from filters %} -{% load profile_by_index from filters %} -{% load yesnoi from filters %} -{% load button from filters %} - -{% block content %} -
-
- {% button 'edit' url='ec_edit' pk=object.pk %} - {% button 'view' url='event_detail' pk=object.event.pk text="Event" %} - {% include 'partials/review_status.html' with perm=perms.RIGS.review_eventchecklist review='ec_review' %} -
-
-
-
-
-
General
-
-
-
Date
-
- {{ object.date }} -
-
Venue
-
- {% if object.venue %} - - {{ object.venue }} - - {% endif %} -
-
{{ object|help_text:'power_mic' }}
-
- {% if object.power_mic %} - {{ object.power_mic.name }} - {% else %} - None - {% endif %} -
-
-

List vehicles and their drivers

-
    - {% for i in object.vehicles.all %} -
  • {{i}}
  • - {% endfor %} -
-
-
-
-
-
-
Safety Checks
-
-
-
{{ object|help_text:'safe_parking'|safe }}
-
- {{ object.safe_parking|yesnoi }} -
-
{{ object|help_text:'safe_packing'|safe }}
-
- {{ object.safe_packing|yesnoi }} -
-
{{ object|help_text:'exits'|safe }}
-
- {{ object.exits|yesnoi }} -
-
{{ object|help_text:'trip_hazard'|safe }}
-
- {{ object.trip_hazard|yesnoi }} -
-
{{ object|help_text:'warning_signs'|safe }}
-
- {{ object.warning_signs|yesnoi }} -
-
{{ object|help_text:'ear_plugs'|safe }}
-
- {{ object.ear_plugs|yesnoi }} -
-
-
-
-
-
-
-
Crew Record
-
- - - - - - - - - - - {% for crew in object.crew.all %} - - - - - - - {% empty %} - - - - {% endfor %} - -
CrewmemberStart TimeRoleEnd Time
{{crew.crewmember}}{{crew.start}}{{crew.role}}{{crew.end}}
Apparently this event happened by magic...
-
-
-
-
Power {% include 'partials/event_size.html' with object=object.event.riskassessment %}
-
- {% if object.event.riskassessment.event_size == 0 %} -
-
{{ object|help_text:'rcds'|safe }}
-
- {{ object.rcds|yesnoi }} -
-
{{ object|help_text:'supply_test'|safe }}
-
- {{ object.supply_test|yesnoi }} -
-
{{ object|help_text:'earthing'|safe }}
-
- {{ object.earthing|yesnoi }} -
-
{{ object|help_text:'pat'|safe }}
-
- {{ object.pat|yesnoi }} -
-
- {% else %} -
-
{{ object|help_text:'source_rcd'|safe }}
-
- {{ object.source_rcd|yesnoi }} -
-
{{ object|help_text:'labelling'|safe }}
-
- {{ object.labelling|yesnoi }} -
-
{{ object|help_text:'earthing'|safe }}
-
- {{ object.earthing|yesnoi }} -
-
{{ object|help_text:'pat'|safe }}
-
- {{ object.pat|yesnoi }} -
-
-
-

Tests at first distro

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestValue
Voltage
(cube meter)
{{ object|help_text:'fd_voltage_l1' }}{{ object|help_text:'fd_voltage_l2' }}{{ object|help_text:'fd_voltage_l3' }}
{{ object.fd_voltage_l1 }}{{ object.fd_voltage_l2 }}{{ object.fd_voltage_l3 }}
{{ object|help_text:'fd_phase_rotation'|safe }}{{ object.fd_phase_rotation|yesnoi }}
{{ object|help_text:'fd_earth_fault'|safe}}{{ object.fd_earth_fault }}
{{ object|help_text:'fd_pssc'}}{{ object.fd_pssc }}
-
-

Tests at 'Worst Case' points (at least 1 point required)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestPoint 1Point 2Point 3
{{ object|help_text:'w1_description'|safe}}{{ object.w1_description }}{{ object.w2_description|default:'' }}{{ object.w3_description|default:'' }}
{{ object|help_text:'w1_polarity'|safe}}{{ object.w1_polarity|yesnoi }}{{ object.w2_polarity|default:''|yesnoi }}{{ object.w3_polarity|default:''|yesnoi }}
{{ object|help_text:'w1_voltage'|safe}}{{ object.w1_voltage }}{{ object.w2_voltage|default:'' }}{{ object.w3_voltage|default:'' }}
{{ object|help_text:'w1_earth_fault'|safe}}{{ object.w1_earth_fault }}{{ object.w2_earth_fault|default:'' }}{{ object.w3_earth_fault|default:'' }}
-
-
-
{{ object|help_text:'all_rcds_tested'|safe }}
-
- {{ object.all_rcds_tested|yesnoi }} -
-
{{ object|help_text:'public_sockets_tested'|safe }}
-
- {{ object.public_sockets_tested|yesnoi }} -
-
-
- {% include 'partials/ec_power_info.html' %} - {% endif %} -
-
-
-{% 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' %} -
-
-{% include 'partials/last_edited.html' with target="eventchecklist_history" %} -
-{% endblock %} diff --git a/RIGS/templates/event_checklist_form.html b/RIGS/templates/event_checklist_form.html deleted file mode 100644 index 6db9f398..00000000 --- a/RIGS/templates/event_checklist_form.html +++ /dev/null @@ -1,355 +0,0 @@ -{% extends request.is_ajax|yesno:'base_ajax.html,base_rigs.html' %} -{% load widget_tweaks %} -{% load static %} -{% load help_text from filters %} -{% load profile_by_index from filters %} -{% 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 edit %} -
- {% else %} - - {% endif %} - - {% csrf_token %} -
-
-
-
Event Information
-
-
-
Event Date
-
{{ event.start_date}}{%if event.end_date %}-{{ event.end_date}}{%endif%}
-
Event Name
-
{{ event.name }}
-
Client
-
{{ event.person }}
-
Event Size
-
{% include 'partials/event_size.html' with object=event.riskassessment %}
-
-
- - {% if not form.date.value %} - {% render_field form.date class+="form-control col-8" value=event.start_date %} - {% else %} - {% render_field form.date class+="form-control col-8" %} - {% endif %} -
-
- - -
-
- - -
-

List vehicles and their drivers

-
- - - - - - - - - - - - - - - {% for i in object.vehicles.all %} - - - - - - {% endfor %} - -
VehicleDriver
- -
-
-
- -
-
-
-
-
-
-
-
-
Safety Checks
-
- {% include 'partials/checklist_checkbox.html' with formitem=form.safe_parking %} - {% include 'partials/checklist_checkbox.html' with formitem=form.safe_packing %} - {% include 'partials/checklist_checkbox.html' with formitem=form.exits %} - {% include 'partials/checklist_checkbox.html' with formitem=form.trip_hazard %} - {% include 'partials/checklist_checkbox.html' with formitem=form.warning_signs %} - {% include 'partials/checklist_checkbox.html' with formitem=form.ear_plugs %} -
- - {% render_field form.hs_location class+="form-control col-7 col-md-4" %} -
-
- - {% render_field form.extinguishers_location class+="form-control col-7 col-md-4" %} -
-
-
-
-
-
-
-
-
Crew Record
-
-
- - - - - - - - - - - - - - - - - - - {% for crew in object.crew.all %} - - - - - - - - {% endfor %} - -
PersonStart TimeRoleEnd Time
- -
-
-
- -
-
-
- {% if event.riskassessment.event_size == 0 %} -
-
-
-
Electrical Checks for ‘Small’ TEC Events <6kVA (approx. 26A)
-
- {% include 'partials/checklist_checkbox.html' with formitem=form.rcds %} - {% include 'partials/checklist_checkbox.html' with formitem=form.supply_test %} - {% include 'partials/checklist_checkbox.html' with formitem=form.earthing %} - {% include 'partials/checklist_checkbox.html' with formitem=form.pat %} -
-
-
-
- {% else %} -
-
- {% if event.riskassessment.event_size == 1 %} -
-
Electrical Checks for ‘Medium’ TEC Events
-
- {% else %} -
-
Electrical Checks for ‘Large’ TEC Events
-
-
Here be dragons. Ensure you have appeased the Power Gods before continuing... (If you didn't check with a Supervisor, you cannot continue your event!)
- {% endif %} - {% include 'partials/checklist_checkbox.html' with formitem=form.source_rcd %} - {% include 'partials/checklist_checkbox.html' with formitem=form.labelling %} - {% include 'partials/checklist_checkbox.html' with formitem=form.earthing %} - {% include 'partials/checklist_checkbox.html' with formitem=form.pat %} -
-

Tests at first distro

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestValue
Voltage
(cube meter)
{{ form.fd_voltage_l1.help_text }}{{ form.fd_voltage_l2.help_text }}{{ form.fd_voltage_l3.help_text }}
{% render_field form.fd_voltage_l1 class+="form-control" style="min-width: 5rem;" %}{% render_field form.fd_voltage_l2 class+="form-control" style="min-width: 5rem;" %}{% render_field form.fd_voltage_l3 class+="form-control" style="min-width: 5rem;" %}
{{form.fd_phase_rotation.help_text|safe}}{% include 'partials/checklist_checkbox.html' with formitem=form.fd_phase_rotation %}
{{form.fd_earth_fault.help_text|safe}}{% render_field form.fd_earth_fault class+="form-control" %}
{{form.fd_pssc.help_text|safe}}{% render_field form.fd_pssc class+="form-control" %}
-
-
-

Tests at 'Worst Case' points (at least 1 point required)

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestPoint 1Point 2Point 3
{{form.w1_description.help_text|safe}}{% render_field form.w1_description class+="form-control" style="min-width: 5rem;" %}{% render_field form.w2_description class+="form-control" style="min-width: 5rem;" %}{% render_field form.w3_description class+="form-control" style="min-width: 5rem;" %}
{{form.w1_polarity.help_text|safe}}{% render_field form.w1_polarity %}{% render_field form.w2_polarity %}{% render_field form.w3_polarity %}
{{form.w1_voltage.help_text|safe}}{% render_field form.w1_voltage class+="form-control" %}{% render_field form.w2_voltage class+="form-control" %}{% render_field form.w3_voltage class+="form-control" %}
{{form.w1_earth_fault.help_text|safe}}{% render_field form.w1_earth_fault class+="form-control" %}{% render_field form.w2_earth_fault class+="form-control" %}{% render_field form.w3_earth_fault class+="form-control" %}
-
-
- {% include 'partials/checklist_checkbox.html' with formitem=form.all_rcds_tested %} - {% include 'partials/checklist_checkbox.html' with formitem=form.public_sockets_tested %} - {% include 'partials/ec_power_info.html' %} -
-
-
-
- {% endif %} -
-
- {% button 'submit' %} -
-
- -
-{% endblock %} diff --git a/RIGS/templates/event_print.xml b/RIGS/templates/event_print.xml index 43b0d849..64d1066d 100644 --- a/RIGS/templates/event_print.xml +++ b/RIGS/templates/event_print.xml @@ -1,136 +1,5 @@ - - - - - - - - +{% extends 'base_print.xml' %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {##} - - - - - - {# #} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {% include "event_print_page.xml" %} - - - +{% block content %} +{% include "event_print_page.xml" %} +{% endblock %} diff --git a/RIGS/templates/event_print_page.xml b/RIGS/templates/event_print_page.xml index 11d238f1..a317d62f 100644 --- a/RIGS/templates/event_print_page.xml +++ b/RIGS/templates/event_print_page.xml @@ -1,12 +1,10 @@ {% load markdown_tags %} {% load filters %} - - -

N{{ object.pk|stringformat:"05d" }}: '{{ object.name }}'

+

N{{ object.pk|stringformat:"05d" }}: '{{ object.name }}'

{{object.start_date|date:"D jS N Y"}} diff --git a/RIGS/templates/hs_list.html b/RIGS/templates/hs_list.html deleted file mode 100644 index 221eecd2..00000000 --- a/RIGS/templates/hs_list.html +++ /dev/null @@ -1,52 +0,0 @@ -{% extends 'base_rigs.html' %} -{% load paginator from filters %} -{% load button from filters %} - -{% block content %} -
- - - - - - - - - - - - {% for event in object_list %} - - - - - - - - - {% empty %} - - - - {% endfor %} - -
EventMICDatesRAChecklists
{{ event }}
{{ event.get_status_display }}
{% if event.mic is not None %}{% else %}{% endif %}{{ event.mic }}{% if event.mic is not None %}{% else %}{%endif%} - {{ event.start_date|date:"D d/m/Y" }} - {% if event.end_date and event.end_date != event.start_date %} -
{{ event.end_date|date:"D d/m/Y" }} - {% endif %} -
{% include 'partials/hs_status.html' with event=event object=event.riskassessment view='ra_detail' edit='ra_edit' create='event_ra' review='ra_review' perm=perms.RIGS.review_riskassessment %} - {% for checklist in event.checklists.all %} - {% include 'partials/hs_status.html' with event=event object=checklist view='ec_detail' edit='ec_edit' create='event_ec' review='ec_review' perm=perms.RIGS.review_eventchecklist %} -
- {% endfor %} - Create -
No events found
- {% if is_paginated %} -
- {% paginator %} -
- {% endif %} -
-{% endblock %} diff --git a/RIGS/templates/hs_object_list.html b/RIGS/templates/hs_object_list.html deleted file mode 100644 index c3ebaf4d..00000000 --- a/RIGS/templates/hs_object_list.html +++ /dev/null @@ -1,59 +0,0 @@ -{% extends 'base_rigs.html' %} -{% load paginator from filters %} -{% load help_text from filters %} -{% load verbose_name from filters %} -{% load get_field from filters %} - -{% block title %}{{ title }} List{% endblock %} - -{% block content %} -
-
-

{{title}} List

-
-
-
-
-
- - - - - {# mmm hax #} - {% if object_list.0 != None %} - {% for field in object_list.0.fieldz %} - - {% endfor %} - {% endif %} - - - - - {% for object in object_list %} - - {# General #} - - {% for field in object_list.0.fieldz %} - - {% endfor %} - {# Buttons #} - - - {% empty %} - - - - {% endfor %} - -
Event{{ object_list.0|verbose_name:field|title }}
{{ object.event }}
{{ object.event.get_status_display }}
{{ object|get_field:field }} - {% include 'partials/hs_status.html' %} -
Nothing found
-
-
-
- {% if is_paginated %} -
- {% paginator %} -
- {% endif %} -{% endblock %} diff --git a/RIGS/templates/partials/event_status.html b/RIGS/templates/partials/event_status.html index bc0e9579..cb93b8d3 100644 --- a/RIGS/templates/partials/event_status.html +++ b/RIGS/templates/partials/event_status.html @@ -16,7 +16,7 @@ {% endif %} {% if not event.dry_hire %} {% if event.riskassessment %} - RA: {%if event.riskassessment.reviewed_by%}{%endif%} + RA: {% else %} RA: {% endif %} diff --git a/RIGS/templates/risk_assessment_detail.html b/RIGS/templates/risk_assessment_detail.html deleted file mode 100644 index df9f1e6f..00000000 --- a/RIGS/templates/risk_assessment_detail.html +++ /dev/null @@ -1,167 +0,0 @@ -{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %} -{% load help_text from filters %} -{% load yesnoi from filters %} -{% load linkornone from filters %} - -{% block content %} -
-
-
-
General
-
-
-
{{ object|help_text:'nonstandard_equipment'|safe }}
-
- {{ object.nonstandard_equipment|yesnoi:'invert' }} -
-
{{ object|help_text:'nonstandard_use'|safe }}
-
- {{ object.nonstandard_use|yesnoi:'invert' }} -
-
{{ object|help_text:'contractors'|safe }}
-
- {{ object.contractors|yesnoi:'invert' }} -
-
{{ object|help_text:'other_companies'|safe }}
-
- {{ object.other_companies|yesnoi:'invert' }} -
-
{{ object|help_text:'crew_fatigue' }}
-
- {{ object.crew_fatigue|yesnoi:'invert' }} -
-
{{ object|help_text:'general_notes' }}
-
- {{ object.general_notes|default:'N/A'|linebreaks }} -
-
-
-
-
-
Power {% include 'partials/event_size.html' %}
-
-
-
{{ object|help_text:'big_power' }}
-
- {{ object.big_power|yesnoi:'invert' }} -
-
{{ object|help_text:'power_mic'|safe }}
-
- {{ object.power_mic.name|default:'None' }} -
-
{{ object|help_text:'outside' }}
-
- {{ object.outside|yesnoi:'invert' }} -
-
{{ object|help_text:'generators' }}
-
- {{ object.generators|yesnoi:'invert' }} -
-
{{ object|help_text:'other_companies_power' }}
-
- {{ object.other_companies_power|yesnoi:'invert' }} -
-
{{ object|help_text:'nonstandard_equipment_power' }}
-
- {{ object.nonstandard_equipment_power|yesnoi:'invert' }} -
-
{{ object|help_text:'multiple_electrical_environments' }}
-
- {{ object.multiple_electrical_environments|yesnoi:'invert' }} -
-
{{ object|help_text:'power_notes' }}
-
- {{ object.power_notes|default:'N/A'|linebreaks }} -
-
{{ object|help_text:'power_plan'|safe }}
-
- {{ object.power_plan|linkornone }} -
-
-
-
-
-
Sound
-
-
-
{{ object|help_text:'noise_monitoring' }}
-
- {{ object.noise_monitoring|yesnoi:'invert' }} -
-
{{ object|help_text:'sound_notes' }}
-
- {{ object.sound_notes|default:'N/A'|linebreaks }} -
-
-
-
-
-
-
-
Site Details
-
-
-
{{ object|help_text:'known_venue' }}
-
- {{ object.known_venue|yesnoi:'invert' }} -
-
{{ object|help_text:'safe_loading'|safe }}
-
- {{ object.safe_loading|yesnoi:'invert' }} -
-
{{ object|help_text:'safe_storage' }}
-
- {{ object.safe_storage|yesnoi:'invert' }} -
-
{{ object|help_text:'area_outside_of_control' }}
-
- {{ object.area_outside_of_control|yesnoi:'invert' }} -
-
{{ object|help_text:'barrier_required' }}
-
- {{ object.barrier_required|yesnoi:'invert' }} -
-
{{ object|help_text:'nonstandard_emergency_procedure' }}
-
- {{ object.nonstandard_emergency_procedure|yesnoi:'invert' }} -
-
-
-
-
-
-
-
Structures
-
-
-
{{ object|help_text:'special_structures' }}
-
- {{ object.special_structures|yesnoi:'invert' }} -
-
{{ object|help_text:'suspended_structures' }}
-
- {{ object.suspended_structures|yesnoi:'invert' }} -
-
{{ object|help_text:'persons_responsible_structures' }}
-
- {{ object.persons_responsible_structures.name|default:'N/A'|linebreaks }} -
-
{{ object|help_text:'rigging_plan'|safe }}
-
- {{ object.rigging_plan|linkornone|default:'N/A' }} -
-
-
-
-
-
-
-
- Edit - View Event - {{ object.review_string|safe }} - {% include 'partials/last_edited.html' with target="riskassessment_history" %} -
-
-{% endblock %} diff --git a/RIGS/templates/risk_assessment_form.html b/RIGS/templates/risk_assessment_form.html deleted file mode 100644 index 28184cd3..00000000 --- a/RIGS/templates/risk_assessment_form.html +++ /dev/null @@ -1,176 +0,0 @@ -{% extends request.is_ajax|yesno:'base_ajax.html,base_rigs.html' %} -{% load widget_tweaks %} -{% load static %} -{% load help_text from filters %} -{% load nice_errors from filters %} - -{% block css %} - -{% endblock %} - -{% block preload_js %} - -{% endblock %} - -{% block js %} - - - - -{% endblock %} - -{% block content %} -
- {% if form.errors %} -
- -
- {% with form|nice_errors as qq %} - {% for error_name,desc in qq.items %} - {% if error_name == 'General form errors' %} - {{ form.non_field_errors.0|safe }} -
- {% render_field form.supervisor_consulted class+="form-check-input" form="form" %}
- -
- {% else %} - -
{{error_name}}
-
{{desc}}
-
- {% endif %} - {% endfor %} - {% endwith %} -
-
- {% endif %} - {% if edit %} -
- {% else %} - - {% endif %} - - {% csrf_token %} -
-
-
-
General
-
-

If the answer is yes to any of the below, you must consult a supervisor and make sure all activities planned to be undertaken are sufficiently covered by health and safety documentation

- {% include 'partials/yes_no_radio.html' with formitem=form.nonstandard_equipment %} - {% include 'partials/yes_no_radio.html' with formitem=form.nonstandard_use %} - {% include 'partials/yes_no_radio.html' with formitem=form.contractors %} - {% include 'partials/yes_no_radio.html' with formitem=form.other_companies %} - {% include 'partials/yes_no_radio.html' with formitem=form.crew_fatigue %} - - - {% render_field form.general_notes class+="form-control" %} -
-
-
-
-
-
-
-
Power
-
- {% include 'partials/yes_no_radio.html' with formitem=form.big_power %} - -
- -
-

If the answer is yes to ANY of the below questions this is a Large Event and you must consult a power supervisor

- {% include 'partials/yes_no_radio.html' with formitem=form.outside %} - {% include 'partials/yes_no_radio.html' with formitem=form.generators label="Will generators be used?" %} - {% include 'partials/yes_no_radio.html' with formitem=form.other_companies_power %} - {% include 'partials/yes_no_radio.html' with formitem=form.nonstandard_equipment_power %} - {% include 'partials/yes_no_radio.html' with formitem=form.multiple_electrical_environments %} - - {% render_field form.power_notes class+="form-control" %} - - {% render_field form.power_plan class+="form-control" %} -
-
-
-
-
-
-
-
Sound
-
-

If yes, consult a supervisor of sound

- {% include 'partials/yes_no_radio.html' with formitem=form.noise_monitoring %} - - {% render_field form.sound_notes class+="form-control" %} -
-
-
-
-
-
-
-
Site Details
-
-

If yes to any of the below, a site visit must be conducted, and an assessment of the venue completed and added to TEC’s records

- {% include 'partials/yes_no_radio.html' with formitem=form.known_venue %} - {% include 'partials/yes_no_radio.html' with formitem=form.safe_loading %} - {% include 'partials/yes_no_radio.html' with formitem=form.safe_storage %} - {% include 'partials/yes_no_radio.html' with formitem=form.area_outside_of_control %} - {% include 'partials/yes_no_radio.html' with formitem=form.barrier_required %} - {% include 'partials/yes_no_radio.html' with formitem=form.nonstandard_emergency_procedure %} -
-
-
-
-
-
-
-
Structures
-
- {% include 'partials/yes_no_radio.html' with formitem=form.special_structures %} - - {% render_field form.persons_responsible_structures class+="form-control mb-3" hidden="true" %} - {% include 'partials/yes_no_radio.html' with formitem=form.suspended_structures %} - - {% render_field form.rigging_plan class+="form-control" hidden="true" %} -
-
-
-
-
-
-
- -
-
-
-
-
-{% endblock %} diff --git a/RIGS/urls.py b/RIGS/urls.py index fe724c88..b67e3c93 100644 --- a/RIGS/urls.py +++ b/RIGS/urls.py @@ -83,6 +83,7 @@ urlpatterns = [ name='ra_list'), path('event/ra//review/', permission_required_with_403('RIGS.review_riskassessment')(views.EventRiskAssessmentReview.as_view()), name='ra_review'), + path('event/ra//print/', permission_required_with_403('RIGS.view_riskassessment')(views.RAPrint.as_view()), name='ra_print'), path('event//checklist/', permission_required_with_403('RIGS.add_eventchecklist')(views.EventChecklistCreate.as_view()), name='event_ec'), diff --git a/RIGS/views/hs.py b/RIGS/views/hs.py index c9b69bda..cc9dffa2 100644 --- a/RIGS/views/hs.py +++ b/RIGS/views/hs.py @@ -12,7 +12,7 @@ from PyRIGS.views import PrintView class EventRiskAssessmentCreate(generic.CreateView): model = models.RiskAssessment - template_name = 'risk_assessment_form.html' + template_name = 'hs/risk_assessment_form.html' form_class = forms.EventRiskAssessmentForm def get(self, *args, **kwargs): @@ -49,7 +49,7 @@ class EventRiskAssessmentCreate(generic.CreateView): class EventRiskAssessmentEdit(generic.UpdateView): model = models.RiskAssessment - template_name = 'risk_assessment_form.html' + template_name = 'hs/risk_assessment_form.html' form_class = forms.EventRiskAssessmentForm def get_success_url(self): @@ -72,7 +72,7 @@ class EventRiskAssessmentEdit(generic.UpdateView): class EventRiskAssessmentDetail(generic.DetailView): model = models.RiskAssessment - template_name = 'risk_assessment_detail.html' + template_name = 'hs/risk_assessment_detail.html' def get_context_data(self, **kwargs): context = super(EventRiskAssessmentDetail, self).get_context_data(**kwargs) @@ -83,7 +83,7 @@ class EventRiskAssessmentDetail(generic.DetailView): class EventRiskAssessmentList(generic.ListView): paginate_by = 20 model = models.RiskAssessment - template_name = 'hs_object_list.html' + template_name = 'hs/hs_object_list.html' def get_queryset(self): return self.model.objects.exclude(event__status=models.Event.CANCELLED).order_by('reviewed_at').select_related('event') @@ -112,7 +112,7 @@ class EventRiskAssessmentReview(generic.View): class EventChecklistDetail(generic.DetailView): model = models.EventChecklist - template_name = 'event_checklist_detail.html' + template_name = 'hs/event_checklist_detail.html' def get_context_data(self, **kwargs): context = super(EventChecklistDetail, self).get_context_data(**kwargs) @@ -122,7 +122,7 @@ class EventChecklistDetail(generic.DetailView): class EventChecklistEdit(generic.UpdateView): model = models.EventChecklist - template_name = 'event_checklist_form.html' + template_name = 'hs/event_checklist_form.html' form_class = forms.EventChecklistForm def get_success_url(self): @@ -145,7 +145,7 @@ class EventChecklistEdit(generic.UpdateView): class EventChecklistCreate(generic.CreateView): model = models.EventChecklist - template_name = 'event_checklist_form.html' + template_name = 'hs/event_checklist_form.html' form_class = forms.EventChecklistForm # From both business logic and programming POVs, RAs must exist before ECs! @@ -184,7 +184,7 @@ class EventChecklistCreate(generic.CreateView): class EventChecklistList(generic.ListView): paginate_by = 20 model = models.EventChecklist - template_name = 'hs_object_list.html' + template_name = 'hs/hs_object_list.html' def get_queryset(self): return self.model.objects.exclude(event__status=models.Event.CANCELLED).order_by('reviewed_at').select_related('event') @@ -214,7 +214,7 @@ class EventChecklistReview(generic.View): class HSList(generic.ListView): paginate_by = 20 model = models.Event - template_name = 'hs_list.html' + template_name = 'hs/hs_list.html' def get_queryset(self): return models.Event.objects.all().exclude(status=models.Event.CANCELLED).order_by('-start_date').select_related('riskassessment').prefetch_related('checklists') @@ -227,3 +227,9 @@ class HSList(generic.ListView): class RAPrint(PrintView): model = models.RiskAssessment + template_name = 'hs/ra_print.xml' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['filename'] = f"EventSpecificRiskAssessment_for_{context['object'].event.display_id}.pdf" + return context diff --git a/RIGS/views/rigboard.py b/RIGS/views/rigboard.py index 7aa7a149..327c9088 100644 --- a/RIGS/views/rigboard.py +++ b/RIGS/views/rigboard.py @@ -1,14 +1,9 @@ import copy import datetime import re -import urllib.error -import urllib.parse -import urllib.request -from io import BytesIO - import premailer import simplejson -from PyPDF2 import PdfFileMerger, PdfFileReader + from django.conf import settings from django.contrib import messages from django.contrib.staticfiles import finders @@ -24,10 +19,9 @@ from django.urls import reverse_lazy from django.utils import timezone from django.utils.decorators import method_decorator from django.views import generic -from z3c.rml import rml2pdf from PyRIGS import decorators -from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin +from PyRIGS.views import OEmbedView, is_ajax, ModalURLMixin, PrintView from RIGS import models, forms __author__ = 'ghost' @@ -178,42 +172,16 @@ class EventDuplicate(EventUpdate): return context -class EventPrint(generic.View): - def get(self, request, pk): - object = get_object_or_404(models.Event, pk=pk) - template = get_template('event_print.xml') +class EventPrint(PrintView): + model = models.Event + template_name = 'event_print.xml' + append_terms = True - merger = PdfFileMerger() - - user_str = f"by {request.user.name} " if request.user is not None else "" - time = timezone.now().strftime('%d/%m/%Y %H:%I') - - name = re.sub(r'[^a-zA-Z0-9 \n\.]', '', object.name) - filename = f"Event_{object.display_id}_{name}_{object.start_date}.pdf" - - context = { - 'object': object, - 'quote': True, - 'current_user': request.user, - 'filename': filename, - 'info_string': f"[Paperwork generated {user_str}on {time} - {object.current_version_id}]", - } - - rml = template.render(context) - buffer = rml2pdf.parseString(rml) - merger.append(PdfFileReader(buffer)) - buffer.close() - - terms = urllib.request.urlopen(settings.TERMS_OF_HIRE_URL) - merger.append(BytesIO(terms.read())) - - merged = BytesIO() - merger.write(merged) - - response = HttpResponse(content_type='application/pdf') - response['Content-Disposition'] = f'filename="{filename}"' - response.write(merged.getvalue()) - return response + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['quote'] = True + context['filename'] = f"Event_{context['object'].display_id}_{context['object_name']}_{context['object'].start_date}.pdf" + return context class EventArchive(generic.ListView): @@ -223,7 +191,6 @@ class EventArchive(generic.ListView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - 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