192 'last_modified_by': forms.fields.CharField( |
192 'last_modified_by': forms.fields.CharField( |
193 widget=widgets.ReadOnlyInput(), required=False), |
193 widget=widgets.ReadOnlyInput(), required=False), |
194 'clean': cleaning.validate_document_acl(self), |
194 'clean': cleaning.validate_document_acl(self), |
195 } |
195 } |
196 |
196 |
|
197 new_params['survey_take_form'] = surveys.SurveyTakeForm |
|
198 |
197 params = dicts.merge(params, new_params, sub_merge=True) |
199 params = dicts.merge(params, new_params, sub_merge=True) |
198 |
200 |
199 super(View, self).__init__(params=params) |
201 super(View, self).__init__(params=params) |
200 |
202 |
201 def list(self, request, access_type, page_name=None, params=None, |
203 def list(self, request, access_type, page_name=None, params=None, |
215 context: the context object |
217 context: the context object |
216 """ |
218 """ |
217 |
219 |
218 # construct the form to be shown on the page |
220 # construct the form to be shown on the page |
219 # TODO(ljvderijk) Generate SurveyForm without passing along the logic |
221 # TODO(ljvderijk) Generate SurveyForm without passing along the logic |
220 survey_form = surveys.SurveyTakeForm(survey_content=entity.survey_content, |
222 survey_form = self._params['survey_take_form']( |
221 survey_logic=self._params['logic']) |
223 survey_content=entity.survey_content, survey_logic=self._params['logic']) |
222 |
224 |
223 survey_form.getFields() |
225 survey_form.getFields() |
224 |
226 |
225 context['survey_form'] = survey_form |
227 context['survey_form'] = survey_form |
226 |
228 |
499 |
501 |
500 # try to get an existing SurveyRecord for the current user |
502 # try to get an existing SurveyRecord for the current user |
501 survey_record = self._getSurveyRecordFor(entity, request, params) |
503 survey_record = self._getSurveyRecordFor(entity, request, params) |
502 |
504 |
503 # get an instance of SurveyTakeForm to use |
505 # get an instance of SurveyTakeForm to use |
504 survey_form = self._getSurveyTakeForm(entity, survey_record, params, |
506 survey_form = params['survey_take_form']( |
505 request.POST) |
507 survey_content=survey.survey_content, |
|
508 survey_record=record, |
|
509 survey_logic=params['logic'], |
|
510 data=post_dict) |
506 |
511 |
507 # fill context with the survey_form and additional information |
512 # fill context with the survey_form and additional information |
508 context['survey_form'] = survey_form |
513 context['survey_form'] = survey_form |
509 self._setSurveyTakeContext(request, params, context, entity, survey_record) |
514 self._setSurveyTakeContext(request, params, context, entity, survey_record) |
510 |
515 |
535 |
540 |
536 filter = {'survey': survey, |
541 filter = {'survey': survey, |
537 'user': user_entity} |
542 'user': user_entity} |
538 |
543 |
539 return record_logic.getForFields(filter, unique=True) |
544 return record_logic.getForFields(filter, unique=True) |
540 |
|
541 def _getSurveyTakeForm(self, survey, record, params, post_dict=None): |
|
542 """Returns the specific SurveyTakeForm needed for the take view. |
|
543 |
|
544 Args: |
|
545 survey: a Survey entity |
|
546 record: a SurveyRecord instance if any exist |
|
547 params: the params dict for the requesting View |
|
548 post_dict: POST data to be passed to form initialization |
|
549 |
|
550 Returns: |
|
551 An instance of SurveyTakeForm that can be used to take a Survey. |
|
552 """ |
|
553 |
|
554 return surveys.SurveyTakeForm(survey_content=survey.survey_content, |
|
555 survey_record=record, |
|
556 survey_logic=params['logic'], |
|
557 data=post_dict) |
|
558 |
|
559 |
545 |
560 def takeGet(self, request, template, context, params, survey_form, entity, |
546 def takeGet(self, request, template, context, params, survey_form, entity, |
561 record, **kwargs): |
547 record, **kwargs): |
562 """Handles the GET request for the Survey's take page. |
548 """Handles the GET request for the Survey's take page. |
563 |
549 |
798 context['page_name'] = "%s titled '%s'" %(page_name, survey_entity.title) |
784 context['page_name'] = "%s titled '%s'" %(page_name, survey_entity.title) |
799 context['entity'] = survey_entity |
785 context['entity'] = survey_entity |
800 context['record'] = record_entity |
786 context['record'] = record_entity |
801 |
787 |
802 # store the read only survey form in the context |
788 # store the read only survey form in the context |
803 survey_form = surveys.SurveyTakeForm( |
789 survey_form = params['survey_take_form']( |
804 survey_content=survey_entity.survey_content, |
790 survey_content=survey_entity.survey_content, |
805 survey_record=record_entity, |
791 survey_record=record_entity, |
806 survey_logic=self._params['logic'], |
792 survey_logic=self._params['logic'], |
807 read_only=True) |
793 read_only=True) |
808 survey_form.getFields() |
794 survey_form.getFields() |