Separated the publish and approve button on the Task list page for Org members.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Mon, 05 Oct 2009 22:43:30 +0200
changeset 3017 6689a4c8f02e
parent 3016 63625e7e0cac
child 3018 0653f924ee7e
Separated the publish and approve button on the Task list page for Org members. Also ensured that only tasks from the right org with the right status can be changed. And that we do not make unneccesary loops over values in the POST dict by grouping all the keys in the POST data under "task_id". The list entries also no longer redirect a user when clicking on the checkbox. Patch by: Madhusudan.C.S and Lennard de Rijk
app/soc/modules/ghop/views/models/task.py
app/soc/templates/modules/ghop/task/approve/approve.html
app/soc/templates/modules/ghop/task/approve/row.html
app/soc/templates/modules/ghop/task/list/heading.html
app/soc/templates/modules/ghop/task/list/row.html
--- a/app/soc/modules/ghop/views/models/task.py	Mon Oct 05 20:35:06 2009 +0200
+++ b/app/soc/modules/ghop/views/models/task.py	Mon Oct 05 22:43:30 2009 +0200
@@ -680,18 +680,36 @@
     """Handles the POST request for the list tasks view.
     """
 
-    # update the status of task entities that have been approved
-    # and published
+    # get the org entity for which we are listing these tasks
+    org_entity = ghop_org_logic.logic.getFromKeyNameOr404(kwargs['scope_path'])
+
+    # save the state to which the selected tasks must be changed
+    # to based on the actions.
+    if request.POST.get('Approve'):
+      changed_status = 'Unpublished'
+    elif request.POST.get('Publish'):
+      changed_status = 'Open'
+
+    # update the status of task entities that should be approved or published
     task_entities = []
-    for key_name, published in request.POST.items():
+
+    # get all the task keys to update, will return empty list if doesn't exist
+    task_keys = request.POST.getlist('task_id')
+
+    for key_name in task_keys:
+
       task_entity = ghop_task_logic.logic.getFromKeyName(key_name)
-      if task_entity:
-        task_entity.status = 'Open'
+
+      # Of course only the tasks from this organization and those with a valid 
+      # state can be updated.
+      if task_entity and task_entity.scope.key() == org_entity.key() and \
+          task_entity.status in ['Unapproved', 'Unpublished']:
+        task_entity.status = changed_status
 
         task_entities.append(task_entity)
 
-    # bulk update the task_entities
-    # TODO: Have to be replaced by Task Queue APIs later
+    # bulk put the task_entities
+    # TODO: replace with Task API call?
     db.put(task_entities)
 
     # redirect to the same page
@@ -728,11 +746,11 @@
                                 up_params)
 
     up_params['list_description'] = ugettext(
-       'List of Unapproved or Unpublished tasks')
+       'List of Unapproved tasks.')
 
     filter = {
         'scope': org_entity,
-        'status': ['Unapproved', 'Unpublished'],
+        'status': 'Unapproved',
         }
 
     up_list = lists.getListContent(request, up_params, filter, idx=0,
@@ -748,6 +766,33 @@
       contents.append(up_list)
       context['up_list'] = True
 
+    aup_params = params.copy()
+    aup_params['list_heading'] = 'modules/ghop/task/approve/heading.html'
+    aup_params['list_row'] = 'modules/ghop/task/approve/row.html'
+
+    aup_params['list_action'] = (redirects.getPublicRedirect,
+                                 aup_params)
+
+    aup_params['list_description'] = ugettext(
+       'List of Approved but Unpublished tasks.')
+
+    filter = {
+        'scope': org_entity,
+        'status': 'Unpublished',
+        }
+
+    aup_list = lists.getListContent(request, aup_params, filter, idx=1,
+                                    need_content=True)
+
+    if aup_list:
+      aup_mentors_list = {}
+      for task_entity in aup_list['data']:
+        aup_mentors_list[task_entity.key()] = db.get(task_entity.mentors)
+
+      aup_list['info'] = (list_info_helper.getTasksInfo(aup_mentors_list), None)
+
+      contents.append(aup_list)
+
     ap_params = up_params.copy()
     ap_params['list_template'] = 'soc/models/list.html'
     ap_params['list_heading'] = 'modules/ghop/task/list/heading.html'
@@ -757,7 +802,7 @@
                                 ap_params)
 
     ap_params['list_description'] = ugettext(
-       'List of published tasks')
+       'List of Published tasks.')
 
     filter = {
         'scope': org_entity,
@@ -766,7 +811,7 @@
             'NeedsWork', 'NeedsReview'],
         }
 
-    ap_list = lists.getListContent(request, ap_params, filter, idx=1,
+    ap_list = lists.getListContent(request, ap_params, filter, idx=2,
                                    need_content=True)
 
     if ap_list:
--- a/app/soc/templates/modules/ghop/task/approve/approve.html	Mon Oct 05 20:35:06 2009 +0200
+++ b/app/soc/templates/modules/ghop/task/approve/approve.html	Mon Oct 05 22:43:30 2009 +0200
@@ -1,26 +1,14 @@
 {% extends "soc/models/list.html" %}
 
-{% block scripts %}
-{{ block.super }}
-
-<script type="text/javascript">
-  var RETURN_URL = "{{ return_url }}";
-  $(document).ready(function(){
-    $('[id^=id_spin_slot_count_]').spin({min:0});
-  });
-</script>
-{% endblock %}
-
 {% block body %}
 <form method="POST">
-{% if up_list %}
-<input style="font-weight: bold" type="submit" 
-value="Approve and Publish"/></span>
-{% endif %}
+<input style="font-weight: bold" type="submit" name="Approve"
+value="Approve"/></span>
+<input style="font-weight: bold" type="submit" name="Publish"
+value="Publish"/></span>
 {% if error_message %}
 <div class="error">{{ error_message|safe }}</div>
 {% endif %}
 {{ block.super }}
 </form>
 {% endblock %}
-
--- a/app/soc/templates/modules/ghop/task/approve/row.html	Mon Oct 05 20:35:06 2009 +0200
+++ b/app/soc/templates/modules/ghop/task/approve/row.html	Mon Oct 05 22:43:30 2009 +0200
@@ -1,11 +1,14 @@
 {% extends "modules/ghop/task/list/row.html" %}
-
 {% block first %}
-<td>
-  <div class="approve" id="id_approve_{{ list.item.link_id }}">
-  <input type="checkbox" id="id_approve_{{ list.item.key.name }}"
-   name="{{ list.item.key.name }}"/>
-  </div>
-</td>
-{% endblock %}
-
+<tr class="off" onmouseover="this.className='on'" onmouseout="this.className='off'" name="name">
+  <td>
+    <div class="select">
+    <input type="checkbox" value="{{list.item.key.name}}" name="task_id"/>
+    </div>
+  </td>
+  <td>
+    <div class="title"><a class="noul" onclick="do_redirect=false"
+         href="{{ list.redirect }}">{{ list.item.title }}</a>
+    </div>
+  </td>
+{% endblock first %}
--- a/app/soc/templates/modules/ghop/task/list/heading.html	Mon Oct 05 20:35:06 2009 +0200
+++ b/app/soc/templates/modules/ghop/task/list/heading.html	Mon Oct 05 22:43:30 2009 +0200
@@ -1,7 +1,7 @@
 <tr align="left">
-  {% block first %}
+{% block first %}
   <th class="first" align="right">Title</th>
-  {% endblock %}
+{% endblock first %}
   <th>Difficulty</th>
   <th>Type</th>
   <th>Time To Complete</th>
--- a/app/soc/templates/modules/ghop/task/list/row.html	Mon Oct 05 20:35:06 2009 +0200
+++ b/app/soc/templates/modules/ghop/task/list/row.html	Mon Oct 05 22:43:30 2009 +0200
@@ -1,12 +1,11 @@
+{% block first %}
 <tr class="off" onmouseover="this.className='on'; do_redirect=true" onmouseout="this.className='off'" 
 onclick="if (do_redirect) document.location.href='{{ list.redirect }}'" name="name">
-  {% block first %}
-  <!-- to be used in the inherited block -->
-  {% endblock %}
   <td align="right"><div class="title"><a class="noul" onclick="do_redirect=false"
          href="{{ list.redirect }}">{{ list.item.title }}</a>
      </div>
   </td>
+{% endblock first %}
   <td><div class="difficulty">{{ list.item.difficulty.0.tag }}</a></div></td>
   <td><div class="task_type">
   {% for task_type in list.item.task_type %}