511 """Handles the GET request for the Survey's take page. |
511 """Handles the GET request for the Survey's take page. |
512 |
512 |
513 Args: |
513 Args: |
514 template: the template used for this view |
514 template: the template used for this view |
515 entity: the Survey entity |
515 entity: the Survey entity |
|
516 record: a SurveyRecord entity |
516 rest: see base.View.public() |
517 rest: see base.View.public() |
517 """ |
518 """ |
518 |
519 |
519 survey_form = surveys.SurveyForm(survey_content=entity.survey_content, |
520 survey_form = surveys.SurveyForm(survey_content=entity.survey_content, |
520 survey_record=record, |
521 survey_record=record, |
524 |
525 |
525 # fill context with the survey and additional information |
526 # fill context with the survey and additional information |
526 context['survey_form'] = survey_form |
527 context['survey_form'] = survey_form |
527 self.setHelpAndStatus(context, entity, record) |
528 self.setHelpAndStatus(context, entity, record) |
528 |
529 |
|
530 # call the hook method |
|
531 self._takeGet(request, template, context, params, entity, record, **kwargs) |
|
532 |
529 return responses.respond(request, template, context) |
533 return responses.respond(request, template, context) |
|
534 |
|
535 def _takeGet(self, request, template, context, params, entity, record, |
|
536 **kwargs): |
|
537 """Hook for the GET request for the Survey's take page. |
|
538 |
|
539 This method is called just before the GET page is shown. |
|
540 |
|
541 Args: |
|
542 template: the template used for this view |
|
543 entity: the Survey entity |
|
544 record: a SurveyRecord entity |
|
545 rest: see base.View.public() |
|
546 """ |
|
547 pass |
530 |
548 |
531 def takePost(self, request, template, context, params, entity, record, |
549 def takePost(self, request, template, context, params, entity, record, |
532 **kwargs): |
550 **kwargs): |
533 """Handles the POST request for the Survey's take page. |
551 """Handles the POST request for the Survey's take page. |
534 |
552 |
535 Args: |
553 Args: |
536 template: the template used for this view |
554 template: the template used for this view |
537 entity: the Survey entity |
555 entity: the Survey entity |
|
556 record: a SurveyRecord entity |
538 rest: see base.View.public() |
557 rest: see base.View.public() |
539 """ |
558 """ |
540 |
559 |
541 survey_logic = params['logic'] |
560 survey_logic = params['logic'] |
542 record_logic = survey_logic.getRecordLogic() |
561 record_logic = survey_logic.getRecordLogic() |
545 properties = surveys.getSurveyResponseFromPost(entity, request.POST) |
564 properties = surveys.getSurveyResponseFromPost(entity, request.POST) |
546 |
565 |
547 # add the required SurveyRecord properties |
566 # add the required SurveyRecord properties |
548 properties['user'] = user_logic.getForCurrentAccount() |
567 properties['user'] = user_logic.getForCurrentAccount() |
549 properties['survey'] = entity |
568 properties['survey'] = entity |
|
569 |
|
570 # call the hook method before updating the SurveyRecord |
|
571 self._takePost(request, params, entity, record, properties) |
550 |
572 |
551 # update the record entity if any and clear all dynamic properties |
573 # update the record entity if any and clear all dynamic properties |
552 record_logic.updateOrCreateFromFields(record, properties, clear_dynamic=True) |
574 record_logic.updateOrCreateFromFields(record, properties, clear_dynamic=True) |
553 |
575 |
554 # TODO: add notice to page that the response has been saved successfully |
576 # TODO: add notice to page that the response has been saved successfully |
555 # redirect to the same page for now |
577 # redirect to the same page for now |
556 redirect = request.path |
578 redirect = request.path |
557 return http.HttpResponseRedirect(redirect) |
579 return http.HttpResponseRedirect(redirect) |
|
580 |
|
581 def _takePost(self, request, params, entity, record, properties): |
|
582 """Hook for the POST request for the Survey's take page. |
|
583 |
|
584 This method is called just before the SurveyRecord is stored. |
|
585 |
|
586 Args: |
|
587 request: Django Request object |
|
588 params: the params for the current view |
|
589 entity: a Survey entity |
|
590 record: a SurveyRecord entity |
|
591 properties: properties to be stored in the SurveyRecord entity |
|
592 """ |
|
593 pass |
558 |
594 |
559 def setHelpAndStatus(self, context, survey, survey_record): |
595 def setHelpAndStatus(self, context, survey, survey_record): |
560 """Get help_text and status for template use. |
596 """Get help_text and status for template use. |
561 |
597 |
562 Args: |
598 Args: |