160 student_create_form = dynaform.extendDynaForm( |
160 student_create_form = dynaform.extendDynaForm( |
161 dynaform=self._params['create_form'], |
161 dynaform=self._params['create_form'], |
162 dynaproperties=dynaproperties) |
162 dynaproperties=dynaproperties) |
163 |
163 |
164 params['student_create_form'] = student_create_form |
164 params['student_create_form'] = student_create_form |
|
165 |
|
166 # create the special form for public review |
|
167 dynafields = [ |
|
168 {'name': 'comment', |
|
169 'base': forms.CharField, |
|
170 'widget': widgets.FullTinyMCE(attrs={'rows': 10, 'cols': 40}), |
|
171 'label': 'Comment', |
|
172 'required': False, |
|
173 }, |
|
174 ] |
|
175 |
|
176 dynaproperties = params_helper.getDynaFields(dynafields) |
|
177 |
|
178 public_review_form = dynaform.newDynaForm(dynamodel=None, |
|
179 dynabase=helper.forms.BaseForm, dynainclude=None, |
|
180 dynaexclude=None, dynaproperties=dynaproperties) |
|
181 params['public_review_form'] = public_review_form |
165 |
182 |
166 # create the special form for mentors |
183 # create the special form for mentors |
167 dynafields = [ |
184 dynafields = [ |
168 {'name': 'score', |
185 {'name': 'score', |
169 'base': forms.ChoiceField, |
186 'base': forms.ChoiceField, |
248 fields['org'] = org_logic.logic.getForFields(filter, unique=True) |
265 fields['org'] = org_logic.logic.getForFields(filter, unique=True) |
249 |
266 |
250 # explicitly change the last_modified_on since the content has been edited |
267 # explicitly change the last_modified_on since the content has been edited |
251 fields['last_modified_on'] = datetime.datetime.now() |
268 fields['last_modified_on'] = datetime.datetime.now() |
252 |
269 |
253 def _public(self, request, entity, context): |
270 @decorators.merge_params |
254 """See base.View._public(). |
271 @decorators.check_access |
|
272 def public(self, request, access_type, |
|
273 page_name=None, params=None, **kwargs): |
|
274 """View in which the student can see and reply to the comments on the |
|
275 Student Proposal. |
|
276 |
|
277 For params see base.view.Public(). |
|
278 """ |
|
279 |
|
280 context = helper.responses.getUniversalContext(request) |
|
281 helper.responses.useJavaScript(context, params['js_uses_all']) |
|
282 context['page_name'] = page_name |
|
283 |
|
284 try: |
|
285 entity = self._logic.getFromKeyFieldsOr404(kwargs) |
|
286 except out_of_band.Error, error: |
|
287 return helper.responses.errorResponse( |
|
288 error, request, template=params['error_public'], context=context) |
|
289 |
|
290 context['entity'] = entity |
|
291 context['entity_type'] = params['name'] |
|
292 context['entity_type_url'] = params['url_name'] |
|
293 |
|
294 if request.method == 'POST': |
|
295 return self.publicPost(request, context, params, entity, **kwargs) |
|
296 else: # request.method == 'GET' |
|
297 return self.publicGet(request, context, params, entity, **kwargs) |
|
298 |
|
299 def publicPost(self, request, context, params, entity, **kwargs): |
|
300 """Handles the POST request for the entity's public page. |
|
301 |
|
302 Args: |
|
303 entity: the student proposal entity |
|
304 rest: see base.View.public() |
|
305 """ |
|
306 |
|
307 # populate the form using the POST data |
|
308 form = params['public_review_form'](request.POST) |
|
309 |
|
310 if not form.is_valid(): |
|
311 # get some entity specific context |
|
312 self.updatePublicContext(context, entity, params) |
|
313 |
|
314 # return the invalid form response |
|
315 return self._constructResponse(request, entity=entity, context=context, |
|
316 form=form, params=params, template=params['public_template']) |
|
317 |
|
318 # get the commentary |
|
319 fields = form.cleaned_data |
|
320 comment = fields['comment'] |
|
321 |
|
322 if comment: |
|
323 # create a new public review containing the comment |
|
324 user_entity = user_logic.logic.getForCurrentAccount() |
|
325 |
|
326 if user_entity.key() == entity.scope.user.key(): |
|
327 # student is posting |
|
328 reviewer = entity.scope |
|
329 else: |
|
330 # check if the person commenting is an org_admin |
|
331 # or a mentor for the given proposal |
|
332 fields = {'user': user_entity, |
|
333 'scope': entity.org, |
|
334 'status': 'active', |
|
335 } |
|
336 |
|
337 reviewer = org_admin_logic.logic.getForFields(fields, unique=True) |
|
338 |
|
339 if not reviewer: |
|
340 # no org_admin found, maybe it's a mentor? |
|
341 reviewer = mentor_logic.logic.getForFields(filter, unique=True) |
|
342 |
|
343 # create the review (reviewer might be None if a Host or Developer is posting) |
|
344 self._createReviewFor(entity, reviewer, comment, is_public=True) |
|
345 |
|
346 # redirect to the same page |
|
347 return http.HttpResponseRedirect('') |
|
348 |
|
349 def publicGet(self, request, context, params, entity, **kwargs): |
|
350 """Handles the GET request for the entity's public page. |
|
351 |
|
352 Args: |
|
353 entity: the student proposal entity |
|
354 rest see base.View.public() |
|
355 """ |
|
356 |
|
357 # get some entity specific context |
|
358 self.updatePublicContext(context, entity, params) |
|
359 |
|
360 context['form'] = params['public_review_form']() |
|
361 template = params['public_template'] |
|
362 |
|
363 return responses.respond(request, template, context=context) |
|
364 |
|
365 def updatePublicContext(self, context, entity, params): |
|
366 """Updates the context for the public page with information from the entity |
|
367 |
|
368 Args: |
|
369 context: the context that should be updated |
|
370 entity: a student proposal_entity used to set context |
|
371 params: dict with params for the view using this context |
255 """ |
372 """ |
256 |
373 |
257 from soc.logic.models.review import logic as review_logic |
374 from soc.logic.models.review import logic as review_logic |
258 |
375 |
259 context['student_name'] = entity.scope.name() |
376 context['student_name'] = entity.scope.name() |
630 |
747 |
631 # update the proposal |
748 # update the proposal |
632 properties = {'mentor': mentor_entity} |
749 properties = {'mentor': mentor_entity} |
633 self._logic.updateEntityProperties(entity, properties) |
750 self._logic.updateEntityProperties(entity, properties) |
634 |
751 |
635 def _createReviewFor(self, entity, reviewer, comment, score, is_public): |
752 def _createReviewFor(self, entity, reviewer, comment, score=0, is_public=True): |
636 """Creates a review for the given proposal. |
753 """Creates a review for the given proposal. |
637 |
754 |
638 Args: |
755 Args: |
639 entity: Student Proposal entity for which the review should be created |
756 entity: Student Proposal entity for which the review should be created |
640 reviewer: A role entity of the reviewer (if possible, else None) |
757 reviewer: A role entity of the reviewer (if possible, else None) |