17 """GHOP specific views for Student. |
17 """GHOP specific views for Student. |
18 """ |
18 """ |
19 |
19 |
20 __authors__ = [ |
20 __authors__ = [ |
21 '"Madhusudan.C.S" <madhusudancs@gmail.com>', |
21 '"Madhusudan.C.S" <madhusudancs@gmail.com>', |
|
22 '"Daniel Hans" <daniel.m.hans@gmail.com>', |
22 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
23 '"Lennard de Rijk" <ljvderijk@gmail.com>', |
23 ] |
24 ] |
24 |
25 |
25 |
26 |
|
27 from django.utils.translation import ugettext |
|
28 |
26 from soc.logic import dicts |
29 from soc.logic import dicts |
27 from soc.views.helper import decorators |
30 from soc.views.helper import decorators |
28 from soc.views.helper import dynaform |
31 from soc.views.helper import dynaform |
|
32 from soc.views.helper import lists |
|
33 from soc.views.helper import redirects |
29 from soc.views.models import student |
34 from soc.views.models import student |
|
35 |
|
36 from soc.logic.models import user as user_logic |
30 |
37 |
31 from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic |
38 from soc.modules.ghop.logic.models import mentor as ghop_mentor_logic |
32 from soc.modules.ghop.logic.models import organization as ghop_org_logic |
39 from soc.modules.ghop.logic.models import organization as ghop_org_logic |
33 from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic |
40 from soc.modules.ghop.logic.models import org_admin as ghop_org_admin_logic |
34 from soc.modules.ghop.logic.models import program as ghop_program_logic |
41 from soc.modules.ghop.logic.models import program as ghop_program_logic |
35 from soc.modules.ghop.logic.models import student as ghop_student_logic |
42 from soc.modules.ghop.logic.models import student as ghop_student_logic |
|
43 from soc.modules.ghop.logic.models import task as ghop_task_logic |
36 from soc.modules.ghop.views.helper import access as ghop_access |
44 from soc.modules.ghop.views.helper import access as ghop_access |
37 from soc.modules.ghop.views.models import program as ghop_program_view |
45 from soc.modules.ghop.views.models import program as ghop_program_view |
38 |
46 |
39 import soc.modules.ghop.logic.models.student |
47 import soc.modules.ghop.logic.models.student |
40 |
48 |
41 |
49 |
42 class View(student.View): |
50 class View(student.View): |
43 """View methods for the GHOP Student model. |
51 """View methods for the GHOP Student model. |
44 """ |
52 """ |
45 |
53 |
|
54 DEF_STUDENT_TASKS_MSG_FMT = ugettext('Your tasks for %s.') |
|
55 |
46 def __init__(self, params=None): |
56 def __init__(self, params=None): |
47 """Defines the fields and methods required for the student View class |
57 """Defines the fields and methods required for the student View class |
48 to provide the user with list, public, create, edit and delete views. |
58 to provide the user with list, public, create, edit and delete views. |
49 |
59 |
50 Params: |
60 Params: |
51 params: a dict with params for this View |
61 params: a dict with params for this View |
52 """ |
62 """ |
53 |
63 |
|
64 patterns = [] |
|
65 patterns += [ |
|
66 (r'^%(url_name)s/(?P<access_type>list_student_tasks)/%(key_fields)s$', |
|
67 '%(module_package)s.%(module_name)s.list_student_tasks', |
|
68 'List Student tasks')] |
|
69 |
54 rights = ghop_access.GHOPChecker(params) |
70 rights = ghop_access.GHOPChecker(params) |
55 rights['edit'] = [('checkIsMyActiveRole', ghop_student_logic.logic)] |
71 rights['edit'] = [('checkIsMyActiveRole', ghop_student_logic.logic)] |
56 rights['apply'] = [ |
72 rights['apply'] = [ |
57 'checkIsUser', |
73 'checkIsUser', |
58 ('checkIsActivePeriod', |
74 ('checkIsActivePeriod', ['student_signup', 'scope_path']), |
59 ['student_signup', 'scope_path', ghop_program_logic.logic]), |
75 ('checkIsNotParticipatingInProgramInScope', |
60 ('checkIsNotParticipatingInProgramInScope', [ghop_program_logic.logic, |
76 [ghop_student_logic.logic, ghop_org_admin_logic.logic, |
61 ghop_student_logic.logic, ghop_org_admin_logic.logic, |
|
62 ghop_mentor_logic.logic]), |
77 ghop_mentor_logic.logic]), |
63 'checkCanApply'] |
78 'checkCanApply'] |
64 rights['manage'] = [('checkIsMyActiveRole', ghop_student_logic.logic)] |
79 rights['manage'] = [('checkIsMyActiveRole', ghop_student_logic.logic)] |
|
80 rights['list_student_tasks'] = [('checkIsMyActiveRole', |
|
81 ghop_student_logic.logic)] |
65 |
82 |
66 new_params = {} |
83 new_params = {} |
67 new_params['logic'] = soc.modules.ghop.logic.models.student.logic |
84 new_params['logic'] = soc.modules.ghop.logic.models.student.logic |
68 new_params['rights'] = rights |
85 new_params['rights'] = rights |
69 |
86 |
77 new_params['sidebar_grouping'] = 'Students' |
94 new_params['sidebar_grouping'] = 'Students' |
78 |
95 |
79 new_params['module_package'] = 'soc.modules.ghop.views.models' |
96 new_params['module_package'] = 'soc.modules.ghop.views.models' |
80 new_params['url_name'] = 'ghop/student' |
97 new_params['url_name'] = 'ghop/student' |
81 |
98 |
|
99 new_params['extra_django_patterns'] = patterns |
|
100 |
82 params = dicts.merge(params, new_params, sub_merge=True) |
101 params = dicts.merge(params, new_params, sub_merge=True) |
83 |
102 |
84 super(View, self).__init__(params=params) |
103 super(View, self).__init__(params=params) |
|
104 |
|
105 @decorators.merge_params |
|
106 @decorators.check_access |
|
107 def listStudentTasks(self, request, access_type, page_name=None, |
|
108 params=None, **kwargs): |
|
109 """Displays a list of all tasks for a given student. |
|
110 |
|
111 See base.View.list() for more details. |
|
112 """ |
|
113 |
|
114 # obtain program entity based on request params |
|
115 program = ghop_program_logic.logic.getFromKeyNameOr404( |
|
116 kwargs['scope_path']) |
|
117 |
|
118 user_account = user_logic.logic.getForCurrentAccount() |
|
119 |
|
120 filter = { |
|
121 'user': user_account, |
|
122 'program': program |
|
123 } |
|
124 |
|
125 tasks = ghop_task_logic.logic.getForFields(filter=filter) |
|
126 |
|
127 tasks_by_orgs = {} |
|
128 for task in tasks: |
|
129 if task.scope.name in tasks_by_orgs: |
|
130 tasks_by_orgs[task.scope.name].append(task) |
|
131 else: |
|
132 tasks_by_orgs[task.scope.name] = [task] |
|
133 |
|
134 contents = [] |
|
135 context = {} |
|
136 |
|
137 sp_params = params.copy() |
|
138 sp_params['list_template'] = 'soc/models/list.html' |
|
139 sp_params['list_heading'] = 'modules/ghop/task/list/heading.html' |
|
140 sp_params['list_row'] = 'modules/ghop/task/list/row.html' |
|
141 sp_params['pagination'] = 'soc/list/no_pagination.html' |
|
142 sp_params['list_action'] = (redirects.getPublicRedirect, sp_params) |
|
143 |
|
144 sp_org_params = sp_params.copy() |
|
145 for org in tasks_by_orgs.keys(): |
|
146 sp_org_params['list_description'] = self.DEF_STUDENT_TASKS_MSG_FMT % org |
|
147 |
|
148 sp_org_list = lists.getListContentForData(request, sp_org_params, |
|
149 data=tasks_by_orgs[org], idx=1, need_content=True) |
|
150 |
|
151 contents.append(sp_org_list) |
|
152 |
|
153 return self._list(request, sp_params, contents, page_name, context) |
85 |
154 |
86 |
155 |
87 view = View() |
156 view = View() |
88 |
157 |
89 apply = decorators.view(view.apply) |
158 apply = decorators.view(view.apply) |
90 create = decorators.view(view.create) |
159 create = decorators.view(view.create) |
91 delete = decorators.view(view.delete) |
160 delete = decorators.view(view.delete) |
92 edit = decorators.view(view.edit) |
161 edit = decorators.view(view.edit) |
93 list = decorators.view(view.list) |
162 list = decorators.view(view.list) |
|
163 list_student_tasks = decorators.view(view.listStudentTasks) |
94 manage = decorators.view(view.manage) |
164 manage = decorators.view(view.manage) |
95 public = decorators.view(view.public) |
165 public = decorators.view(view.public) |
96 export = decorators.view(view.export) |
166 export = decorators.view(view.export) |