Commit 81e658afac1425b8117fc93505608c222940b2af

Authored by fbormann
1 parent 3be7ec9d

end_date and init_date of reportForm created

Showing 2 changed files with 14 additions and 1 deletions   Show diff stats
reports/forms.py
@@ -20,6 +20,18 @@ class CreateInteractionReportForm(forms.Form): @@ -20,6 +20,18 @@ class CreateInteractionReportForm(forms.Form):
20 20
21 initial = kwargs['initial'] 21 initial = kwargs['initial']
22 topics = list(initial['topic']) 22 topics = list(initial['topic'])
23 - 23 + self.subject = initial['subject'] #so we can check date cleaned data
24 self.fields['topic'].choices = [(topic.id, topic.name) for topic in topics] 24 self.fields['topic'].choices = [(topic.id, topic.name) for topic in topics]
25 self.fields['topic'].choices.append((_("All"), _("All"))) 25 self.fields['topic'].choices.append((_("All"), _("All")))
  26 +
  27 + def clean_init_date(self):
  28 + init_date = self.cleaned_data.get('init_date')
  29 + if init_date < self.subject.init_date:
  30 + self._errors['init_date'] = [_('This date should be right or after ' + str(self.subject.init_date) + ', which is when the subject started. ')]
  31 + return init_date
  32 +
  33 + def clean_end_date(self):
  34 + end_date = self.cleaned_data.get('init_date')
  35 + if end_date > self.subject.init_date:
  36 + self._errors['end_date'] = [_('This date should be right or before ' + str(self.subject.init_date) + ', which is when the subject finishes. ')]
  37 + return end_date
26 \ No newline at end of file 38 \ No newline at end of file
reports/views.py
@@ -30,6 +30,7 @@ class ReportView(LoginRequiredMixin, generic.FormView): @@ -30,6 +30,7 @@ class ReportView(LoginRequiredMixin, generic.FormView):
30 params = self.request.GET 30 params = self.request.GET
31 subject = Subject.objects.get(id=params['subject_id']) 31 subject = Subject.objects.get(id=params['subject_id'])
32 topics = subject.topic_subject.all() 32 topics = subject.topic_subject.all()
  33 + initial['subject'] = subject
33 initial['topic'] = topics 34 initial['topic'] = topics
34 initial['end_date'] = date.today() 35 initial['end_date'] = date.today()
35 return initial 36 return initial