app/soc/modules/ghop/views/models/task.py
changeset 3017 6689a4c8f02e
parent 3002 2c5e9cd4ba4d
child 3018 0653f924ee7e
equal deleted inserted replaced
3016:63625e7e0cac 3017:6689a4c8f02e
   678 
   678 
   679   def listOrgTasksPost(self, request, params, **kwargs):
   679   def listOrgTasksPost(self, request, params, **kwargs):
   680     """Handles the POST request for the list tasks view.
   680     """Handles the POST request for the list tasks view.
   681     """
   681     """
   682 
   682 
   683     # update the status of task entities that have been approved
   683     # get the org entity for which we are listing these tasks
   684     # and published
   684     org_entity = ghop_org_logic.logic.getFromKeyNameOr404(kwargs['scope_path'])
       
   685 
       
   686     # save the state to which the selected tasks must be changed
       
   687     # to based on the actions.
       
   688     if request.POST.get('Approve'):
       
   689       changed_status = 'Unpublished'
       
   690     elif request.POST.get('Publish'):
       
   691       changed_status = 'Open'
       
   692 
       
   693     # update the status of task entities that should be approved or published
   685     task_entities = []
   694     task_entities = []
   686     for key_name, published in request.POST.items():
   695 
       
   696     # get all the task keys to update, will return empty list if doesn't exist
       
   697     task_keys = request.POST.getlist('task_id')
       
   698 
       
   699     for key_name in task_keys:
       
   700 
   687       task_entity = ghop_task_logic.logic.getFromKeyName(key_name)
   701       task_entity = ghop_task_logic.logic.getFromKeyName(key_name)
   688       if task_entity:
   702 
   689         task_entity.status = 'Open'
   703       # Of course only the tasks from this organization and those with a valid 
       
   704       # state can be updated.
       
   705       if task_entity and task_entity.scope.key() == org_entity.key() and \
       
   706           task_entity.status in ['Unapproved', 'Unpublished']:
       
   707         task_entity.status = changed_status
   690 
   708 
   691         task_entities.append(task_entity)
   709         task_entities.append(task_entity)
   692 
   710 
   693     # bulk update the task_entities
   711     # bulk put the task_entities
   694     # TODO: Have to be replaced by Task Queue APIs later
   712     # TODO: replace with Task API call?
   695     db.put(task_entities)
   713     db.put(task_entities)
   696 
   714 
   697     # redirect to the same page
   715     # redirect to the same page
   698     return http.HttpResponseRedirect('')
   716     return http.HttpResponseRedirect('')
   699 
   717 
   726 
   744 
   727     up_params['list_action'] = (redirects.getPublicRedirect,
   745     up_params['list_action'] = (redirects.getPublicRedirect,
   728                                 up_params)
   746                                 up_params)
   729 
   747 
   730     up_params['list_description'] = ugettext(
   748     up_params['list_description'] = ugettext(
   731        'List of Unapproved or Unpublished tasks')
   749        'List of Unapproved tasks.')
   732 
   750 
   733     filter = {
   751     filter = {
   734         'scope': org_entity,
   752         'scope': org_entity,
   735         'status': ['Unapproved', 'Unpublished'],
   753         'status': 'Unapproved',
   736         }
   754         }
   737 
   755 
   738     up_list = lists.getListContent(request, up_params, filter, idx=0,
   756     up_list = lists.getListContent(request, up_params, filter, idx=0,
   739                                    need_content=True)
   757                                    need_content=True)
   740 
   758 
   746       up_list['info'] = (list_info_helper.getTasksInfo(up_mentors_list), None)
   764       up_list['info'] = (list_info_helper.getTasksInfo(up_mentors_list), None)
   747 
   765 
   748       contents.append(up_list)
   766       contents.append(up_list)
   749       context['up_list'] = True
   767       context['up_list'] = True
   750 
   768 
       
   769     aup_params = params.copy()
       
   770     aup_params['list_heading'] = 'modules/ghop/task/approve/heading.html'
       
   771     aup_params['list_row'] = 'modules/ghop/task/approve/row.html'
       
   772 
       
   773     aup_params['list_action'] = (redirects.getPublicRedirect,
       
   774                                  aup_params)
       
   775 
       
   776     aup_params['list_description'] = ugettext(
       
   777        'List of Approved but Unpublished tasks.')
       
   778 
       
   779     filter = {
       
   780         'scope': org_entity,
       
   781         'status': 'Unpublished',
       
   782         }
       
   783 
       
   784     aup_list = lists.getListContent(request, aup_params, filter, idx=1,
       
   785                                     need_content=True)
       
   786 
       
   787     if aup_list:
       
   788       aup_mentors_list = {}
       
   789       for task_entity in aup_list['data']:
       
   790         aup_mentors_list[task_entity.key()] = db.get(task_entity.mentors)
       
   791 
       
   792       aup_list['info'] = (list_info_helper.getTasksInfo(aup_mentors_list), None)
       
   793 
       
   794       contents.append(aup_list)
       
   795 
   751     ap_params = up_params.copy()
   796     ap_params = up_params.copy()
   752     ap_params['list_template'] = 'soc/models/list.html'
   797     ap_params['list_template'] = 'soc/models/list.html'
   753     ap_params['list_heading'] = 'modules/ghop/task/list/heading.html'
   798     ap_params['list_heading'] = 'modules/ghop/task/list/heading.html'
   754     ap_params['list_row'] = 'modules/ghop/task/list/row.html'
   799     ap_params['list_row'] = 'modules/ghop/task/list/row.html'
   755 
   800 
   756     ap_params['list_action'] = (redirects.getPublicRedirect,
   801     ap_params['list_action'] = (redirects.getPublicRedirect,
   757                                 ap_params)
   802                                 ap_params)
   758 
   803 
   759     ap_params['list_description'] = ugettext(
   804     ap_params['list_description'] = ugettext(
   760        'List of published tasks')
   805        'List of Published tasks.')
   761 
   806 
   762     filter = {
   807     filter = {
   763         'scope': org_entity,
   808         'scope': org_entity,
   764         'status': ['Open', 'Reopened', 'ClaimRequested', 'Claimed',
   809         'status': ['Open', 'Reopened', 'ClaimRequested', 'Claimed',
   765             'ActionNeeded', 'Closed', 'AwaitingRegistration', 
   810             'ActionNeeded', 'Closed', 'AwaitingRegistration', 
   766             'NeedsWork', 'NeedsReview'],
   811             'NeedsWork', 'NeedsReview'],
   767         }
   812         }
   768 
   813 
   769     ap_list = lists.getListContent(request, ap_params, filter, idx=1,
   814     ap_list = lists.getListContent(request, ap_params, filter, idx=2,
   770                                    need_content=True)
   815                                    need_content=True)
   771 
   816 
   772     if ap_list:
   817     if ap_list:
   773       ap_mentors_list = {}
   818       ap_mentors_list = {}
   774       for task_entity in ap_list['data']:
   819       for task_entity in ap_list['data']: