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.helper import timeline as timeline_helper |
30 from soc.logic.helper import timeline as timeline_helper |
31 from soc.logic.models import host as host_logic |
31 from soc.logic.models import host as host_logic |
|
32 from soc.logic.models import mentor as mentor_logic |
|
33 from soc.logic.models import org_admin as org_admin_logic |
32 from soc.logic.models import program as program_logic |
34 from soc.logic.models import program as program_logic |
|
35 from soc.logic.models import student as student_logic |
33 from soc.logic.models.document import logic as document_logic |
36 from soc.logic.models.document import logic as document_logic |
34 from soc.views import helper |
37 from soc.views import helper |
35 from soc.views import out_of_band |
38 from soc.views import out_of_band |
36 from soc.views.helper import access |
39 from soc.views.helper import access |
37 from soc.views.helper import decorators |
40 from soc.views.helper import decorators |
73 new_params['scope_redirect'] = redirects.getCreateRedirect |
76 new_params['scope_redirect'] = redirects.getCreateRedirect |
74 |
77 |
75 new_params['name'] = "Program" |
78 new_params['name'] = "Program" |
76 new_params['sidebar_grouping'] = 'Programs' |
79 new_params['sidebar_grouping'] = 'Programs' |
77 new_params['document_prefix'] = "program" |
80 new_params['document_prefix'] = "program" |
78 |
|
79 |
81 |
80 new_params['extra_dynaexclude'] = ['timeline', 'org_admin_agreement', |
82 new_params['extra_dynaexclude'] = ['timeline', 'org_admin_agreement', |
81 'mentor_agreement', 'student_agreement'] |
83 'mentor_agreement', 'student_agreement'] |
82 |
84 |
83 # TODO add clean field to check for uniqueness in link_id and scope_path |
85 # TODO add clean field to check for uniqueness in link_id and scope_path |
113 result['workflow'] = forms.CharField(widget=widgets.ReadOnlyInput(), |
115 result['workflow'] = forms.CharField(widget=widgets.ReadOnlyInput(), |
114 required=True) |
116 required=True) |
115 |
117 |
116 new_params['edit_extra_dynaproperties'] = result |
118 new_params['edit_extra_dynaproperties'] = result |
117 |
119 |
118 |
|
119 references = [ |
120 references = [ |
120 ('org_admin_agreement_link_id', 'org_admin_agreement', document_logic, |
121 ('org_admin_agreement_link_id', 'org_admin_agreement', document_logic, |
121 lambda x: x.org_admin_agreement), |
122 lambda x: x.org_admin_agreement), |
122 ('mentor_agreement_link_id', 'mentor_agreement', document_logic, |
123 ('mentor_agreement_link_id', 'mentor_agreement', document_logic, |
123 lambda x: x.mentor_agreement), |
124 lambda x: x.mentor_agreement), |
188 |
189 |
189 if entity.status == 'visible': |
190 if entity.status == 'visible': |
190 # show the documents for this program, even for not logged in users |
191 # show the documents for this program, even for not logged in users |
191 items += document_view.view.getMenusForScope(entity, params) |
192 items += document_view.view.getMenusForScope(entity, params) |
192 items += self._getTimeDependentEntries(entity, params, id, user) |
193 items += self._getTimeDependentEntries(entity, params, id, user) |
193 |
|
194 url = redirects.getPublicListRedirect(entity, {'url_name': 'org'}) |
|
195 items += [(url, "List Organizations", 'any_access')] |
|
196 |
194 |
197 try: |
195 try: |
198 # check if the current user is a host for this program |
196 # check if the current user is a host for this program |
199 rights.doCachedCheck('checkIsHostForProgram', |
197 rights.doCachedCheck('checkIsHostForProgram', |
200 {'scope_path': entity.scope_path, |
198 {'scope_path': entity.scope_path, |
253 items += [ |
251 items += [ |
254 (redirects.getListSelfRedirect(program_entity, |
252 (redirects.getListSelfRedirect(program_entity, |
255 {'url_name' : 'org_app'}), |
253 {'url_name' : 'org_app'}), |
256 "List My Organization Applications", 'any_access')] |
254 "List My Organization Applications", 'any_access')] |
257 |
255 |
|
256 # get the student entity for this user and program |
|
257 filter = {'user': user, |
|
258 'scope': program_entity} |
|
259 student_entity = student_logic.logic.getForFields(filter, unique=True) |
|
260 |
|
261 if student_entity: |
|
262 items += self._getStudentEntries(program_entity, params, id, user) |
|
263 |
|
264 # get mentor and org_admin entity for this user and program |
|
265 filter = {'user': user, |
|
266 'program': program_entity} |
|
267 mentor_entity = mentor_logic.logic.getForFields(filter, unique=True) |
|
268 org_admin_entity = org_admin_logic.logic.getForFields(filter, unique=True) |
|
269 |
|
270 if mentor_entity or org_admin_entity: |
|
271 items += self._getOrganizationEntries(program_entity, params, id, user) |
|
272 |
|
273 if not (student_entity or mentor_entity or org_admin_entity): |
|
274 if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'): |
|
275 # this user does not have a role yet for this program |
|
276 items += [('/student/apply/%s' % (program_entity.key().name()), |
|
277 "Register as a Student", 'any_access')] |
|
278 |
|
279 if timeline_helper.isAfterEvent(timeline_entity, |
|
280 'accepted_organization_announced_deadline'): |
|
281 # add a link to list all the organizations |
|
282 items += [(redirects.getPublicListRedirect(program_entity, {'url_name': 'org'}), |
|
283 "List participating Organizations", 'any_access')] |
|
284 |
|
285 if not student_entity: |
|
286 # add apply to become a mentor link |
|
287 items += [('/org/apply_mentor/%s' % (program_entity.key().name()), |
|
288 "Apply to become a Mentor", 'any_access')] |
|
289 |
|
290 return items |
|
291 |
|
292 def _getStudentEntries(self, program_entity, params, id, user): |
|
293 """Returns a list with menu items for students in a specific program. |
|
294 """ |
|
295 |
|
296 items = [] |
|
297 |
|
298 timeline_entity = program_entity.timeline |
|
299 |
|
300 # TODO(ljvderijk) add the student application links |
|
301 |
|
302 if timeline_helper.isActivePeriod(timeline_entity, 'student_signup'): |
|
303 #items += [('/org/apply_mentor/%s' % (program_entity.key().name()), |
|
304 # "Send in your student proposal (N/A)", 'any_access')] |
|
305 #items += [('/org/apply_mentor/%s' % (program_entity.key().name()), |
|
306 # "List my student proposals (N/A)", 'any_access')] |
|
307 pass |
|
308 |
|
309 return items |
|
310 |
|
311 def _getOrganizationEntries(self, program_entity, params, id, user): |
|
312 """Returns a list with menu items for org admins and mentors in a |
|
313 specific program. |
|
314 """ |
|
315 |
|
316 # TODO(ljvderijk) think about adding specific org items like submit review |
|
317 |
|
318 items = [] |
|
319 |
258 return items |
320 return items |
259 |
321 |
260 |
322 |
261 view = View() |
323 view = View() |
262 |
324 |