fix #1085 maybe could be done better but for 1.5 integration this could be used . input 60< is converted to hh:mm

This commit is contained in:
Dominik Breu 2013-11-19 13:48:55 +01:00
parent d889be6db6
commit 8e6269b495
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)
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,

View File

@ -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()