List view of all tasks for a GHOP student.
Link 'List my tasks' in the GHOP program submenu is now active for a GHOP student and displays all tasks (grouped by organizations) which the user is involved in.
--- a/app/soc/modules/ghop/views/helper/redirects.py Tue Nov 03 00:50:23 2009 +0100
+++ b/app/soc/modules/ghop/views/helper/redirects.py Tue Nov 03 02:10:47 2009 +0100
@@ -19,6 +19,7 @@
__authors__ = [
'"Madhusudan.C.S" <madhusudancs@gmail.com>',
+ '"Daniel Hans" <daniel.m.hans@gmail.com>',
]
@@ -52,6 +53,16 @@
return result
+def getListStudentTasksRedirect(entity, params):
+ """Returns the redirect for the List Projects page for the given entity.
+ """
+
+ result = '/%s/list_student_tasks/%s' % (
+ params['url_name'], entity.key().id_or_name())
+
+ return result
+
+
def getDifficultyEditRedirect(entity, params):
"""Returns the task difficulty levels edit redirect for the specified entity.
"""
--- a/app/soc/modules/ghop/views/models/program.py Tue Nov 03 00:50:23 2009 +0100
+++ b/app/soc/modules/ghop/views/models/program.py Tue Nov 03 02:10:47 2009 +0100
@@ -19,6 +19,7 @@
__authors__ = [
'"Madhusudan.C.S" <madhusudancs@gmail.com>',
+ '"Daniel Hans" <daniel.m.hans@gmail.com>',
'"Lennard de Rijk" <ljvderijk@gmail.com>',
]
@@ -438,8 +439,8 @@
if timeline_helper.isAfterEvent(timeline_entity,
'student_signup_start'):
# add a link to show all projects
- items += [(redirects.getListProjectsRedirect(ghop_program_entity,
- {'url_name':'ghop/task'}),
+ items += [(ghop_redirects.getListStudentTasksRedirect(
+ student_entity, {'url_name':'ghop/student'}),
"List my Tasks", 'any_access')]
items += [(redirects.getEditRedirect(student_entity,
--- a/app/soc/modules/ghop/views/models/student.py Tue Nov 03 00:50:23 2009 +0100
+++ b/app/soc/modules/ghop/views/models/student.py Tue Nov 03 02:10:47 2009 +0100
@@ -19,20 +19,28 @@
__authors__ = [
'"Madhusudan.C.S" <madhusudancs@gmail.com>',
+ '"Daniel Hans" <daniel.m.hans@gmail.com>',
'"Lennard de Rijk" <ljvderijk@gmail.com>',
]
+from django.utils.translation import ugettext
+
from soc.logic import dicts
from soc.views.helper import decorators
from soc.views.helper import dynaform
+from soc.views.helper import lists
+from soc.views.helper import redirects
from soc.views.models import student
+from soc.logic.models import user as user_logic
+
from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic
from soc.modules.ghop.logic.models import organization as ghop_org_logic
from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic
from soc.modules.ghop.logic.models import program as ghop_program_logic
from soc.modules.ghop.logic.models import student as ghop_student_logic
+from soc.modules.ghop.logic.models import task as ghop_task_logic
from soc.modules.ghop.views.helper import access as ghop_access
from soc.modules.ghop.views.models import program as ghop_program_view
@@ -43,6 +51,8 @@
"""View methods for the GHOP Student model.
"""
+ DEF_STUDENT_TASKS_MSG_FMT = ugettext('Your tasks for %s.')
+
def __init__(self, params=None):
"""Defines the fields and methods required for the student View class
to provide the user with list, public, create, edit and delete views.
@@ -51,17 +61,24 @@
params: a dict with params for this View
"""
+ patterns = []
+ patterns += [
+ (r'^%(url_name)s/(?P<access_type>list_student_tasks)/%(key_fields)s$',
+ '%(module_package)s.%(module_name)s.list_student_tasks',
+ 'List Student tasks')]
+
rights = ghop_access.GHOPChecker(params)
rights['edit'] = [('checkIsMyActiveRole', ghop_student_logic.logic)]
rights['apply'] = [
'checkIsUser',
- ('checkIsActivePeriod',
- ['student_signup', 'scope_path', ghop_program_logic.logic]),
- ('checkIsNotParticipatingInProgramInScope', [ghop_program_logic.logic,
- ghop_student_logic.logic, ghop_org_admin_logic.logic,
+ ('checkIsActivePeriod', ['student_signup', 'scope_path']),
+ ('checkIsNotParticipatingInProgramInScope',
+ [ghop_student_logic.logic, ghop_org_admin_logic.logic,
ghop_mentor_logic.logic]),
'checkCanApply']
rights['manage'] = [('checkIsMyActiveRole', ghop_student_logic.logic)]
+ rights['list_student_tasks'] = [('checkIsMyActiveRole',
+ ghop_student_logic.logic)]
new_params = {}
new_params['logic'] = soc.modules.ghop.logic.models.student.logic
@@ -79,10 +96,62 @@
new_params['module_package'] = 'soc.modules.ghop.views.models'
new_params['url_name'] = 'ghop/student'
+ new_params['extra_django_patterns'] = patterns
+
params = dicts.merge(params, new_params, sub_merge=True)
super(View, self).__init__(params=params)
+ @decorators.merge_params
+ @decorators.check_access
+ def listStudentTasks(self, request, access_type, page_name=None,
+ params=None, **kwargs):
+ """Displays a list of all tasks for a given student.
+
+ See base.View.list() for more details.
+ """
+
+ # obtain program entity based on request params
+ program = ghop_program_logic.logic.getFromKeyNameOr404(
+ kwargs['scope_path'])
+
+ user_account = user_logic.logic.getForCurrentAccount()
+
+ filter = {
+ 'user': user_account,
+ 'program': program
+ }
+
+ tasks = ghop_task_logic.logic.getForFields(filter=filter)
+
+ tasks_by_orgs = {}
+ for task in tasks:
+ if task.scope.name in tasks_by_orgs:
+ tasks_by_orgs[task.scope.name].append(task)
+ else:
+ tasks_by_orgs[task.scope.name] = [task]
+
+ contents = []
+ context = {}
+
+ sp_params = params.copy()
+ sp_params['list_template'] = 'soc/models/list.html'
+ sp_params['list_heading'] = 'modules/ghop/task/list/heading.html'
+ sp_params['list_row'] = 'modules/ghop/task/list/row.html'
+ sp_params['pagination'] = 'soc/list/no_pagination.html'
+ sp_params['list_action'] = (redirects.getPublicRedirect, sp_params)
+
+ sp_org_params = sp_params.copy()
+ for org in tasks_by_orgs.keys():
+ sp_org_params['list_description'] = self.DEF_STUDENT_TASKS_MSG_FMT % org
+
+ sp_org_list = lists.getListContentForData(request, sp_org_params,
+ data=tasks_by_orgs[org], idx=1, need_content=True)
+
+ contents.append(sp_org_list)
+
+ return self._list(request, sp_params, contents, page_name, context)
+
view = View()
@@ -91,6 +160,7 @@
delete = decorators.view(view.delete)
edit = decorators.view(view.edit)
list = decorators.view(view.list)
+list_student_tasks = decorators.view(view.listStudentTasks)
manage = decorators.view(view.manage)
public = decorators.view(view.public)
export = decorators.view(view.export)