From 8e6269b495fdd9fbeb67cf3b00f178d57ed5db4a Mon Sep 17 00:00:00 2001 From: Dominik Breu Date: Tue, 19 Nov 2013 13:48:55 +0100 Subject: [PATCH] fix #1085 maybe could be done better but for 1.5 integration this could be used . input 60< is converted to hh:mm --- openslides/agenda/forms.py | 2 +- openslides/agenda/views.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/openslides/agenda/forms.py b/openslides/agenda/forms.py index dd854e03c..e4cb375d9 100644 --- a/openslides/agenda/forms.py +++ b/openslides/agenda/forms.py @@ -23,7 +23,7 @@ class ItemForm(CleanHtmlFormMixin, CssClassMixin, forms.ModelForm): queryset=Item.objects.all(), label=ugettext_lazy("Parent item"), required=False) 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"), max_length=5, required=False, diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index 3a6ae2d66..18637e688 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -57,11 +57,19 @@ class Overview(TemplateView): duration = timedelta() for item in items: - if (item.duration is not None and - len(item.duration) > 0): - duration_list = item.duration.split(':') - duration += timedelta(hours=int(duration_list[0]), - minutes=int(duration_list[1])) + if item.duration is not None and len(item.duration) > 0: + if ':' in item.duration: + duration_list = item.duration.split(':') + duration += timedelta(hours=int(duration_list[0]), + 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: item.tooltip = start + duration @@ -118,7 +126,7 @@ class Overview(TemplateView): break else: 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) transaction.commit()