Enable the project management page to be visited for project in other statusses.
authorLennard de Rijk <ljvderijk@gmail.com>
Mon, 10 Aug 2009 15:14:29 -0700
changeset 2743 b9a146acb9bb
parent 2742 53a3c5f4252a
child 2744 6f5e303f64b5
Enable the project management page to be visited for project in other statusses. This enables org admins to easily view Survey results for projects that have failed.
app/soc/templates/soc/student_project/manage.html
app/soc/views/models/student_project.py
--- a/app/soc/templates/soc/student_project/manage.html	Sun Aug 09 21:00:32 2009 -0700
+++ b/app/soc/templates/soc/student_project/manage.html	Mon Aug 10 15:14:29 2009 -0700
@@ -28,65 +28,67 @@
 </table>
 </p>
 
-<p>
-<b>Primary Mentor</b><br />
-In this section you can assign a new Primary Mentor.
-Note that if you select a co-Mentor from this list that Mentor will be removed from the co-Mentors.
-<form method="POST">
-  <table>
-    {% as_table mentor_edit_form %}
-  </table>
-  <table>
-  <tr>
-   <td colspan="4">&nbsp;</td>
-  </tr>
-  <tr>
-    <td> 
-      <input style="font-weight: bold" type="submit" value="Submit" name="set_mentor"/></span>
-    </td>
-    <td>
-      <input type="button" value="Back to Previous Page" onClick="javascript: history.go(-1)">
-    </td>
-  </tr>
- </table>
-</form>
-</p>
-
-<p>
-<b>Co-Mentors</b><br/>
-In this section you can add/remove co-mentors for this project.
-Co-mentors usually play a vital role in the success of a project, however they are not responsible for taking evaluations.
-<table>
-  {% for mentor in additional_mentors %}
+{% ifequal entity.status "accepted" %}
+  <p>
+  <b>Primary Mentor</b><br />
+  In this section you can assign a new Primary Mentor.
+  Note that if you select a co-Mentor from this list that Mentor will be removed from the co-Mentors.
+  <form method="POST">
+    <table>
+      {% as_table mentor_edit_form %}
+    </table>
+    <table>
     <tr>
-      <td>
-        {{ mentor.name }}
+     <td colspan="4">&nbsp;</td>
+    </tr>
+    <tr>
+      <td> 
+        <input style="font-weight: bold" type="submit" value="Submit" name="set_mentor"/></span>
       </td>
       <td>
-        <input type="button" onclick="location.href='?remove={{ mentor.link_id }}'" value="Remove"/>
+        <input type="button" value="Back to Previous Page" onClick="javascript: history.go(-1)">
       </td>
-  {% endfor %}
-</table>
-
-<form method="POST">
-  <table>
-    {% as_table additional_mentor_form %}
-  </table>
+    </tr>
+   </table>
+  </form>
+  </p>
+  
+  <p>
+  <b>Co-Mentors</b><br/>
+  In this section you can add/remove co-mentors for this project.
+  Co-mentors usually play a vital role in the success of a project, however they are not responsible for taking evaluations.
   <table>
-  <tr>
-   <td colspan="4">&nbsp;</td>
-  </tr>
-  <tr>
-    <td> 
-      <input style="font-weight: bold" type="submit" value="Add" name="add_additional_mentor"/></span>
-    </td>
-    <td>
-      <input type="button" value="Back to Previous Page" onClick="javascript: history.go(-1)">
-    </td>
-  </tr>
- </table>
-</form>
-</p>
+    {% for mentor in additional_mentors %}
+      <tr>
+        <td>
+          {{ mentor.name }}
+        </td>
+        <td>
+          <input type="button" onclick="location.href='?remove={{ mentor.link_id }}'" value="Remove"/>
+        </td>
+    {% endfor %}
+  </table>
+  
+  <form method="POST">
+    <table>
+      {% as_table additional_mentor_form %}
+    </table>
+    <table>
+    <tr>
+     <td colspan="4">&nbsp;</td>
+    </tr>
+    <tr>
+      <td> 
+        <input style="font-weight: bold" type="submit" value="Add" name="add_additional_mentor"/></span>
+      </td>
+      <td>
+        <input type="button" value="Back to Previous Page" onClick="javascript: history.go(-1)">
+      </td>
+    </tr>
+   </table>
+  </form>
+  </p>
+{% endifequal %}
 
 <p>
 <b>Evaluations</b><br />
--- a/app/soc/views/models/student_project.py	Sun Aug 09 21:00:32 2009 -0700
+++ b/app/soc/views/models/student_project.py	Mon Aug 10 15:14:29 2009 -0700
@@ -74,7 +74,8 @@
     rights['list'] = ['checkIsDeveloper']
     rights['manage'] = [('checkHasActiveRoleForScope',
                          org_admin_logic),
-        ('checkStudentProjectHasStatus', [['accepted']])]
+        ('checkStudentProjectHasStatus', [['accepted', 'failed', 'completed',
+                                           'withdrawn']])]
     rights['manage_overview'] = [('checkHasActiveRoleForScope',
                          org_admin_logic)]
     # TODO: lack of better name here!
@@ -185,7 +186,6 @@
 
     self._params['student_edit_form'] = student_edit_form
 
-
   def _editGet(self, request, entity, form):
     """See base.View._editGet().
     """
@@ -351,26 +351,6 @@
       return responses.errorResponse(
           error, request, template=params['error_public'])
 
-    get_dict = request.GET
-
-    if 'remove' in get_dict:
-      # get the mentor to remove
-      fields = {'link_id': get_dict['remove'],
-                'scope': entity.scope}
-      mentor = mentor_logic.logic.getForFields(fields, unique=True)
-
-      additional_mentors = entity.additional_mentors
-      # pylint: disable-msg=E1103
-      if additional_mentors and mentor.key() in additional_mentors:
-        # remove the mentor from the additional mentors list
-        additional_mentors.remove(mentor.key())
-        fields = {'additional_mentors': additional_mentors}
-        project_logic.updateEntityProperties(entity, fields)
-
-      # redirect to the same page without GET arguments
-      redirect = request.path
-      return http.HttpResponseRedirect(redirect)
-
     template = params['manage_template']
 
     # get the context for this webpage
@@ -380,6 +360,30 @@
                                                 entity.student.name())
     context['entity'] = entity
 
+
+    if entity.status == 'accepted':
+      # only accepted project can have their mentors managed
+      self._enableMentorManagement(entity, params, context)
+
+    context['evaluation_list'] = self._getEvaluationLists(request, params,
+                                                          entity)
+
+    if request.POST:
+      return self.managePost(request, template, context, params, entity,
+                             **kwargs)
+    else: #request.GET
+      return self.manageGet(request, template, context, params, entity,
+                            **kwargs)
+
+  def _enableMentorManagement(self, entity, params, context):
+    """Sets the data required to manage mentors for a StudentProject.
+
+    Args:
+      entity: StudentProject entity to manage
+      params: params dict for the manage view
+      context: context for the manage view
+    """
+
     # get all mentors for this organization
     fields = {'scope': entity.scope,
               'status': 'active'}
@@ -449,16 +453,6 @@
 
     params['additional_mentor_form'] = additional_mentor_form
 
-    context['evaluation_list'] = self._getEvaluationLists(request, params,
-                                                          entity)
-
-    if request.POST:
-      return self.managePost(request, template, context, params, entity,
-                             **kwargs)
-    else: #request.GET
-      return self.manageGet(request, template, context, params, entity,
-                            **kwargs)
-
   def _getEvaluationLists(self, request, params, entity):
     """Returns List Object containing the list to be shown on the Student 
     Project's manage page.
@@ -536,11 +530,31 @@
         rest: see base.View.public()
     """
 
-    # populate form with the current mentor
-    initial = {'mentor_id': entity.mentor.link_id}
-    context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial)
+    get_dict = request.GET
+
+    if 'remove' in get_dict and entity.status == 'accepted':
+      # get the mentor to remove
+      fields = {'link_id': get_dict['remove'],
+                'scope': entity.scope}
+      mentor = mentor_logic.logic.getForFields(fields, unique=True)
 
-    context['additional_mentor_form'] = params['additional_mentor_form']()
+      additional_mentors = entity.additional_mentors
+      # pylint: disable-  msg=E1103
+      if additional_mentors and mentor.key() in additional_mentors:
+        # remove the mentor from the additional mentors list
+        additional_mentors.remove(mentor.key())
+        fields = {'additional_mentors': additional_mentors}
+        project_logic.updateEntityProperties(entity, fields)
+
+      # redirect to the same page without GET arguments
+      redirect = request.path
+      return http.HttpResponseRedirect(redirect)
+
+    if entity.status == 'accepted':
+      # populate forms with the current mentors set
+      initial = {'mentor_id': entity.mentor.link_id}
+      context['mentor_edit_form'] = params['mentor_edit_form'](initial=initial)
+      context['additional_mentor_form'] = params['additional_mentor_form']()
 
     return responses.respond(request, template, context)
 
@@ -555,11 +569,11 @@
 
     post_dict = request.POST
 
-    if 'set_mentor' in post_dict:
+    if 'set_mentor' in post_dict and entity.status == 'accepted':
       form = params['mentor_edit_form'](post_dict)
       return self._manageSetMentor(request, template, context, params, entity,
                                    form)
-    elif 'add_additional_mentor' in post_dict:
+    elif 'add_additional_mentor' in post_dict and entity.status == 'accepted':
       form = params['additional_mentor_form'](post_dict)
       return self._manageAddAdditionalMentor(request, template, context,
                                              params, entity, form)