Added the ability to update project + mail when editing a single GradingRecord
authorLennard de Rijk <ljvderijk@gmail.com>
Tue, 14 Jul 2009 21:09:18 +0200
changeset 2651 842c0f11fc1e
parent 2650 6adbb87b91db
child 2652 e1f980775030
Added the ability to update project + mail when editing a single GradingRecord
app/soc/templates/soc/grading_record/edit.html
app/soc/views/models/grading_survey_group.py
--- a/app/soc/templates/soc/grading_record/edit.html	Tue Jul 14 19:06:53 2009 +0200
+++ b/app/soc/templates/soc/grading_record/edit.html	Tue Jul 14 21:09:18 2009 +0200
@@ -49,7 +49,13 @@
   </tr>
   <tr>
    <td> 
-    <input style="font-weight: bold" type="submit" value="Save Changes"/></span>
+    <input style="font-weight: bold" type="submit" name="save" value="Save Changes"/></span>
+   </td>
+   <td> 
+    <input style="font-weight: bold" type="submit" name="save_update" value="Save Changes and Update Project"/></span>
+   </td>
+   <td> 
+    <input style="font-weight: bold" type="submit" name="save_update_mail" value="Save Changes, Update Project and Send Mail"/></span>
    </td>
    <td>
      <input type="button" value="Back to Previous Page" onClick="javascript:history.go(-1)">
--- a/app/soc/views/models/grading_survey_group.py	Tue Jul 14 19:06:53 2009 +0200
+++ b/app/soc/views/models/grading_survey_group.py	Tue Jul 14 21:09:18 2009 +0200
@@ -436,10 +436,15 @@
       record_entity: a GradingRecord entity
     """
 
+    from google.appengine.api.labs import taskqueue
+    from soc.logic.models.student_project import logic as student_project_logic
+
     survey_logic = params['logic']
     record_logic = survey_logic.getRecordLogic()
 
-    form = params['record_edit_form'](request.POST)
+    post_dict = request.POST
+
+    form = params['record_edit_form'](post_dict)
 
     if not form.is_valid():
       return self._constructResponse(request, record_entity, context, form,
@@ -449,6 +454,20 @@
 
     record_entity = record_logic.updateEntityProperties(record_entity, fields)
 
+    if 'save_update' in post_dict:
+      # also update the accompanying StudentProject
+      student_project_logic.updateProjectsForGradingRecords([record_entity])
+    elif 'save_update_mail' in post_dict:
+      # update the StudentProject and send an email about the result
+      student_project_logic.updateProjectsForGradingRecords([record_entity])
+
+      # pass along these params as POST to the new task
+      task_params = {'record_key': record_entity.key().id_or_name()}
+      task_url = '/tasks/grading_survey_group/mail_result'
+
+      mail_task = taskqueue.Task(params=task_params, url=task_url)
+      mail_task.add('mail')
+
     # Redirect to the same page
     redirect = request.META['HTTP_REFERER']
     return http.HttpResponseRedirect(redirect)