Skip to content

Commit

Permalink
Winterthur: Adapts UI for multi missions
Browse files Browse the repository at this point in the history
- Make time field required
- Always display correct time
- Remove mission count from /mission-reports table
  • Loading branch information
Lukas Burkhard committed Jun 16, 2021
2 parents f3caf5e + cac93b1 commit 673cf13
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
18 changes: 6 additions & 12 deletions src/onegov/winterthur/forms/mission_report.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import sedate

from datetime import datetime
from datetime import time
from onegov.file.utils import IMAGE_MIME_TYPES_AND_SVG
from onegov.form import Form
from onegov.form.fields import UploadFileWithORMSupport
from onegov.form.validators import FileSizeLimit, StrictOptional
from onegov.form.validators import FileSizeLimit
from onegov.form.validators import WhitelistedMimeType
from onegov.winterthur import _
from onegov.winterthur.models import MissionReportFile
Expand All @@ -31,7 +30,10 @@ class MissionReportForm(Form):
default=today,
validators=[InputRequired()])

time = TimeField(_("Time"), validators=[StrictOptional()])
time = TimeField(
_("Time"),
validators=[InputRequired()]
)

duration = DecimalField(
_("Mission duration (h)"),
Expand Down Expand Up @@ -75,8 +77,7 @@ class MissionReportForm(Form):

@property
def date(self):
dt = datetime.combine(
self.day.data, self.time.data or time(hour=0, minute=0))
dt = datetime.combine(self.day.data, self.time.data)
return sedate.replace_timezone(dt, timezone='Europe/Zurich')

@date.setter
Expand All @@ -89,13 +90,6 @@ def on_request(self):
if self.request.app.hide_civil_defence_field:
self.delete_field('civil_defence')

def ensure_correct_time(self):
if not self.day.data:
return
if self.mission_type.data == 'single' and not self.time.data:
self.time.errors.append(_('This field is required.'))
return False

def ensure_correct_mission_count(self):
if self.mission_type.data == 'single':
if self.mission_count.data > 1:
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/winterthur/templates/mission_report.pt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</tr>
<tr>
<td class="min-width-column" i18n:translate>Alarm</td>
<td tal:define="hour model.local_date.strftime('%H:%M')">${'-' if hour == '00:00' else hour}</td>
<td tal:define="hour model.local_date.strftime('%H:%M')">${hour}</td>
</tr>
<tr>
<td class="min-width-column" i18n:translate>Location</td>
Expand Down
6 changes: 1 addition & 5 deletions src/onegov/winterthur/templates/mission_reports.pt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<th class="min-width-column" i18n:translate>Date</th>
<th class="min-width-column" i18n:translate>Alarm</th>
<th class="min-width-column" i18n:translate>Duration</th>
<th class="min-width-column" i18n:translate># Missions</th>
<th i18n:translate>Mission nature</th>
<th class="min-width-column" i18n:translate>Location</th>
<th class="min-width-column">
Expand All @@ -30,14 +29,11 @@
${report.local_date.strftime('%d.%m.%Y')}
</td>
<td data-label="Alarm" i18n:attributes="data-label" class="min-width-column" tal:define="hour report.local_date.strftime('%H:%M')">
${'-' if hour == '00:00' else hour}
${hour}
</td>
<td data-label="Duration" i18n:attributes="data-label" class="min-width-column">
${report.readable_duration}
</td>
<td class="mission-count" data-label="# Missions" i18n:attributes="data-label">
${report.mission_count}
</td>
<td class="mission-nature" data-label="Mission nature" i18n:attributes="data-label">
<div><a href="${request.link(report)}">${report.nature}</a></div>
<tal:b define="used_vehicles report.used_vehicles" condition="report.used_vehicles">
Expand Down
3 changes: 2 additions & 1 deletion tests/onegov/winterthur/test_mission_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def test_view_mission_reports(winterthur_app):
# change the mode to multi
page.form['mission_type'] = 'multi'
page.form['mission_count'] = 5
page.form['time'] = '00:00'
entry = page.form.submit().follow()
# setting the time for the date to midnight
assert '-' in entry.pyquery('tr td:last-of-type')[1].text
assert '00:00' in entry.pyquery('tr td:last-of-type')[1].text
assert entry.pyquery('#mission-count')[0].text == '5'
assert entry.pyquery('#mission-type')[0].text == 'Mehrfach-Einsatz'

Expand Down

0 comments on commit 673cf13

Please sign in to comment.