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