533 'user': user_entity} |
533 'user': user_entity} |
534 |
534 |
535 return record_logic.getForFields(filter, unique=True) |
535 return record_logic.getForFields(filter, unique=True) |
536 |
536 |
537 def takeGet(self, request, template, context, params, entity, record, |
537 def takeGet(self, request, template, context, params, entity, record, |
538 form_data=None, **kwargs): |
538 **kwargs): |
539 """Handles the GET request for the Survey's take page. |
539 """Handles the GET request for the Survey's take page. |
540 |
540 |
541 Args: |
541 Args: |
542 template: the template used for this view |
542 template: the template used for this view |
543 entity: the Survey entity |
543 entity: the Survey entity |
544 record: a SurveyRecord entity |
544 record: a SurveyRecord entity |
545 form_data: dict with form data that will be used for validation |
|
546 rest: see base.View.public() |
545 rest: see base.View.public() |
547 """ |
546 """ |
548 |
547 |
549 survey_form = surveys.SurveyForm(survey_content=entity.survey_content, |
548 survey_form = surveys.SurveyForm(survey_content=entity.survey_content, |
550 survey_record=record, |
549 survey_record=record, |
551 survey_logic=self._params['logic']) |
550 survey_logic=self._params['logic']) |
552 |
551 |
553 # fetch field contents and pass request data, if any |
552 # fetch field contents |
554 survey_form.getFields(post_dict=form_data) |
553 survey_form.getFields() |
555 |
554 |
556 # fill context with the survey and additional information |
555 # fill context with the survey and additional information |
557 context['survey_form'] = survey_form |
556 context['survey_form'] = survey_form |
558 self.setHelpAndStatus(context, entity, record) |
557 self.setHelpAndStatus(context, entity, record) |
559 |
|
560 # validate request data |
|
561 if form_data and not survey_form.is_valid(): |
|
562 return self._constructResponse(request, entity=entity, context=context, |
|
563 form=survey_form, params=params, template=template) |
|
564 |
558 |
565 # call the hook method |
559 # call the hook method |
566 self._takeGet(request, template, context, params, entity, record, **kwargs) |
560 self._takeGet(request, template, context, params, entity, record, **kwargs) |
567 |
561 |
568 return responses.respond(request, template, context) |
562 return responses.respond(request, template, context) |
601 survey_logic=self._params['logic']) |
595 survey_logic=self._params['logic']) |
602 # fill form with request data |
596 # fill form with request data |
603 survey_form.getFields(post_dict=request.POST) |
597 survey_form.getFields(post_dict=request.POST) |
604 |
598 |
605 if not survey_form.is_valid(): |
599 if not survey_form.is_valid(): |
606 # redirect to takeGet so we can handle errors |
600 # fill context with the survey and additional information |
607 return self.takeGet(request, template, context, params, entity, record, |
601 context['survey_form'] = survey_form |
608 form_data=request.POST) |
602 self.setHelpAndStatus(context, entity, record) |
|
603 # show the form errors |
|
604 return self._constructResponse(request, entity=entity, context=context, |
|
605 form=survey_form, params=params, |
|
606 template=template) |
609 |
607 |
610 # retrieve the data from the form |
608 # retrieve the data from the form |
611 _, properties = forms_helper.collectCleanedFields(survey_form) |
609 _, properties = forms_helper.collectCleanedFields(survey_form) |
612 |
610 |
613 # add the required SurveyRecord properties |
611 # add the required SurveyRecord properties |