Project

General

Profile

« Previous | Next » 

Revision cb424fd8

Added by Mikaël Ates about 12 years ago

statistics: refactor forms.

View differences:

calebasse/statistics/forms.py
from statistics import Statistic
class StatForm(Form):
class BaseForm(Form):
display_or_export = forms.BooleanField(label=u'Exporter dans un fichier', required=False, localize=True)
start_date = forms.DateField(label=u'Date de début', required=False, localize=True)
end_date = forms.DateField(label=u'Date de fin', required=False, localize=True)
patients = make_ajax_field(Statistic, 'patients', 'patientrecord', True)
participants = make_ajax_field(Statistic, 'participants', 'worker-or-group', True)
class ActivePatientsForm(Form):
display_or_export = forms.BooleanField(label=u'Exporter dans un fichier', required=False, localize=True)
class OneDateForm(BaseForm):
start_date = forms.DateField(label=u'Date', required=False, localize=True)
class TwoDatesForm(BaseForm):
start_date = forms.DateField(label=u'Date de début', required=False, localize=True)
end_date = forms.DateField(label=u'Date de fin', required=False, localize=True)
class AnnualActivityForm(Form):
display_or_export = forms.BooleanField(label=u'Exporter dans un fichier', required=False, localize=True)
class AnnualActivityForm(BaseForm):
start_date = forms.DateField(label=u"Date de l'année souhaitée", required=False, localize=True)
participants = make_ajax_field(Statistic, 'participants', 'worker-or-group', True)
class PatientsDetailsForm(Form):
display_or_export = forms.BooleanField(label=u'Exporter dans un fichier', required=False, localize=True)
start_date = forms.DateField(label=u'Date de début', required=False, localize=True)
end_date = forms.DateField(label=u'Date de fin', required=False, localize=True)
class PatientsTwoDatesForm(TwoDatesForm):
patients = make_ajax_field(Statistic, 'patients', 'patientrecord', True)
class ParticipantsPatientsTwoDatesForm(PatientsTwoDatesForm):
participants = make_ajax_field(Statistic, 'participants', 'worker-or-group', True)
calebasse/statistics/views.py
def get_form_class(self):
if self.name == 'annual_activity':
return forms.AnnualActivityForm
if self.name == 'patients_details':
return forms.PatientsDetailsForm
elif self.name in ('active_patients', 'closed_files',
elif self.name == 'patients_details':
return forms.PatientsTwoDatesForm
elif self.name == 'active_patients_by_state_only':
return forms.OneDateForm
elif self.name in ('active_patients_with_act', 'closed_files',
'patients_synthesis', 'acts_synthesis',
'acts_synthesis_cmpp', 'mises'):
return forms.ActivePatientsForm
return forms.TwoDatesForm
else:
return forms.StatForm
return forms.ParticipantsPatientsTwoDatesForm
def form_valid(self, form):
if 'display_or_export' in form.data:

Also available in: Unified diff