# HG changeset patch # User Madhusudan.C.S # Date 1254775410 -7200 # Node ID 6689a4c8f02ede9913938ca4d5fc6b90280a0b6f # Parent 63625e7e0caccf77a6b31b19ad7d01b66a79a54c 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 diff -r 63625e7e0cac -r 6689a4c8f02e app/soc/modules/ghop/views/models/task.py --- 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: diff -r 63625e7e0cac -r 6689a4c8f02e app/soc/templates/modules/ghop/task/approve/approve.html --- 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 }} - - -{% endblock %} - {% block body %}
-{% if up_list %} - -{% endif %} + + {% if error_message %}
{{ error_message|safe }}
{% endif %} {{ block.super }}
{% endblock %} - diff -r 63625e7e0cac -r 6689a4c8f02e app/soc/templates/modules/ghop/task/approve/row.html --- 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 %} - - - -{% endblock %} - + + +
+ +
+ + +
{{ list.item.title }} +
+ +{% endblock first %} diff -r 63625e7e0cac -r 6689a4c8f02e app/soc/templates/modules/ghop/task/list/heading.html --- 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 @@ - {% block first %} +{% block first %} Title - {% endblock %} +{% endblock first %} Difficulty Type Time To Complete diff -r 63625e7e0cac -r 6689a4c8f02e app/soc/templates/modules/ghop/task/list/row.html --- 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 %} - {% block first %} - - {% endblock %}
{{ list.item.title }}
+{% endblock first %}
{{ list.item.difficulty.0.tag }}
{% for task_type in list.item.task_type %}