1 | ##parameters=REQUEST |
---|
2 | # $Id: add_course_ticket.py 155 2005-11-04 22:20:14Z joachim $ |
---|
3 | """ |
---|
4 | book an accomodation |
---|
5 | """ |
---|
6 | type_name = 'CourseTicket' |
---|
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= 'metadata', |
---|
20 | context=context, |
---|
21 | mapping=validate and REQUEST, |
---|
22 | ob={}, |
---|
23 | layout_mode='create', |
---|
24 | create_action = 'add_course_ticket', |
---|
25 | ) |
---|
26 | if True or psm == 'invalid': |
---|
27 | return context.common_edit_form(rendered = res, |
---|
28 | create = 1, |
---|
29 | type_name = type_name, |
---|
30 | psm = 'Not yet active', |
---|
31 | #psm = 'Please correct your errors', |
---|
32 | ) |
---|
33 | elif psm == '': |
---|
34 | return context.common_edit_form(rendered = res, |
---|
35 | create = 1, |
---|
36 | type_name = type_name, |
---|
37 | psm = psm, |
---|
38 | #psm = str(ds), |
---|
39 | ) |
---|
40 | |
---|
41 | elif psm == 'valid': |
---|
42 | psm = (ds) |
---|
43 | oid = ds.get('Title') |
---|
44 | if hasattr(context,oid): |
---|
45 | return context.common_edit_form(rendered = res, |
---|
46 | create = 1, |
---|
47 | type_name = type_name, |
---|
48 | psm = 'You already registered for that level', |
---|
49 | ) |
---|
50 | context.invokeFactory(type_name,oid) |
---|
51 | object = getattr(context,oid) |
---|
52 | voc = pv.courselevel |
---|
53 | ds.set('Title',voc.get(oid)) |
---|
54 | object.getContent().edit(mapping=ds,proxy=object) |
---|
55 | context.notifyCPSDocumentCreation(ob=object) |
---|
56 | psm = 'new %s created' % oid |
---|
57 | semester_id = 'Semester_1_%s_%s' % (oid,context.getId()) |
---|
58 | object.invokeFactory('Semester',semester_id) |
---|
59 | semester = getattr(object,semester_id) |
---|
60 | semester.getContent().edit(mapping={'Title': 'First Semester'}) |
---|
61 | semester_id = 'Semester_2_%s_%s' % (oid,context.getId()) |
---|
62 | object.invokeFactory('Semester',semester_id) |
---|
63 | semester = getattr(object,semester_id) |
---|
64 | semester.getContent().edit(mapping={'Title': 'Second Semester'}) |
---|
65 | context_ti = context.portal_types[context.portal_type] |
---|
66 | index = context_ti.getActionById('view','university_view') |
---|
67 | return getattr(context,index)(psm=psm) |
---|