From 49a2bc83abddaf1b3711c5620c6b4a4eb9a76ab3 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Sat, 10 Oct 2020 13:41:36 +0100 Subject: [PATCH] Make venue/date editable on EC For multi venue, multi day events Defaults to date and venue set on the event. Also made power MIC default to that set in RA --- RIGS/forms.py | 6 + RIGS/hs.py | 6 + RIGS/migrations/0043_auto_20201010_1320.py | 27 ++ RIGS/models.py | 3 + RIGS/templates/event_checklist_detail.html | 468 +++++++++++---------- RIGS/templates/event_checklist_form.html | 42 +- RIGS/templates/hs_list.html | 2 +- RIGS/templatetags/filters.py | 6 +- 8 files changed, 314 insertions(+), 246 deletions(-) create mode 100644 RIGS/migrations/0043_auto_20201010_1320.py diff --git a/RIGS/forms.py b/RIGS/forms.py index 6faf6e67..0d425a9e 100644 --- a/RIGS/forms.py +++ b/RIGS/forms.py @@ -187,6 +187,7 @@ class EventRiskAssessmentForm(forms.ModelForm): class EventChecklistForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(EventChecklistForm, self).__init__(*args, **kwargs) + self.fields['date'].widget.format = '%Y-%m-%d' 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 @@ -194,6 +195,11 @@ class EventChecklistForm(forms.ModelForm): # Parsed from incoming form data by clean, then saved into models when the form is saved items = {} + related_models = { + 'venue': models.Venue, + 'power_mic': models.Profile, + } + # Two possible formats def parsedatetime(self, date_string): try: diff --git a/RIGS/hs.py b/RIGS/hs.py index 188e1e46..f2843ce8 100644 --- a/RIGS/hs.py +++ b/RIGS/hs.py @@ -127,6 +127,12 @@ class EventChecklistEdit(generic.UpdateView): context['event'] = ec.event context['edit'] = True context['page_title'] = 'Edit Event Checklist for Event {}'.format(ec.event.display_id) + form = context['form'] + # Get some other objects to include in the form. Used when there are errors but also nice and quick. + for field, model in form.related_models.items(): + value = form[field].value() + if value is not None and value != '': + context[field] = model.objects.get(pk=value) return context diff --git a/RIGS/migrations/0043_auto_20201010_1320.py b/RIGS/migrations/0043_auto_20201010_1320.py new file mode 100644 index 00000000..74aaab87 --- /dev/null +++ b/RIGS/migrations/0043_auto_20201010_1320.py @@ -0,0 +1,27 @@ +# Generated by Django 3.1.2 on 2020-10-10 12:20 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('RIGS', '0042_riskassessment_supervisor_consulted'), + ] + + operations = [ + migrations.AddField( + model_name='eventchecklist', + name='date', + field=models.DateField(default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='eventchecklist', + name='venue', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='RIGS.venue'), + preserve_default=False, + ), + ] diff --git a/RIGS/models.py b/RIGS/models.py index 458b9929..20b86ddb 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -690,6 +690,7 @@ class RiskAssessment(models.Model, RevisionMixin): 'special_structures': False, 'suspended_structures': False, } + #inverted_fields = filter(lambda key,value: value, expected_values.items()) class Meta: ordering = ['event'] @@ -719,6 +720,8 @@ class EventChecklist(models.Model, RevisionMixin): # General power_mic = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name='checklists', verbose_name="Power MIC", on_delete=models.CASCADE, help_text="Who is the Power MIC?") + venue = models.ForeignKey('Venue', on_delete=models.CASCADE) + date = models.DateField() # Safety Checks safe_parking = models.BooleanField(blank=True, null=True, help_text="Vehicles parked safely?
(does not obstruct venue access)") diff --git a/RIGS/templates/event_checklist_detail.html b/RIGS/templates/event_checklist_detail.html index 27f271ec..d7aa983d 100644 --- a/RIGS/templates/event_checklist_detail.html +++ b/RIGS/templates/event_checklist_detail.html @@ -5,238 +5,248 @@ {% load button from filters %} {% block content %} -
-
-
-
- {% 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' %} -
-
-
-
-
-
General
-
-
-
{{ object|help_text:'power_mic' }}
-
- {{ object.power_mic.name }} -
-
-

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 %} - - - - - - - {% endfor %} - -
CrewmemberStart TimeRoleEnd Time
{{crew.crewmember}}{{crew.start}}{{crew.role}}{{crew.end}}
-
-
-
Power {% if object.event_size == 2 %} - Large Event - {% elif object.event_size == 1 %} - Medium Event - {%else%}Small Event - {%endif%}
- {% if object.event_size != 2 %} -
- {% if object.event_size == 1 %} -
-
{{ 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' %} - {% else %} -
-
{{ 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 }} -
-
+
+
+ {% 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' %} +
+
+
+
+
+
General
+
+
+
Date
+
+ {{ object.date }} +
+
Venue
+
+ {% if object.venue %} + + {{ object.venue }} + {% endif %} -
- {% endif %} + +
{{ object|help_text:'power_mic' }}
+
+ {{ object.power_mic.name }} +
+ +

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 }} +
+
-
- {% 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" %} -
+
+
Crew Record
+
+ + + + + + + + + + + {% for crew in object.crew.all %} + + + + + + + {% endfor %} + +
CrewmemberStart TimeRoleEnd Time
{{crew.crewmember}}{{crew.start}}{{crew.role}}{{crew.end}}
+
+
+
+
Power {% if object.event_size == 2 %} + Large Event + {% elif object.event_size == 1 %} + Medium Event + {%else%}Small Event + {%endif%}
+ {% if object.event_size != 2 %} +
+ {% if object.event_size == 1 %} +
+
{{ 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' %} + {% else %} +
+
{{ 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 }} +
+
+ {% endif %} +
+ {% 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 index e8333fa1..d48e54e8 100644 --- a/RIGS/templates/event_checklist_form.html +++ b/RIGS/templates/event_checklist_form.html @@ -114,19 +114,37 @@
{{ event.name }}
Client
{{ event.person }}
-
Venue
-
{{ event.venue }}
-
- -
- -
+
+ + {% 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

diff --git a/RIGS/templates/hs_list.html b/RIGS/templates/hs_list.html index 173484df..74c3b517 100644 --- a/RIGS/templates/hs_list.html +++ b/RIGS/templates/hs_list.html @@ -30,7 +30,7 @@ {% 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 %} - diff --git a/RIGS/templatetags/filters.py b/RIGS/templatetags/filters.py index 82a9f78b..24434f3f 100644 --- a/RIGS/templatetags/filters.py +++ b/RIGS/templatetags/filters.py @@ -47,6 +47,7 @@ def nice_errors(form, non_field_msg='General form errors', autoescape=True): return nice_errors +@register.inclusion_tag('pagination.html', takes_context=True) def paginator(context, adjacent_pages=3): """ To be used in conjunction with the object_list generic view. @@ -90,9 +91,6 @@ def paginator(context, adjacent_pages=3): return dict -register.inclusion_tag('pagination.html', takes_context=True)(paginator) - - @register.simple_tag def url_replace(request, field, value): dict_ = request.GET.copy() @@ -123,7 +121,7 @@ def orderby(request, field, attr): def get_field(obj, field, autoescape=True): value = getattr(obj, field) if(isinstance(value, bool)): - value = yesnoi(value) + value = yesnoi(value, field in obj.inverted_fields) elif(isinstance(value, str)): value = truncatewords(value, 20) return mark_safe(value)