##parameters=REQUEST # $Id: add_course_ticket.py 404 2006-08-22 21:45:50Z joachim $ """ add a course_ticket """ type_name = 'CourseTicket' ti = context.portal_types[type_name] pm = context.portal_membership REQUEST.set('type_name',type_name) validate = REQUEST.has_key("cpsdocument_create_button") lt = context.portal_layouts pv = context.portal_vocabularies #pr = context.portal_registration res,psm,ds = lt.renderLayout(layout_id= 'study_level', schema_id= 'study_level', context=context, mapping=validate and REQUEST, ob={}, layout_mode='create', create_action = 'add_course_ticket', ) if True or psm == 'invalid': return context.common_edit_form(rendered = res, create = 1, type_name = type_name, psm = 'Not yet active', #psm = 'Please correct your errors', ) elif psm == '': return context.common_edit_form(rendered = res, create = 1, type_name = type_name, psm = psm, #psm = str(ds), ) elif psm == 'valid': psm = (ds) oid = ds.get('Title') if hasattr(context,oid): return context.common_edit_form(rendered = res, create = 1, type_name = type_name, psm = 'You already registered for that level', ) context.invokeFactory(type_name,oid) object = getattr(context,oid) voc = pv.courselevel ds.set('Title',voc.get(oid)) object.getContent().edit(mapping=ds,proxy=object) context.notifyCPSDocumentCreation(ob=object) psm = 'new %s created' % oid semester_id = 'Semester_1_%s_%s' % (oid,context.getId()) object.invokeFactory('Semester',semester_id) semester = getattr(object,semester_id) semester.getContent().edit(mapping={'Title': 'First Semester'}) semester_id = 'Semester_2_%s_%s' % (oid,context.getId()) object.invokeFactory('Semester',semester_id) semester = getattr(object,semester_id) semester.getContent().edit(mapping={'Title': 'Second Semester'}) context_ti = context.portal_types[context.portal_type] index = context_ti.getActionById('view','university_view') return getattr(context,index)(psm=psm)