Start move of event size logic to RA from Ec

This commit is contained in:
2020-12-13 16:48:06 +00:00
parent 124b7a8e51
commit 13fcadaf79
4 changed files with 48 additions and 6 deletions

View File

@@ -170,6 +170,7 @@ class EventRiskAssessmentForm(forms.ModelForm):
], attrs={'class': 'custom-control-input', 'required': 'true'})
def clean(self):
# Check expected values
unexpected_values = []
for field, value in models.RiskAssessment.expected_values.items():
if self.cleaned_data.get(field) != value:

View File

@@ -0,0 +1,22 @@
# Generated by Django 3.1.2 on 2020-12-13 16:42
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('RIGS', '0046_auto_20201213_1625'),
]
operations = [
migrations.RemoveField(
model_name='eventchecklist',
name='event_size',
),
migrations.AddField(
model_name='riskassessment',
name='event_size',
field=models.IntegerField(blank=True, choices=[(0, 'Small'), (1, 'Medium'), (2, 'Large')], null=True),
),
]

View File

@@ -622,6 +622,11 @@ def validate_url(value):
@reversion.register
class RiskAssessment(models.Model, RevisionMixin):
SMALL = (0, 'Small')
MEDIUM = (1, 'Medium')
LARGE = (2, 'Large')
SIZES = (SMALL, MEDIUM, LARGE)
event = models.OneToOneField('Event', on_delete=models.CASCADE)
# General
nonstandard_equipment = models.BooleanField(help_text="Does the event require any hired in equipment or use of equipment that is not covered by <a href='https://nottinghamtec.sharepoint.com/:f:/g/HealthAndSafety/Eo4xED_DrqFFsfYIjKzMZIIB6Gm_ZfR-a8l84RnzxtBjrA?e=Bf0Haw'>"
@@ -633,6 +638,7 @@ class RiskAssessment(models.Model, RevisionMixin):
general_notes = models.TextField(blank=True, null=True, help_text="Did you have to consult a supervisor about any of the above? If so who did you consult and what was the outcome?")
# Power
event_size = models.IntegerField(blank=True, null=True, choices=SIZES)
big_power = models.BooleanField(help_text="Does the event require larger power supplies than 13A or 16A single phase wall sockets, or draw more than 20A total current?")
outside = models.BooleanField(help_text="Is the event outdoors?")
# If yes to the above two, you must answer...
@@ -694,6 +700,19 @@ class RiskAssessment(models.Model, RevisionMixin):
}
inverted_fields = {key: value for (key, value) in expected_values.items() if not value}.keys()
def clean(self):
# Check for idiots
if not self.outside and self.generators:
raise forms.ValidationError("Engage brain, please. <strong>No generators indoors!(!)</strong>")
# Confirm event size
if self.outside:
self.event_size = self.LARGE[0]
# Check all except generators, since generators entails outside and hence LARGE
elif self.big_power or self.other_companies_power or self.nonstandard_equipment_power or self.multiple_electrical_environments:
self.event_size = self.MEDIUM[0]
else:
self.event_size = self.SMALL[0]
class Meta:
ordering = ['event']
permissions = [
@@ -713,10 +732,6 @@ class RiskAssessment(models.Model, RevisionMixin):
@reversion.register(follow=['vehicles', 'crew'])
class EventChecklist(models.Model, RevisionMixin):
SMALL = (0, 'Small')
MEDIUM = (1, 'Medium')
LARGE = (2, 'Large')
SIZES = (SMALL, MEDIUM, LARGE)
event = models.ForeignKey('Event', related_name='checklists', on_delete=models.CASCADE)
# General
@@ -743,7 +758,6 @@ class EventChecklist(models.Model, RevisionMixin):
earthing = models.BooleanField(blank=True, null=True, help_text="Equipment appropriately earthed?<br><small>(truss, stage, generators etc)</small>")
pat = models.BooleanField(blank=True, null=True, help_text="All equipment in PAT period?")
event_size = models.IntegerField(blank=True, null=True, choices=SIZES)
# Medium Electrical Checks
source_rcd = models.BooleanField(blank=True, null=True, help_text="Source RCD protected?<br><small>(if cable is more than 3m long) </small>")
labelling = models.BooleanField(blank=True, null=True, help_text="Appropriate and clear labelling on distribution and cabling?")

View File

@@ -40,7 +40,12 @@
</div>
</div>
<div class="card card-default mb-3">
<div class="card-header">Power</div>
<div class="card-header">Power {% if object.event_size == 2 %}
<span class="badge badge-danger p-2 my-3">Large Event</span>
{% elif object.event_size == 1 %}
<span class="badge badge-warning p-2 my-3">Medium Event</span>
{%else%}<span class="badge badge-success p-2 my-3">Small Event</span>
{%endif%}</div>
<div class="card-body">
<dl class="row">
<dt class="col-sm-6">{{ object|help_text:'big_power' }}</dt>