From f3c2ce251962af211bbb482e0bb73e90b293da69 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Sun, 30 Aug 2020 12:15:04 +0100 Subject: [PATCH] Validation of power reqs --- RIGS/forms.py | 9 +- RIGS/migrations/0051_auto_20200830_1115.py | 73 ++++++++++++++++ RIGS/migrations/0052_auto_20200830_1117.py | 73 ++++++++++++++++ RIGS/models.py | 33 +++++--- RIGS/templates/event_checklist_detail.html | 83 ++++++++++++++++--- RIGS/templates/event_checklist_form.html | 31 +++---- .../partials/checklist_checkbox.html | 2 +- RIGS/templates/partials/yes_no_radio.html | 20 +++-- RIGS/templatetags/filters.py | 5 +- versioning/versioning.py | 5 +- 10 files changed, 281 insertions(+), 53 deletions(-) create mode 100644 RIGS/migrations/0051_auto_20200830_1115.py create mode 100644 RIGS/migrations/0052_auto_20200830_1117.py diff --git a/RIGS/forms.py b/RIGS/forms.py index bb375c14..3eb4453a 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -173,6 +173,12 @@ class EventRiskAssessmentForm(forms.ModelForm): class EventChecklistForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super(EventChecklistForm, self).__init__(*args, **kwargs) + for name, field in self.fields.items(): + if field.__class__ == forms.NullBooleanField: + # Only display yes/no to user, the 'none' is only ever set in the background + field.widget = forms.CheckboxInput() # Parsed from incoming form data by clean, then saved into models when the form is saved items = {} @@ -231,6 +237,7 @@ class EventChecklistForm(forms.ModelForm): # Remove all existing, to be recreated from the form checklist.vehicles.all().delete() checklist.crew.all().delete() + checklist.save() for key in self.items: item = self.items[key] @@ -240,8 +247,6 @@ class EventChecklistForm(forms.ModelForm): item.full_clean() item.save() - checklist.save() - self.items.clear() return checklist diff --git a/RIGS/migrations/0051_auto_20200830_1115.py b/RIGS/migrations/0051_auto_20200830_1115.py new file mode 100644 index 00000000..bd845846 --- /dev/null +++ b/RIGS/migrations/0051_auto_20200830_1115.py @@ -0,0 +1,73 @@ +# Generated by Django 3.1 on 2020-08-30 10:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('RIGS', '0050_auto_20200830_1048'), + ] + + operations = [ + migrations.AlterField( + model_name='eventchecklist', + name='all_rcds_tested', + field=models.BooleanField(blank=True, help_text='All circuit RCDs tested?(using test button)'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_earth_fault', + field=models.IntegerField(blank=True, help_text='Earth Fault Loop Impedance (ZS)', verbose_name='Earth Fault Loop Impedance'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_phase_rotation', + field=models.BooleanField(blank=True, help_text='Phase Rotation
(if required)', verbose_name='Phase Rotation'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_pssc', + field=models.IntegerField(blank=True, help_text='Prospective Short Circuit Current', verbose_name='PSCC'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_voltage_l1', + field=models.IntegerField(blank=True, help_text='L1 - N', verbose_name='First Distro Voltage L1-N'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_voltage_l2', + field=models.IntegerField(blank=True, help_text='L2 - N', verbose_name='First Distro Voltage L2-N'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_voltage_l3', + field=models.IntegerField(blank=True, help_text='L3 - N', verbose_name='First Distro Voltage L3-N'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='labelling', + field=models.BooleanField(blank=True, help_text='Appropriate and clear labelling on distribution and cabling?'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='public_sockets_tested', + field=models.BooleanField(blank=True, help_text='Public/Performer accessible circuits tested?(using socket tester)'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='rcds', + field=models.BooleanField(blank=True, help_text='RCDs installed where needed and tested?'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='source_rcd', + field=models.BooleanField(blank=True, help_text='Source RCD protected?
(if cable is more than 3m long) '), + ), + migrations.AlterField( + model_name='eventchecklist', + name='supply_test', + field=models.BooleanField(blank=True, help_text='Electrical supplies tested?
(using socket tester)'), + ), + ] diff --git a/RIGS/migrations/0052_auto_20200830_1117.py b/RIGS/migrations/0052_auto_20200830_1117.py new file mode 100644 index 00000000..7ef4d10d --- /dev/null +++ b/RIGS/migrations/0052_auto_20200830_1117.py @@ -0,0 +1,73 @@ +# Generated by Django 3.1 on 2020-08-30 10:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('RIGS', '0051_auto_20200830_1115'), + ] + + operations = [ + migrations.AlterField( + model_name='eventchecklist', + name='all_rcds_tested', + field=models.BooleanField(blank=True, help_text='All circuit RCDs tested?(using test button)', null=True), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_earth_fault', + field=models.IntegerField(blank=True, help_text='Earth Fault Loop Impedance (ZS)', null=True, verbose_name='Earth Fault Loop Impedance'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_phase_rotation', + field=models.BooleanField(blank=True, help_text='Phase Rotation
(if required)', null=True, verbose_name='Phase Rotation'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_pssc', + field=models.IntegerField(blank=True, help_text='Prospective Short Circuit Current', null=True, verbose_name='PSCC'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_voltage_l1', + field=models.IntegerField(blank=True, help_text='L1 - N', null=True, verbose_name='First Distro Voltage L1-N'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_voltage_l2', + field=models.IntegerField(blank=True, help_text='L2 - N', null=True, verbose_name='First Distro Voltage L2-N'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='fd_voltage_l3', + field=models.IntegerField(blank=True, help_text='L3 - N', null=True, verbose_name='First Distro Voltage L3-N'), + ), + migrations.AlterField( + model_name='eventchecklist', + name='labelling', + field=models.BooleanField(blank=True, help_text='Appropriate and clear labelling on distribution and cabling?', null=True), + ), + migrations.AlterField( + model_name='eventchecklist', + name='public_sockets_tested', + field=models.BooleanField(blank=True, help_text='Public/Performer accessible circuits tested?(using socket tester)', null=True), + ), + migrations.AlterField( + model_name='eventchecklist', + name='rcds', + field=models.BooleanField(blank=True, help_text='RCDs installed where needed and tested?', null=True), + ), + migrations.AlterField( + model_name='eventchecklist', + name='source_rcd', + field=models.BooleanField(blank=True, help_text='Source RCD protected?
(if cable is more than 3m long) ', null=True), + ), + migrations.AlterField( + model_name='eventchecklist', + name='supply_test', + field=models.BooleanField(blank=True, help_text='Electrical supplies tested?
(using socket tester)', null=True), + ), + ] diff --git a/RIGS/models.py b/RIGS/models.py index 5055e1bf..3356a82d 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -654,8 +654,8 @@ class EventChecklist(models.Model, RevisionMixin): extinguishers_location = models.CharField(max_length=255, help_text="Location of fire extinguishers") # Small Electrical Checks - rcds = models.BooleanField(help_text="RCDs installed where needed and tested?") - supply_test = models.BooleanField(help_text="Electrical supplies tested?
(using socket tester)") + rcds = models.BooleanField(blank=True,null=True,help_text="RCDs installed where needed and tested?") + supply_test = models.BooleanField(blank=True,null=True,help_text="Electrical supplies tested?
(using socket tester)") # Shared electrical checks earthing = models.BooleanField(help_text="Equipment appropriately earthed?
(truss, stage, generators etc)") @@ -663,18 +663,27 @@ class EventChecklist(models.Model, RevisionMixin): medium_event = models.BooleanField() # Medium Electrical Checks - source_rcd = models.BooleanField(help_text="Source RCD protected?
(if cable is more than 3m long) ") - labelling = models.BooleanField(help_text="Appropriate and clear labelling on distribution and cabling?") + source_rcd = models.BooleanField(blank=True,null=True,help_text="Source RCD protected?
(if cable is more than 3m long) ") + labelling = models.BooleanField(blank=True,null=True, help_text="Appropriate and clear labelling on distribution and cabling?") # First Distro - fd_voltage_l1 = models.IntegerField(verbose_name="First Distro Voltage L1-N", help_text="L1 - N") - fd_voltage_l2 = models.IntegerField(verbose_name="First Distro Voltage L2-N", help_text="L2 - N") - fd_voltage_l3 = models.IntegerField(verbose_name="First Distro Voltage L3-N", help_text="L3 - N") - fd_phase_rotation = models.BooleanField(verbose_name="Phase Rotation", help_text="Phase Rotation
(if required)") - fd_earth_fault = models.IntegerField(verbose_name="Earth Fault Loop Impedance", help_text="Earth Fault Loop Impedance (ZS)") - fd_pssc = models.IntegerField(verbose_name="PSCC", help_text="Prospective Short Circuit Current") + fd_voltage_l1 = models.IntegerField(blank=True,null=True, verbose_name="First Distro Voltage L1-N", help_text="L1 - N") + fd_voltage_l2 = models.IntegerField(blank=True,null=True,verbose_name="First Distro Voltage L2-N", help_text="L2 - N") + fd_voltage_l3 = models.IntegerField(blank=True,null=True,verbose_name="First Distro Voltage L3-N", help_text="L3 - N") + fd_phase_rotation = models.BooleanField(blank=True,null=True,verbose_name="Phase Rotation", help_text="Phase Rotation
(if required)") + fd_earth_fault = models.IntegerField(blank=True,null=True,verbose_name="Earth Fault Loop Impedance", help_text="Earth Fault Loop Impedance (ZS)") + fd_pssc = models.IntegerField(blank=True,null=True,verbose_name="PSCC", help_text="Prospective Short Circuit Current") - all_rcds_tested = models.BooleanField(help_text="All circuit RCDs tested?(using test button)") - public_sockets_tested = models.BooleanField(help_text="Public/Performer accessible circuits tested?(using socket tester)") + all_rcds_tested = models.BooleanField(blank=True,null=True,help_text="All circuit RCDs tested?
(using test button)") + public_sockets_tested = models.BooleanField(blank=True,null=True,help_text="Public/Performer accessible circuits tested?
(using socket tester)") + + def clean(self): + errdict = {} + if self.earthing == None or self.pat == None: + raise ValidationError('Fill out the electrical checks') + if self.medium_event and (self.source_rcd == None or self.labelling == None or self.all_rcds_tested == None or self.public_sockets_tested == None): + raise ValidationError('Fill out the medium event electrical checks') + elif self.rcds == None or self.supply_test == None: + raise ValidationError('Fill out the small event electrical checks') @property def activity_feed_string(self): diff --git a/RIGS/templates/event_checklist_detail.html b/RIGS/templates/event_checklist_detail.html index 1b547a9f..3e0f0fec 100644 --- a/RIGS/templates/event_checklist_detail.html +++ b/RIGS/templates/event_checklist_detail.html @@ -91,12 +91,75 @@
-
Power
+
Power {% if object.medium_event %}Medium Event{%else%}Small Event{%endif%}
{% if object.medium_event %} - Medium Event +
+
{{ object|help_text:'source_rcd'|safe }}
+
+ {{ object.source_rcd|yesno|title }} +
+
{{ object|help_text:'labelling'|safe }}
+
+ {{ object.labelling|yesno|title }} +
+
{{ object|help_text:'earthing'|safe }}
+
+ {{ object.earthing|yesno|title }} +
+
{{ object|help_text:'pat'|safe }}
+
+ {{ object.pat|yesno|title }} +
+
+
+

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|yesno|title }}
{{ object|help_text:'fd_earth_fault'|safe}}{{ object.fd_earth_fault }}
{{ object|help_text:'fd_pssc'}}{{ object.fd_pssc }}
+
+
+
{{ object|help_text:'all_rcds_tested'|safe }}
+
+ {{ object.all_rcds_tested|yesno|title }} +
+
{{ object|help_text:'public_sockets_tested'|safe }}
+
+ {{ object.public_sockets_tested|yesno|title }} +
+
+ {% include 'partials/ec_power_info.html' %} {% else %} - Small Event
{{ object|help_text:'rcds'|safe }}
@@ -119,13 +182,13 @@
- -
- -
-
- {% include 'partials/last_edited.html' with target="eventchecklist_history" %} +
+ +
+
+ {% 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 index 1684bba2..d6be3c53 100644 --- a/RIGS/templates/event_checklist_form.html +++ b/RIGS/templates/event_checklist_form.html @@ -49,10 +49,14 @@ $('#{{form.medium_event.auto_id}}').prop('checked', true); $('#small-event').slideUp(); $('#medium-event').slideDown(); + //$('#medium-event').find('select,input').attr('required', 'true'); + //$('#small-event').find('select,input').removeAttr('required'); } else { $('#{{form.medium_event.auto_id}}').prop('checked', false); $('#small-event').slideDown(); $('#medium-event').slideUp(); + //('#small-event').find('select,input').attr('required', 'true'); + //('#medium-event').find('select,input').removeAttr('required'); } }); $('button[data-action=add]').on('click', function (event) { @@ -118,7 +122,7 @@
- {% if object.power_mic %} {% endif %} @@ -261,27 +265,24 @@
Electrical Checks for ‘Medium’ TEC Events
{% include 'partials/checklist_checkbox.html' with formitem=form.source_rcd %} - {% include 'partials/checklist_checkbox.html' with formitem=form.clear_labelling %} + {% 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

- +
- - - - + + - - - - + + + @@ -289,15 +290,15 @@ - - + + - + - + diff --git a/RIGS/templates/partials/checklist_checkbox.html b/RIGS/templates/partials/checklist_checkbox.html index ac8dd80e..f0e2cd8c 100644 --- a/RIGS/templates/partials/checklist_checkbox.html +++ b/RIGS/templates/partials/checklist_checkbox.html @@ -1,6 +1,6 @@ {% load widget_tweaks %} {% load help_text from filters %}
- {% render_field formitem|attr:'required=true' class+="form-check-input" %} + {% render_field formitem class+="form-check-input" %}
diff --git a/RIGS/templates/partials/yes_no_radio.html b/RIGS/templates/partials/yes_no_radio.html index 84aecfa4..1bcd838b 100644 --- a/RIGS/templates/partials/yes_no_radio.html +++ b/RIGS/templates/partials/yes_no_radio.html @@ -1,10 +1,12 @@ - -
- {% for radio in formitem %} -
- {{ radio.tag }} - -
- {% endfor %} +
+ +
+ {% for radio in formitem %} +
+ {{ radio.tag }} + +
+ {% endfor %} +
diff --git a/RIGS/templatetags/filters.py b/RIGS/templatetags/filters.py index 5865fe2b..28bb5237 100644 --- a/RIGS/templatetags/filters.py +++ b/RIGS/templatetags/filters.py @@ -114,10 +114,11 @@ def orderby(request, field, attr): return dict_.urlencode() - +# Used for accessing outside of a form, i.e. in detail views of RiskAssessment and EventChecklist @register.filter def help_text(obj, field): - return obj._meta.get_field(field).help_text + if hasattr(obj, '_meta'): + return obj._meta.get_field(field).help_text @register.filter diff --git a/versioning/versioning.py b/versioning/versioning.py index 3db76247..07106afa 100644 --- a/versioning/versioning.py +++ b/versioning/versioning.py @@ -117,17 +117,17 @@ class ModelComparison(object): @cached_property def item_changes(self): - # Recieves two event version objects and compares their items, returns an array of ItemCompare objects item_type = ContentType.objects.get_for_model(self.version.object) old_item_versions = self.version.parent.revision.version_set.exclude(content_type=item_type) new_item_versions = self.version.revision.version_set.exclude(content_type=item_type) - comparisonParams = {'excluded_keys': ['id', 'event', 'order']} + comparisonParams = {'excluded_keys': ['id', 'event', 'order', 'checklist']} # Build some dicts of what we have item_dict = {} # build a list of items, key is the item_pk # FIXME Removing the if checks makes things REALLY slow... for version in old_item_versions: # put all the old versions in a list + print(version) # if version.field_dict["event_id"] == int(self.new.pk): compare = ModelComparison(old=version._object_version.object, **comparisonParams) item_dict[version.object_id] = compare @@ -179,6 +179,7 @@ class RIGSVersion(Version): objects = RIGSVersionManager.as_manager() + # Gets the most recent previous version @cached_property def parent(self): thisId = self.object_id
TestTestValue
Voltage
(cube meter)
{{object|help_text:'fd_voltage_l1'}}{{object|help_text:'fd_voltage_l2'}}{{object|help_text:'fd_voltage_l3'}}{{ 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" %}{% render_field form.fd_voltage_l3 class+="form-control" %}
{{object|help_text:'fd_phase_rotation'|safe}}{% render_field form.fd_phase_rotation %}{{form.fd_phase_rotation.help_text|safe}}{% include 'partials/checklist_checkbox.html' with formitem=form.fd_phase_rotation %}
{{object|help_text:'fd_earth_fault'|safe}}{{form.fd_earth_fault.help_text|safe}} {% render_field form.fd_earth_fault class+="form-control" %}
{{object|help_text:'fd_pssc'|safe}}{{form.fd_pssc.help_text|safe}} {% render_field form.fd_pssc class+="form-control" %}