Fixed showing the correct list of projects for taking a Grading Project Survey.
Note that when a user is a mentor for a lot of Organizations the amount of subqueries might exceed the allowed amount. A TODO has been added to fix this issue. However this will hopefully not be a problem that pops up soon.
Also some minor docstring addition to Project Survey view.
--- a/app/soc/views/models/grading_project_survey.py Sat Jul 04 15:08:28 2009 +0200
+++ b/app/soc/views/models/grading_project_survey.py Sat Jul 04 15:16:54 2009 +0200
@@ -29,6 +29,7 @@
from soc.logic import dicts
from soc.logic.models.survey import GRADES
from soc.logic.models.survey import grading_logic as grading_survey_logic
+from soc.logic.models.user import logic as user_logic
from soc.views.helper import access
from soc.views.helper import decorators
from soc.views.helper import surveys
@@ -102,6 +103,37 @@
return survey_form
+ def _constructFilterForProjectSelection(self, survey, params):
+ """Returns the filter needed for the Project selection view.
+
+ Constructs a filter that returns all valid projects for which the current
+ user is the mentor. Only for the projects in the program given by the
+ survey's scope of course.
+
+ For args see project_survey.View._constructFilterForProjectSelection().
+ """
+
+ from soc.logic.models.mentor import logic as mentor_logic
+
+ survey_logic = params['logic']
+
+ user_entity = user_logic.getForCurrentAccount()
+
+ # get the mentor entities for the current user and program
+ fields = {'user': user_entity,
+ 'program': survey_logic.getScope(survey),
+ 'status': 'active'}
+
+ mentor_entities = mentor_logic.getForFields(fields)
+
+ # TODO: Ensure that this doesn't break when someone is a mentor for
+ # a lot of organizations.
+
+ # TODO(ljvderijk) transform StudentProject to handle multiple surveys
+ fields = {'mentor': mentor_entities,
+ 'status': 'accepted'}
+
+ return fields
class GradeSurveyTakeForm(surveys.SurveyTakeForm):
"""Extends SurveyTakeForm by adding a grade field.
--- a/app/soc/views/models/project_survey.py Sat Jul 04 15:08:28 2009 +0200
+++ b/app/soc/views/models/project_survey.py Sat Jul 04 15:16:54 2009 +0200
@@ -151,6 +151,9 @@
def _constructFilterForProjectSelection(self, survey, params):
"""Returns the filter needed for the Project selection view.
+ Returns a filter for all the valid projects for which the current user
+ is a student. Of course only in the survey's scope.
+
Args:
survey: a Survey entity
params: the params dict for the requesting view