When editing interim meeting request show duration as HH:MM instead of HH:MM:SS. Fixes #2226. Commit ready for merge.
- Legacy-Id: 13337
This commit is contained in:
parent
7542e8daa3
commit
066de1e612
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import codecs
|
||||
import datetime
|
||||
|
||||
from django import forms
|
||||
from django.db.models import Q
|
||||
|
@ -33,6 +34,32 @@ class GroupModelChoiceField(forms.ModelChoiceField):
|
|||
def label_from_instance(self, obj):
|
||||
return obj.acronym
|
||||
|
||||
class CustomDurationField(DurationField):
|
||||
'''Custom DurationField to display as HH:MM (no seconds)'''
|
||||
def prepare_value(self, value):
|
||||
if isinstance(value, datetime.timedelta):
|
||||
return duration_string(value)
|
||||
return value
|
||||
|
||||
def duration_string(duration):
|
||||
'''Custom duration_string to return HH:MM (no seconds)'''
|
||||
days = duration.days
|
||||
seconds = duration.seconds
|
||||
microseconds = duration.microseconds
|
||||
|
||||
minutes = seconds // 60
|
||||
seconds = seconds % 60
|
||||
|
||||
hours = minutes // 60
|
||||
minutes = minutes % 60
|
||||
|
||||
string = '{:02d}:{:02d}'.format(hours, minutes)
|
||||
if days:
|
||||
string = '{} '.format(days) + string
|
||||
if microseconds:
|
||||
string += '.{:06d}'.format(microseconds)
|
||||
|
||||
return string
|
||||
# -------------------------------------------------
|
||||
# Forms
|
||||
# -------------------------------------------------
|
||||
|
@ -160,7 +187,7 @@ class InterimMeetingModelForm(forms.ModelForm):
|
|||
class InterimSessionModelForm(forms.ModelForm):
|
||||
date = DatepickerDateField(date_format="yyyy-mm-dd", picker_settings={"autoclose": "1"}, label='Date', required=False)
|
||||
time = forms.TimeField(widget=forms.TimeInput(format='%H:%M'), required=True)
|
||||
requested_duration = DurationField(required=True)
|
||||
requested_duration = CustomDurationField(required=True)
|
||||
end_time = forms.TimeField(required=False)
|
||||
remote_instructions = forms.CharField(max_length=1024, required=True)
|
||||
agenda = forms.CharField(required=False, widget=forms.Textarea, strip=False)
|
||||
|
|
Loading…
Reference in a new issue