Do not use Django 'required' for radio selects

As this requires them to be True, whereas we just need to require that an option be entered.
This commit is contained in:
2020-07-03 17:09:32 +01:00
parent d09f3994fc
commit 2e60c5e7bf
6 changed files with 158 additions and 36 deletions

View File

@@ -163,10 +163,9 @@ class EventRiskAssessmentForm(forms.ModelForm):
field.widget = forms.RadioSelect(choices=[ field.widget = forms.RadioSelect(choices=[
(True, 'Yes'), (True, 'Yes'),
(False, 'No') (False, 'No')
], attrs={'class': 'custom-control-input'}) ], attrs={'class': 'custom-control-input', 'required': 'true'})
field.required = True
class Meta: class Meta:
model = models.RiskAssessment model = models.RiskAssessment
fields = '__all__' fields = '__all__'
exclude = ['event'] exclude = []

View File

@@ -0,0 +1,108 @@
# Generated by Django 3.0.7 on 2020-07-03 14:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('RIGS', '0041_auto_20200528_2253'),
]
operations = [
migrations.AlterField(
model_name='riskassessment',
name='area_outside_of_control',
field=models.BooleanField(help_text="Is any part of the work area out of TEC's direct control or openly accessible during the build or breakdown period?"),
),
migrations.AlterField(
model_name='riskassessment',
name='barrier_required',
field=models.BooleanField(help_text='Is there a requirement for TEC to provide any barrier for security or protection of persons/equipment?'),
),
migrations.AlterField(
model_name='riskassessment',
name='big_power',
field=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?'),
),
migrations.AlterField(
model_name='riskassessment',
name='contractors',
field=models.BooleanField(help_text='Are you using any external contractors?'),
),
migrations.AlterField(
model_name='riskassessment',
name='crew_fatigue',
field=models.BooleanField(help_text='Is crew fatigue likely to be a risk at any point during this event?'),
),
migrations.AlterField(
model_name='riskassessment',
name='generators',
field=models.BooleanField(help_text='Will generators be used?'),
),
migrations.AlterField(
model_name='riskassessment',
name='known_venue',
field=models.BooleanField(help_text='Is the event in a venue that you and/or TEC have experience working in?'),
),
migrations.AlterField(
model_name='riskassessment',
name='multiple_electrical_environments',
field=models.BooleanField(help_text='Will the electrical installation occupy more than one electrical environment?'),
),
migrations.AlterField(
model_name='riskassessment',
name='noise_monitoring',
field=models.BooleanField(help_text='Does the event require noise monitoring or any non-standard procedures in order to comply with health and safety legislation or site rules?'),
),
migrations.AlterField(
model_name='riskassessment',
name='nonstandard_emergency_procedure',
field=models.BooleanField(help_text="Does the emergency procedure for the event differ from TEC's standard procedures?"),
),
migrations.AlterField(
model_name='riskassessment',
name='nonstandard_equipment',
field=models.BooleanField(help_text="Does the event require any hired in equipment or use of equipment that is not covered by TEC's standard risk assessments and method statements?"),
),
migrations.AlterField(
model_name='riskassessment',
name='nonstandard_equipment_power',
field=models.BooleanField(help_text='Does the power plan require the use of any power equipment (distros, dimmers, motor controllers, etc.) that does not belong to TEC?'),
),
migrations.AlterField(
model_name='riskassessment',
name='nonstandard_use',
field=models.BooleanField(help_text='Are TEC using their equipment in a way that is abnormal?<br><small>i.e. Not covered by TECs standard health and safety documentation</small>'),
),
migrations.AlterField(
model_name='riskassessment',
name='other_companies',
field=models.BooleanField(help_text='Are TEC working with any other companies on site?'),
),
migrations.AlterField(
model_name='riskassessment',
name='other_companies_power',
field=models.BooleanField(help_text='Will TEC be supplying power to any other companies?'),
),
migrations.AlterField(
model_name='riskassessment',
name='safe_loading',
field=models.BooleanField(help_text='Is there a safe load in/out?<br><small>e.g. sufficient lighting, flat, not in a crowded area etc.</small>'),
),
migrations.AlterField(
model_name='riskassessment',
name='safe_storage',
field=models.BooleanField(help_text='Are there areas to safely store equipment?'),
),
migrations.AlterField(
model_name='riskassessment',
name='special_structures',
field=models.BooleanField(help_text='Does the event require use of winch stands, motors, MPT Towers, or staging?'),
),
migrations.AlterField(
model_name='riskassessment',
name='suspended_structures',
field=models.BooleanField(help_text="Are any structures (excluding projector screens and IWBs) being suspended from TEC's structures?"),
),
]

View File

@@ -3,6 +3,7 @@ import hashlib
import datetime import datetime
import pytz import pytz
from django import forms
from django.db import models from django.db import models
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.conf import settings from django.conf import settings
@@ -615,11 +616,19 @@ class RiskAssessment(models.Model, RevisionMixin):
# Blimey that was a lot of options # Blimey that was a lot of options
# created = models.DateTimeField(auto_now_add=True)
# reviewed_at = models.DateTimeField() # reviewed_at = models.DateTimeField()
# reviewed_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, # reviewed_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True,
# verbose_name="Reviewer", on_delete=models.CASCADE) # verbose_name="Reviewer", on_delete=models.CASCADE)
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 @property
def activity_feed_string(self): def activity_feed_string(self):
return str(self.event) return str(self.event)

View File

@@ -7,4 +7,4 @@
<label class="custom-control-label" for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label> <label class="custom-control-label" for="{{ radio.id_for_label }}">{{ radio.choice_label }}</label>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>

View File

@@ -3,7 +3,7 @@
{% load static %} {% load static %}
{% load help_text from filters %} {% load help_text from filters %}
{% block title %}{% if edit %}Edit{% else %}Create{% endif %} Risk Assessment for Event N{{ object.event.pk|stringformat:"05d" }} {{ object.event.name }}{% endblock %} {% block title %}{% if edit %}Edit{% else %}Create{% endif %} Risk Assessment for Event N{{ event.pk|stringformat:"05d" }}{% endblock %}
{% block css %} {% block css %}
{{ block.super }} {{ block.super }}
@@ -29,12 +29,15 @@
{% block content %} {% block content %}
<div class="col-sm-offset-1 col-sm-10"> <div class="col-sm-offset-1 col-sm-10">
<h3>{% if edit %}Edit{% else %}Create{% endif %} Risk Assessment for Event N{{ object.event.pk|stringformat:"05d" }} {{ object.event.name }}</h3> <h3>{% if edit %}Edit{% else %}Create{% endif %} Risk Assessment for Event N{{ event.pk|stringformat:"05d" }}</h3>
{% include 'form_errors.html' %}
{% if edit %} {% if edit %}
<form method="POST" action="{% url 'ra_edit' pk=object.pk %}"> <form role="form" method="POST" action="{% url 'ra_edit' pk=object.pk %}">
{% else %} {% else %}
<form role="form" method="POST" action="{% url 'event_ra' pk=event.pk %}"> <form role="form" method="POST" action="{% url 'event_ra' pk=event.pk %}">
{% endif %} {% endif %}
<input type="hidden" name="{{ form.event.name }}" id="{{ form.event.id_for_label }}"
value="{{event.pk}}"/>
{% csrf_token %} {% csrf_token %}
<div class="row"> <div class="row">
<div class="col-12"> <div class="col-12">

View File

@@ -18,30 +18,33 @@
<thead> <thead>
<tr> <tr>
<th scope="col">Event</th> <th scope="col">Event</th>
<th scope="col" class="">{{ object_list.0|verbose_name:'nonstandard_equipment'|title }}</th> {# mmm hax #}
<th scope="col">{{ object_list.0|verbose_name:'nonstandard_use'|title }}</th> {% if object_list.0 %}
<th scope="col">{{ object_list.0|verbose_name:'contractors'|title }}</th> <th scope="col" class="">{{ object_list.0|verbose_name:'nonstandard_equipment'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'other_companies'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'nonstandard_use'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'crew_fatigue'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'contractors'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'general_notes'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'other_companies'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'big_power'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'crew_fatigue'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'power_mic'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'general_notes'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'generators'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'big_power'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'other_companies_power'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'power_mic'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'nonstandard_equipment_power'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'generators'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'multiple_electrical_environments'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'other_companies_power'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'power_notes'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'nonstandard_equipment_power'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'noise_monitoring'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'multiple_electrical_environments'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'sound_notes'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'power_notes'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'known_venue'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'noise_monitoring'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'safe_loading'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'sound_notes'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'safe_storage'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'known_venue'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'area_outside_of_control'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'safe_loading'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'nonstandard_emergency_procedure'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'safe_storage'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'barrier_required'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'area_outside_of_control'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'special_structures'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'nonstandard_emergency_procedure'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'persons_responsible_structures'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'barrier_required'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'suspended_structures'|title }}</th> <th scope="col">{{ object_list.0|verbose_name:'special_structures'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'persons_responsible_structures'|title }}</th>
<th scope="col">{{ object_list.0|verbose_name:'suspended_structures'|title }}</th>
{% endif %}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -54,7 +57,7 @@
<td class="{% if object.other_companies%}bg-danger text-white{%endif%}">{{object.other_companies|yesno|title}}</td> <td class="{% if object.other_companies%}bg-danger text-white{%endif%}">{{object.other_companies|yesno|title}}</td>
<td class="{% if object.crew_fatigue%}bg-danger text-white{%endif%}">{{object.crew_fatigue|yesno|title}}</td> <td class="{% if object.crew_fatigue%}bg-danger text-white{%endif%}">{{object.crew_fatigue|yesno|title}}</td>
<td>{{ object.general_notes|default:'N/A'|linebreaks }}</td> <td>{{ object.general_notes|default:'N/A'|linebreaks }}</td>
<td class="{% if object.big_power%}bg-danger text-white{%endif%}">{{object.big_power|yesno|title}}</td> <td class="{% if object.big_power%}bg-danger text-white{%endif%}">{{object.big_power|yesno|title}}</td>
<td>{{ object.power_mic.name|default:'N/A' }}</td> <td>{{ object.power_mic.name|default:'N/A' }}</td>
<td class="{% if object.generators%}bg-danger text-white{%endif%}">{{object.generators|yesno|title}}</td> <td class="{% if object.generators%}bg-danger text-white{%endif%}">{{object.generators|yesno|title}}</td>
@@ -62,17 +65,17 @@
<td class="{% if object.nonstandard_equipment_power%}bg-danger text-white{%endif%}">{{object.nonstandard_equipment_power|yesno|title}}</td> <td class="{% if object.nonstandard_equipment_power%}bg-danger text-white{%endif%}">{{object.nonstandard_equipment_power|yesno|title}}</td>
<td class="{% if object.multiple_electrical_environments%}bg-danger text-white{%endif%}">{{object.multiple_electrical_environments|yesno|title}}</td> <td class="{% if object.multiple_electrical_environments%}bg-danger text-white{%endif%}">{{object.multiple_electrical_environments|yesno|title}}</td>
<td>{{ object.power_notes|default:'N/A'|linebreaks }}</td> <td>{{ object.power_notes|default:'N/A'|linebreaks }}</td>
<td class="{% if object.noise_monitoring%}bg-danger text-white{%endif%}">{{object.noise_monitoring|yesno|title}}</td> <td class="{% if object.noise_monitoring%}bg-danger text-white{%endif%}">{{object.noise_monitoring|yesno|title}}</td>
<td>{{ object.sound_notes|default:'N/A'|linebreaks }}</td> <td>{{ object.sound_notes|default:'N/A'|linebreaks }}</td>
<td class="{% if not object.known_venue%}bg-danger text-white{%endif%}">{{object.known_venue|yesno|title}}</td> <td class="{% if not object.known_venue%}bg-danger text-white{%endif%}">{{object.known_venue|yesno|title}}</td>
<td class="{% if not object.safe_loading%}bg-danger text-white{%endif%}">{{object.safe_loading|yesno|title}}</td> <td class="{% if not object.safe_loading%}bg-danger text-white{%endif%}">{{object.safe_loading|yesno|title}}</td>
<td class="{% if object.safe_storage%}bg-danger text-white{%endif%}">{{object.safe_storage|yesno|title}}</td> <td class="{% if object.safe_storage%}bg-danger text-white{%endif%}">{{object.safe_storage|yesno|title}}</td>
<td class="{% if object.area_outside_of_control%}bg-danger text-white{%endif%}">{{object.area_outside_of_control|yesno|title}}</td> <td class="{% if object.area_outside_of_control%}bg-danger text-white{%endif%}">{{object.area_outside_of_control|yesno|title}}</td>
<td class="{% if object.nonstandard_emergency_procedure%}bg-danger text-white{%endif%}">{{object.nonstandard_emergency_procedure|yesno|title}}</td> <td class="{% if object.nonstandard_emergency_procedure%}bg-danger text-white{%endif%}">{{object.nonstandard_emergency_procedure|yesno|title}}</td>
<td class="{% if object.barrier_required%}bg-danger text-white{%endif%}">{{object.barrier_required|yesno|title}}</td> <td class="{% if object.barrier_required%}bg-danger text-white{%endif%}">{{object.barrier_required|yesno|title}}</td>
<td class="{% if object.special_structures%}bg-danger text-white{%endif%}">{{object.special_structures|yesno|title}}</td> <td class="{% if object.special_structures%}bg-danger text-white{%endif%}">{{object.special_structures|yesno|title}}</td>
<td>{{ object.persons_responsible_structures|default:'N/A'|linebreaks }}</td> <td>{{ object.persons_responsible_structures|default:'N/A'|linebreaks }}</td>
<td class="{% if object.suspended_structures%}bg-danger text-white{%endif%}">{{object.suspended_structures|yesno|title}}</td> <td class="{% if object.suspended_structures%}bg-danger text-white{%endif%}">{{object.suspended_structures|yesno|title}}</td>