##parameters=REQUEST # $Id: register_level.py 188 2005-11-17 08:55:12Z henrik $ """ register for next level """ type_name = 'StudyLevel' 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 = 'register_level', ) if psm == 'invalid': return context.register_level_form(rendered = res, psm = "Please correct your input", ds = ds, ) elif psm == '': return context.register_level_form(rendered = res, psm = None, ds = ds, ) elif psm == 'valid': voc = pv.courselevel level_id = voc.items()[0][0] level = getattr(context,level_id,None) if level: return context.register_level_form(rendered = res, psm = "You have already registered for Level %s" % voc.get(level_id), ds = ds, ) context.invokeFactory(type_name,level_id) object = getattr(context,level_id) ds.set('Title',voc.get(level_id)) object.getContent().edit(mapping=ds,proxy=object) context.notifyCPSDocumentCreation(ob=object) psm = 'new %s created' % level_id semester_id = 'Semester_1_%s_%s' % (level_id,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' % (level_id,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)