25 |
25 |
26 |
26 |
27 from django.utils.translation import ugettext |
27 from django.utils.translation import ugettext |
28 |
28 |
29 from soc.logic import dicts |
29 from soc.logic import dicts |
|
30 from soc.logic.models import user as user_logic |
|
31 |
30 from soc.views.helper import decorators |
32 from soc.views.helper import decorators |
31 from soc.views.helper import dynaform |
33 from soc.views.helper import dynaform |
32 from soc.views.helper import lists |
34 from soc.views.helper import lists |
33 from soc.views.helper import redirects |
35 from soc.views.helper import redirects |
34 from soc.views.models import student |
36 from soc.views.models import student |
35 |
|
36 from soc.logic.models import user as user_logic |
|
37 |
37 |
38 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 |
39 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 |
40 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 |
41 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 |
42 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 |
43 from soc.modules.ghop.logic.models import task as ghop_task_logic |
44 from soc.modules.ghop.views.helper import access as ghop_access |
44 from soc.modules.ghop.views.helper import access as ghop_access |
45 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 |
|
46 from soc.modules.ghop.views.models import task as ghop_task_view |
46 |
47 |
47 import soc.modules.ghop.logic.models.student |
48 import soc.modules.ghop.logic.models.student |
48 |
49 |
49 |
50 |
50 class View(student.View): |
51 class View(student.View): |
61 params: a dict with params for this View |
62 params: a dict with params for this View |
62 """ |
63 """ |
63 |
64 |
64 patterns = [] |
65 patterns = [] |
65 patterns += [ |
66 patterns += [ |
66 (r'^%(url_name)s/(?P<access_type>list_student_tasks)/%(key_fields)s$', |
67 (r'^%(url_name)s/(?P<access_type>list_student_tasks)/%(scope)s$', |
67 '%(module_package)s.%(module_name)s.list_student_tasks', |
68 '%(module_package)s.%(module_name)s.list_student_tasks', |
68 'List Student tasks')] |
69 'List Student tasks')] |
69 |
70 |
70 rights = ghop_access.GHOPChecker(params) |
71 rights = ghop_access.GHOPChecker(params) |
71 rights['edit'] = [('checkIsMyActiveRole', ghop_student_logic.logic)] |
72 rights['edit'] = [('checkIsMyActiveRole', ghop_student_logic.logic)] |
75 ('checkIsNotParticipatingInProgramInScope', |
76 ('checkIsNotParticipatingInProgramInScope', |
76 [ghop_student_logic.logic, ghop_org_admin_logic.logic, |
77 [ghop_student_logic.logic, ghop_org_admin_logic.logic, |
77 ghop_mentor_logic.logic]), |
78 ghop_mentor_logic.logic]), |
78 'checkCanApply'] |
79 'checkCanApply'] |
79 rights['manage'] = [('checkIsMyActiveRole', ghop_student_logic.logic)] |
80 rights['manage'] = [('checkIsMyActiveRole', ghop_student_logic.logic)] |
80 rights['list_student_tasks'] = [('checkIsMyActiveRole', |
81 rights['list_student_tasks'] = [('checkHasActiveRoleForScope', |
81 ghop_student_logic.logic)] |
82 ghop_student_logic.logic)] |
82 |
83 |
83 new_params = {} |
84 new_params = {} |
84 new_params['logic'] = soc.modules.ghop.logic.models.student.logic |
85 new_params['logic'] = soc.modules.ghop.logic.models.student.logic |
85 new_params['rights'] = rights |
86 new_params['rights'] = rights |
124 |
125 |
125 tasks = ghop_task_logic.logic.getForFields(filter=filter) |
126 tasks = ghop_task_logic.logic.getForFields(filter=filter) |
126 |
127 |
127 tasks_by_orgs = {} |
128 tasks_by_orgs = {} |
128 for task in tasks: |
129 for task in tasks: |
129 if task.scope.name in tasks_by_orgs: |
130 key = task.scope.key().id_or_name() |
130 tasks_by_orgs[task.scope.name].append(task) |
131 if key in tasks_by_orgs: |
|
132 tasks_by_orgs[key][1].append(task) |
131 else: |
133 else: |
132 tasks_by_orgs[task.scope.name] = [task] |
134 tasks_by_orgs[key] = (task.scope.name, [task]) |
133 |
135 |
134 contents = [] |
136 contents = [] |
135 context = {} |
137 context = {} |
136 |
138 |
137 sp_params = params.copy() |
139 st_params = ghop_task_view.view.getParams().copy() |
138 sp_params['list_template'] = 'soc/models/list.html' |
140 st_params['list_template'] = 'soc/models/list.html' |
139 sp_params['list_heading'] = 'modules/ghop/task/list/heading.html' |
141 st_params['list_heading'] = 'modules/ghop/task/list/heading.html' |
140 sp_params['list_row'] = 'modules/ghop/task/list/row.html' |
142 st_params['list_row'] = 'modules/ghop/task/list/row.html' |
141 sp_params['pagination'] = 'soc/list/no_pagination.html' |
143 st_params['list_action'] = (redirects.getPublicRedirect, st_params) |
142 sp_params['list_action'] = (redirects.getPublicRedirect, sp_params) |
|
143 |
144 |
144 sp_org_params = sp_params.copy() |
145 st_org_params = st_params.copy() |
145 for org in tasks_by_orgs.keys(): |
146 for k, v in tasks_by_orgs.iteritems(): |
146 sp_org_params['list_description'] = self.DEF_STUDENT_TASKS_MSG_FMT % org |
147 st_org_params['list_description'] = self.DEF_STUDENT_TASKS_MSG_FMT % v[0] |
147 |
148 |
148 sp_org_list = lists.getListContentForData(request, sp_org_params, |
149 st_org_list = self._listStudentTasks(tasks_by_orgs[k][1], st_org_params) |
149 data=tasks_by_orgs[org], idx=1, need_content=True) |
|
150 |
150 |
151 contents.append(sp_org_list) |
151 contents.append(st_org_list) |
152 |
152 |
153 return self._list(request, sp_params, contents, page_name, context) |
153 return self._list(request, st_params, contents, page_name, context) |
154 |
154 |
|
155 def _listStudentTasks(self, data, params): |
|
156 """Returns a list with all entities specified in data. |
|
157 """ |
|
158 |
|
159 result = dicts.rename(params, params['list_params']) |
|
160 result['action'] = (redirects.getPublicRedirect, params) |
|
161 result['data'] = data |
|
162 result['pagination'] = 'soc/list/no_pagination.html' |
|
163 |
|
164 return result |
155 |
165 |
156 view = View() |
166 view = View() |
157 |
167 |
158 apply = decorators.view(view.apply) |
168 apply = decorators.view(view.apply) |
159 create = decorators.view(view.create) |
169 create = decorators.view(view.create) |