app/soc/views/models/project_survey.py
changeset 2531 855ee76c16a2
parent 2510 a85484d1f441
child 2532 0b4dbe4b3fb7
--- a/app/soc/views/models/project_survey.py	Sat Jul 04 14:29:13 2009 +0200
+++ b/app/soc/views/models/project_survey.py	Sat Jul 04 15:08:28 2009 +0200
@@ -75,8 +75,6 @@
     For Args see base.View().public().
     """
 
-    from soc.logic.models.student import logic as student_logic
-
     survey_logic = params['logic']
 
     try:
@@ -88,19 +86,10 @@
     get_dict = request.GET
 
     if not 'project' in get_dict:
-      user_entity = user_logic.getForCurrentAccount()
-
-      fields = {'user': user_entity,
-                'scope': survey_logic.getScope(entity),
-                'status': 'active'}
+      # get the fields needed to filter projects on
+      fields = self._constructFilterForProjectSelection(entity, params)
 
-      student_entity = student_logic.getForFields(fields, unique=True)
-
-      # TODO(ljvderijk) transform StudentProject to handle multiple surveys
-      fields = {'student': student_entity,
-                'status': 'accepted'}
-
-      # show project selection screen
+      # show project selection screen using the given filter
       return self._selectProjects(request, page_name, params, entity, fields)
 
     return super(View, self).take(request, 'any_access', page_name=page_name,
@@ -112,7 +101,7 @@
     This method also take the StudentProject specified as GET param into
     account when querying for the SurveyRecord.
 
-    For params see base.View._getSurveyRecordFor().
+    For params see survey.View._getSurveyRecordFor().
     """
 
     from soc.logic.models.student_project import logic as student_project_logic
@@ -159,13 +148,43 @@
     # update the properties that will be stored with the referenced project
     properties.update(project=project_entity)
 
+  def _constructFilterForProjectSelection(self, survey, params):
+    """Returns the filter needed for the Project selection view.
+
+    Args:
+      survey: a Survey entity
+      params: the params dict for the requesting view
+
+    Returns:
+      Dictionary that can be used as a input for a query.
+    """
+
+    from soc.logic.models.student import logic as student_logic
+
+    survey_logic = params['logic']
+
+    user_entity = user_logic.getForCurrentAccount()
+
+    # get the student entity for the current user and program
+    fields = {'user': user_entity,
+              'scope': survey_logic.getScope(survey),
+              'status': 'active'}
+
+    student_entity = student_logic.getForFields(fields, unique=True)
+
+    # TODO(ljvderijk) transform StudentProject to handle multiple surveys
+    fields = {'student': student_entity,
+              'status': 'accepted'}
+
+    return fields
+
   def _selectProjects(self, request, page_name, params, survey, fields):
     """Shows a view upon which a User can select a Student Project to fill in
     the ProjectSurvey for.
 
     Args:
       survey: a Survey entity
-      fields: the filter to use on the Project List.
+      fields: the filter to use on the Project List
       rest: see base.View.public()
     """