1 | ##parameters=REQUEST |
---|
2 | # $Id: register_level.py 188 2005-11-17 08:55:12Z henrik $ |
---|
3 | """ |
---|
4 | register for next level |
---|
5 | """ |
---|
6 | type_name = 'StudyLevel' |
---|
7 | ti = context.portal_types[type_name] |
---|
8 | pm = context.portal_membership |
---|
9 | REQUEST.set('type_name',type_name) |
---|
10 | |
---|
11 | validate = REQUEST.has_key("cpsdocument_create_button") |
---|
12 | |
---|
13 | |
---|
14 | lt = context.portal_layouts |
---|
15 | pv = context.portal_vocabularies |
---|
16 | #pr = context.portal_registration |
---|
17 | |
---|
18 | res,psm,ds = lt.renderLayout(layout_id= 'study_level', |
---|
19 | schema_id= 'study_level', |
---|
20 | context=context, |
---|
21 | mapping=validate and REQUEST, |
---|
22 | ob={}, |
---|
23 | layout_mode='create', |
---|
24 | create_action = 'register_level', |
---|
25 | ) |
---|
26 | if psm == 'invalid': |
---|
27 | return context.register_level_form(rendered = res, |
---|
28 | psm = "Please correct your input", |
---|
29 | ds = ds, |
---|
30 | ) |
---|
31 | elif psm == '': |
---|
32 | return context.register_level_form(rendered = res, |
---|
33 | psm = None, |
---|
34 | ds = ds, |
---|
35 | ) |
---|
36 | |
---|
37 | elif psm == 'valid': |
---|
38 | voc = pv.courselevel |
---|
39 | level_id = voc.items()[0][0] |
---|
40 | level = getattr(context,level_id,None) |
---|
41 | if level: |
---|
42 | return context.register_level_form(rendered = res, |
---|
43 | psm = "You have already registered for Level %s" % voc.get(level_id), |
---|
44 | ds = ds, |
---|
45 | ) |
---|
46 | |
---|
47 | context.invokeFactory(type_name,level_id) |
---|
48 | object = getattr(context,level_id) |
---|
49 | ds.set('Title',voc.get(level_id)) |
---|
50 | object.getContent().edit(mapping=ds,proxy=object) |
---|
51 | context.notifyCPSDocumentCreation(ob=object) |
---|
52 | psm = 'new %s created' % level_id |
---|
53 | semester_id = 'Semester_1_%s_%s' % (level_id,context.getId()) |
---|
54 | object.invokeFactory('Semester',semester_id) |
---|
55 | semester = getattr(object,semester_id) |
---|
56 | semester.getContent().edit(mapping={'Title': 'First Semester'}) |
---|
57 | semester_id = 'Semester_2_%s_%s' % (level_id,context.getId()) |
---|
58 | object.invokeFactory('Semester',semester_id) |
---|
59 | semester = getattr(object,semester_id) |
---|
60 | semester.getContent().edit(mapping={'Title': 'Second Semester'}) |
---|
61 | context_ti = context.portal_types[context.portal_type] |
---|
62 | index = context_ti.getActionById('view','university_view') |
---|
63 | return getattr(context,index)(psm=psm) |
---|