Merge pull request #1087 from DerPate/master

Agenda Item Time input fixes #1085
This commit is contained in:
Oskar Hahn 2013-11-21 10:41:33 -08:00
commit daf272d09e
2 changed files with 15 additions and 7 deletions

View File

@ -23,7 +23,7 @@ class ItemForm(CleanHtmlFormMixin, CssClassMixin, forms.ModelForm):
queryset=Item.objects.all(), label=ugettext_lazy("Parent item"), required=False) queryset=Item.objects.all(), label=ugettext_lazy("Parent item"), required=False)
duration = forms.RegexField( duration = forms.RegexField(
regex=re.compile('[0-99]:[0-5][0-9]'), regex=re.compile('^(?:[0-9]{1,2}:[0-5][0-9]|[0-9]+)$'),
error_message=ugettext_lazy("Invalid format. Hours from 0 to 99 and minutes from 00 to 59"), error_message=ugettext_lazy("Invalid format. Hours from 0 to 99 and minutes from 00 to 59"),
max_length=5, max_length=5,
required=False, required=False,

View File

@ -57,11 +57,19 @@ class Overview(TemplateView):
duration = timedelta() duration = timedelta()
for item in items: for item in items:
if (item.duration is not None and if item.duration is not None and len(item.duration) > 0:
len(item.duration) > 0): if ':' in item.duration:
duration_list = item.duration.split(':') duration_list = item.duration.split(':')
duration += timedelta(hours=int(duration_list[0]), duration += timedelta(hours=int(duration_list[0]),
minutes=int(duration_list[1])) minutes=int(duration_list[1]))
else:
hours = int(item.duration) / 60
minutes = int(item.duration) - (60 * hours)
duration += timedelta(hours=hours,
minutes=minutes)
if minutes < 10:
minutes = "%s%s" % (0, minutes)
item.duration = "%s:%s" % (hours, minutes)
if not start is None: if not start is None:
item.tooltip = start + duration item.tooltip = start + duration
@ -118,7 +126,7 @@ class Overview(TemplateView):
break break
else: else:
Item.objects.rebuild() Item.objects.rebuild()
# TODO: assure, that it is a valid tree # TODO: assure, that it is a valid tree
context = self.get_context_data(**kwargs) context = self.get_context_data(**kwargs)
transaction.commit() transaction.commit()