app/soc/views/models/survey.py
changeset 2484 f41a9e1eeeea
parent 2478 985fd974e095
child 2485 4f4e4fdc283d
equal deleted inserted replaced
2483:be8a113ee021 2484:f41a9e1eeeea
   494 
   494 
   495     # try to get an existing SurveyRecord for the current user
   495     # try to get an existing SurveyRecord for the current user
   496     # TODO(ljvderijk) deal with the SurveyProperty name in subclasses
   496     # TODO(ljvderijk) deal with the SurveyProperty name in subclasses
   497     filter = {'survey': entity,
   497     filter = {'survey': entity,
   498               'user': user_entity}
   498               'user': user_entity}
       
   499 
   499     survey_record = record_logic.getForFields(filter, unique=True)
   500     survey_record = record_logic.getForFields(filter, unique=True)
   500 
   501 
   501     if request.POST:
   502     if request.POST:
   502       return self.takePost(request, template, context, params, entity,
   503       return self.takePost(request, template, context, params, entity,
   503                            survey_record, **kwargs)
   504                            survey_record, **kwargs)
   535         template: the template used for this view
   536         template: the template used for this view
   536         entity: the Survey entity
   537         entity: the Survey entity
   537         rest: see base.View.public()
   538         rest: see base.View.public()
   538     """
   539     """
   539 
   540 
   540     # TODO(ljvderijk) implement takePost
   541     survey_logic = params['logic']
   541 
   542     record_logic = survey_logic.getRecordLogic()
   542     return http.HttpResponse("Work in Progress")
   543 
       
   544     # TODO: check the validity of the form data
       
   545     properties = surveys.getSurveyResponseFromPost(entity, request.POST)
       
   546 
       
   547     # add the required SurveyRecord properties
       
   548     properties['user'] = user_logic.getForCurrentAccount()
       
   549     properties['survey'] = entity
       
   550 
       
   551     # update the record entity if any and clear all dynamic properties
       
   552     record_logic.updateOrCreateFromFields(record, properties, clear_dynamic=True)
       
   553 
       
   554     # TODO: add notice to page that the response has been saved successfully
       
   555     # redirect to the same page for now
       
   556     redirect = request.path
       
   557     return http.HttpResponseRedirect(redirect)
   543 
   558 
   544   def setHelpAndStatus(self, context, survey, survey_record):
   559   def setHelpAndStatus(self, context, survey, survey_record):
   545     """Get help_text and status for template use.
   560     """Get help_text and status for template use.
   546 
   561 
   547     Args:
   562     Args: