73 """View for taking a Survey. |
73 """View for taking a Survey. |
74 |
74 |
75 For Args see base.View().public(). |
75 For Args see base.View().public(). |
76 """ |
76 """ |
77 |
77 |
78 from soc.logic.models.student import logic as student_logic |
|
79 |
|
80 survey_logic = params['logic'] |
78 survey_logic = params['logic'] |
81 |
79 |
82 try: |
80 try: |
83 entity = survey_logic.getFromKeyFieldsOr404(kwargs) |
81 entity = survey_logic.getFromKeyFieldsOr404(kwargs) |
84 except out_of_band.Error, error: |
82 except out_of_band.Error, error: |
86 error, request, template=params['error_public']) |
84 error, request, template=params['error_public']) |
87 |
85 |
88 get_dict = request.GET |
86 get_dict = request.GET |
89 |
87 |
90 if not 'project' in get_dict: |
88 if not 'project' in get_dict: |
91 user_entity = user_logic.getForCurrentAccount() |
89 # get the fields needed to filter projects on |
92 |
90 fields = self._constructFilterForProjectSelection(entity, params) |
93 fields = {'user': user_entity, |
91 |
94 'scope': survey_logic.getScope(entity), |
92 # show project selection screen using the given filter |
95 'status': 'active'} |
|
96 |
|
97 student_entity = student_logic.getForFields(fields, unique=True) |
|
98 |
|
99 # TODO(ljvderijk) transform StudentProject to handle multiple surveys |
|
100 fields = {'student': student_entity, |
|
101 'status': 'accepted'} |
|
102 |
|
103 # show project selection screen |
|
104 return self._selectProjects(request, page_name, params, entity, fields) |
93 return self._selectProjects(request, page_name, params, entity, fields) |
105 |
94 |
106 return super(View, self).take(request, 'any_access', page_name=page_name, |
95 return super(View, self).take(request, 'any_access', page_name=page_name, |
107 params=params, **kwargs) |
96 params=params, **kwargs) |
108 |
97 |
110 """Returns the SurveyRecord for the given Survey and request. |
99 """Returns the SurveyRecord for the given Survey and request. |
111 |
100 |
112 This method also take the StudentProject specified as GET param into |
101 This method also take the StudentProject specified as GET param into |
113 account when querying for the SurveyRecord. |
102 account when querying for the SurveyRecord. |
114 |
103 |
115 For params see base.View._getSurveyRecordFor(). |
104 For params see survey.View._getSurveyRecordFor(). |
116 """ |
105 """ |
117 |
106 |
118 from soc.logic.models.student_project import logic as student_project_logic |
107 from soc.logic.models.student_project import logic as student_project_logic |
119 |
108 |
120 survey_logic = params['logic'] |
109 survey_logic = params['logic'] |
157 project_entity = student_project_logic.getFromKeyName(get_dict['project']) |
146 project_entity = student_project_logic.getFromKeyName(get_dict['project']) |
158 |
147 |
159 # update the properties that will be stored with the referenced project |
148 # update the properties that will be stored with the referenced project |
160 properties.update(project=project_entity) |
149 properties.update(project=project_entity) |
161 |
150 |
|
151 def _constructFilterForProjectSelection(self, survey, params): |
|
152 """Returns the filter needed for the Project selection view. |
|
153 |
|
154 Args: |
|
155 survey: a Survey entity |
|
156 params: the params dict for the requesting view |
|
157 |
|
158 Returns: |
|
159 Dictionary that can be used as a input for a query. |
|
160 """ |
|
161 |
|
162 from soc.logic.models.student import logic as student_logic |
|
163 |
|
164 survey_logic = params['logic'] |
|
165 |
|
166 user_entity = user_logic.getForCurrentAccount() |
|
167 |
|
168 # get the student entity for the current user and program |
|
169 fields = {'user': user_entity, |
|
170 'scope': survey_logic.getScope(survey), |
|
171 'status': 'active'} |
|
172 |
|
173 student_entity = student_logic.getForFields(fields, unique=True) |
|
174 |
|
175 # TODO(ljvderijk) transform StudentProject to handle multiple surveys |
|
176 fields = {'student': student_entity, |
|
177 'status': 'accepted'} |
|
178 |
|
179 return fields |
|
180 |
162 def _selectProjects(self, request, page_name, params, survey, fields): |
181 def _selectProjects(self, request, page_name, params, survey, fields): |
163 """Shows a view upon which a User can select a Student Project to fill in |
182 """Shows a view upon which a User can select a Student Project to fill in |
164 the ProjectSurvey for. |
183 the ProjectSurvey for. |
165 |
184 |
166 Args: |
185 Args: |
167 survey: a Survey entity |
186 survey: a Survey entity |
168 fields: the filter to use on the Project List. |
187 fields: the filter to use on the Project List |
169 rest: see base.View.public() |
188 rest: see base.View.public() |
170 """ |
189 """ |
171 |
190 |
172 from soc.views.models.student_project import view as student_project_view |
191 from soc.views.models.student_project import view as student_project_view |
173 |
192 |