app/soc/views/models/grading_project_survey.py
changeset 2532 0b4dbe4b3fb7
parent 2528 9de8348890d8
child 2534 c880489123fc
equal deleted inserted replaced
2531:855ee76c16a2 2532:0b4dbe4b3fb7
    27 from django import forms
    27 from django import forms
    28 
    28 
    29 from soc.logic import dicts
    29 from soc.logic import dicts
    30 from soc.logic.models.survey import GRADES
    30 from soc.logic.models.survey import GRADES
    31 from soc.logic.models.survey import grading_logic as grading_survey_logic
    31 from soc.logic.models.survey import grading_logic as grading_survey_logic
       
    32 from soc.logic.models.user import logic as user_logic
    32 from soc.views.helper import access
    33 from soc.views.helper import access
    33 from soc.views.helper import decorators
    34 from soc.views.helper import decorators
    34 from soc.views.helper import surveys
    35 from soc.views.helper import surveys
    35 from soc.views.models import project_survey
    36 from soc.views.models import project_survey
    36 
    37 
   100                                       survey_logic=params['logic'],
   101                                       survey_logic=params['logic'],
   101                                       grade_choices=grade_choices)
   102                                       grade_choices=grade_choices)
   102 
   103 
   103     return survey_form
   104     return survey_form
   104 
   105 
       
   106   def _constructFilterForProjectSelection(self, survey, params):
       
   107     """Returns the filter needed for the Project selection view.
       
   108 
       
   109     Constructs a filter that returns all valid projects for which the current
       
   110     user is the mentor. Only for the projects in the program given by the
       
   111     survey's scope of course.
       
   112 
       
   113     For args see project_survey.View._constructFilterForProjectSelection().
       
   114     """
       
   115 
       
   116     from soc.logic.models.mentor import logic as mentor_logic
       
   117 
       
   118     survey_logic = params['logic']
       
   119 
       
   120     user_entity = user_logic.getForCurrentAccount()
       
   121 
       
   122     # get the mentor entities for the current user and program
       
   123     fields = {'user': user_entity,
       
   124               'program': survey_logic.getScope(survey),
       
   125               'status': 'active'}
       
   126 
       
   127     mentor_entities = mentor_logic.getForFields(fields)
       
   128 
       
   129     # TODO: Ensure that this doesn't break when someone is a mentor for
       
   130     # a lot of organizations.
       
   131 
       
   132     # TODO(ljvderijk) transform StudentProject to handle multiple surveys
       
   133     fields = {'mentor': mentor_entities,
       
   134               'status': 'accepted'}
       
   135 
       
   136     return fields
   105 
   137 
   106 class GradeSurveyTakeForm(surveys.SurveyTakeForm):
   138 class GradeSurveyTakeForm(surveys.SurveyTakeForm):
   107   """Extends SurveyTakeForm by adding a grade field.
   139   """Extends SurveyTakeForm by adding a grade field.
   108 
   140 
   109   The grade field logic is dependent on the kwarg 'grade_choices' (behavior
   141   The grade field logic is dependent on the kwarg 'grade_choices' (behavior