Added _getSurveyRecordFor method to Survey View.
This method is used by the Take view to get the right SurveyRecord for the current request. Subclassed Views that want to fetch their records in another way can override this method.
--- a/app/soc/views/models/survey.py Thu Jul 02 18:35:57 2009 +0200
+++ b/app/soc/views/models/survey.py Fri Jul 03 12:00:53 2009 +0200
@@ -474,10 +474,9 @@
"""
survey_logic = params['logic']
- record_logic = survey_logic.getRecordLogic()
try:
- entity = self._logic.getFromKeyFieldsOr404(kwargs)
+ entity = survey_logic.getFromKeyFieldsOr404(kwargs)
except out_of_band.Error, error:
return responses.errorResponse(
error, request, template=params['error_public'])
@@ -490,13 +489,8 @@
context['page_name'] = "%s titled '%s'" % (page_name, entity.title)
context['entity'] = entity
- user_entity = user_logic.getForCurrentAccount()
-
# try to get an existing SurveyRecord for the current user
- filter = {'survey': entity,
- 'user': user_entity}
-
- survey_record = record_logic.getForFields(filter, unique=True)
+ survey_record = self._getSurveyRecordFor(entity, request, params)
if request.POST:
return self.takePost(request, template, context, params, entity,
@@ -505,6 +499,29 @@
return self.takeGet(request, template, context, params, entity,
survey_record, **kwargs)
+ def _getSurveyRecordFor(self, survey, request, params):
+ """Returns the SurveyRecord for the given Survey and request.
+
+ Args:
+ survey: a Survey entity
+ request: a Django HTTPRequest object
+ params: params for the requesting view
+
+ Returns:
+ An existing SurveyRecord iff any exists for the given Survey, request
+ and any other conditions that must apply.
+ """
+
+ survey_logic = params['logic']
+ record_logic = survey_logic.getRecordLogic()
+
+ user_entity = user_logic.getForCurrentAccount()
+
+ filter = {'survey': survey,
+ 'user': user_entity}
+
+ return record_logic.getForFields(filter, unique=True)
+
def takeGet(self, request, template, context, params, entity, record,
**kwargs):
"""Handles the GET request for the Survey's take page.