diff --git a/smash/web/forms/forms.py b/smash/web/forms/forms.py index acead32df6e5e1401a5346ecbec59be00aac8d8d..805f2e72684e1274bc064633bfa71bafd15a0b7d 100644 --- a/smash/web/forms/forms.py +++ b/smash/web/forms/forms.py @@ -7,8 +7,10 @@ from django.utils.dates import MONTHS from web.models import Appointment, AppointmentType, AppointmentTypeLink, \ Availability, ContactAttempt, FlyingTeam, Holiday, Item, \ - StudySubject, Room, Worker, Visit, VoucherType, VoucherTypePrice -from web.models.constants import SUBJECT_TYPE_CHOICES + StudySubject, Room, Worker, Visit, VoucherType, VoucherTypePrice, ConfigurationItem +from web.models.constants import SUBJECT_TYPE_CHOICES, VISIT_SHOW_VISIT_NUMBER_FROM_ZERO +from distutils.util import strtobool +from web.templatetags.filters import display_visit_number """ Possible redundancy, but if need arises, contents of forms can be easily customized @@ -127,6 +129,16 @@ class StatisticsForm(Form): choices = [(-1, "all")] choices.extend(SUBJECT_TYPE_CHOICES.items()) self.fields['subject_type'] = forms.ChoiceField(choices=choices, initial="-1") + visit_from_zero = ConfigurationItem.objects.get(type=VISIT_SHOW_VISIT_NUMBER_FROM_ZERO).value + #True values are y, yes, t, true, on and 1; false values are n, no, f, false, off and 0. + if strtobool(visit_from_zero): + new_choices = [] + for value, label in visit_choices: + if int(value) > 0: + label = display_visit_number(label) + new_choices.append((value, label)) + visit_choices = new_choices + self.fields['visit'] = forms.ChoiceField(choices=visit_choices, initial="-1")