Minor fixes

This commit is contained in:
2020-09-19 13:39:58 +01:00
parent 31f63ba5c7
commit 1ea8090668
3 changed files with 13 additions and 7 deletions

View File

@@ -469,19 +469,23 @@ class Event(models.Model, RevisionMixin):
return self.display_id + ": " + self.name
def clean(self):
errdict = {}
if self.end_date and self.start_date > self.end_date:
raise ValidationError('Unless you\'ve invented time travel, the event can\'t finish before it has started.')
errdict['end_date'] = ['Unless you\'ve invented time travel, the event can\'t finish before it has started.']
startEndSameDay = not self.end_date or self.end_date == self.start_date
hasStartAndEnd = self.has_start_time and self.has_end_time
if startEndSameDay and hasStartAndEnd and self.start_time > self.end_time:
raise ValidationError('Unless you\'ve invented time travel, the event can\'t finish before it has started.')
errdict['end_time'] = ['Unless you\'ve invented time travel, the event can\'t finish before it has started.']
if self.access_at is not None:
if self.access_at.date() > self.start_date:
raise ValidationError('Regardless of what some clients might think, access time cannot be after the event has started.')
errdict['access_at'] = ['Regardless of what some clients might think, access time cannot be after the event has started.']
elif self.start_time is not None and self.start_date == self.access_at.date() and self.access_at.time() > self.start_time:
raise ValidationError('Regardless of what some clients might think, access time cannot be after the event has started.')
errdict['access_at'] = ['Regardless of what some clients might think, access time cannot be after the event has started.']
if errdict != {}: # If there was an error when validation
raise ValidationError(errdict)
def save(self, *args, **kwargs):
"""Call :meth:`full_clean` before saving."""

View File

@@ -142,7 +142,9 @@
{% endif %}
</h2>
</div>
{% include 'form_errors.html' %}
<div class="col-12">
{% include 'form_errors.html' %}
</div>
{% render_field form.is_rig style="display: none" %}
<input type="hidden" name="{{ form.items_json.name }}" id="{{ form.items_json.id_for_label }}"
value="{{ form.items_json.value }}"/>

View File

@@ -31,11 +31,11 @@
</dd>
<dt class="col-10">{{ object|help_text:'other_companies' }}</dt>
<dd class="col-2">
{{ object.othercompanies|yesnoi:'invert' }}
{{ object.other_companies|yesnoi:'invert' }}
</dd>
<dt class="col-10">{{ object|help_text:'crew_fatigue' }}</dt>
<dd class="col-2">
{{ object.crewfatigue|yesnoi:'invert' }}
{{ object.crew_fatigue|yesnoi:'invert' }}
</dd>
<dt class="col-12">{{ object|help_text:'general_notes' }}</dt>
<dd class="col-12">