mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 13:32:15 +00:00
Javascript required shenanigans for RA power
This commit is contained in:
@@ -640,10 +640,10 @@ class RiskAssessment(models.Model, RevisionMixin):
|
||||
# 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...
|
||||
power_mic = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='power_mic', blank=True, null=True,
|
||||
verbose_name="Power MIC", on_delete=models.CASCADE, help_text="Who is the Power MIC?")
|
||||
verbose_name="Power MIC", on_delete=models.CASCADE, help_text="Who is the Power MIC? (if yes to the above question, this person <em>must</em> be a Power Technician or Power Supervisor)")
|
||||
outside = models.BooleanField(help_text="Is the event outdoors?")
|
||||
generators = models.BooleanField(help_text="Will generators be used?")
|
||||
other_companies_power = models.BooleanField(help_text="Will TEC be supplying power to any other companies?")
|
||||
nonstandard_equipment_power = 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?")
|
||||
@@ -704,11 +704,10 @@ class RiskAssessment(models.Model, RevisionMixin):
|
||||
# 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:
|
||||
# Confirm event size. Check all except generators, since generators entails outside
|
||||
if self.outside or self.other_companies_power or self.nonstandard_equipment_power or self.multiple_electrical_environments:
|
||||
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:
|
||||
elif self.big_power:
|
||||
self.event_size = self.MEDIUM[0]
|
||||
else:
|
||||
self.event_size = self.SMALL[0]
|
||||
|
||||
@@ -24,6 +24,24 @@
|
||||
<script src="{% static 'js/tooltip.js' %}"></script>
|
||||
|
||||
<script src="{% static 'js/autocompleter.js' %}"></script>
|
||||
|
||||
<script>
|
||||
function parseBool(str) {
|
||||
if (str.toLowerCase() == 'true') {
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
$('input[type=radio][name=big_power]').change(function() {
|
||||
$('#{{ form.power_mic.id_for_label }}').prop('required', parseBool(this.value));
|
||||
});
|
||||
$('input[type=radio][name=outside], input[type=radio][name=generators], input[type=radio][name=other_companies_power], input[type=radio][name=nonstandard_equipment_power], input[type=radio][name=multiple_electrical_environments]').change(function() {
|
||||
$('#{{ form.power_notes.id_for_label }}').prop('required', parseBool(this.value));
|
||||
$('#{{ form.power_plan.id_for_label }}').prop('required', parseBool(this.value));
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
@@ -83,17 +101,17 @@
|
||||
<div class="card-header">Power</div>
|
||||
<div class="card-body">
|
||||
{% include 'partials/yes_no_radio.html' with formitem=form.big_power %}
|
||||
{% include 'partials/yes_no_radio.html' with formitem=form.outside %}
|
||||
<label for="{{ form.power_mic.id_for_label }}"
|
||||
class="col-sm-8 col-form-label">{{ form.power_mic.help_text }}</label>
|
||||
<div class="col-sm-8">
|
||||
class="col col-form-label">{{ form.power_mic.help_text|safe }}</label>
|
||||
<div class="col-6">
|
||||
<select id="{{ form.power_mic.id_for_label }}" name="{{ form.power_mic.name }}" class="form-control selectpicker" data-live-search="true" data-sourceurl="{% url 'api_secure' model='profile' %}?fields=first_name,last_name,initials">
|
||||
{% if object.power_mic %}
|
||||
<option value="{{object.power_mic.pk}}" selected="selected">{{ object.power_mic.name }}</option>
|
||||
{% endif %}
|
||||
</select>
|
||||
</div>
|
||||
<p class="pt-4"><strong>If the answer is yes to any of the below questions you must consult a power supervisor</strong></p>
|
||||
<p class="pt-4"><strong>If the answer is yes to any of the below questions this is a Large Event and you <em>must</em> consult a power supervisor</strong></p>
|
||||
{% 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 %}
|
||||
|
||||
Reference in New Issue
Block a user