source: WAeUP_SRP/trunk/skins/waeup_default/waeup_document_create_do.py @ 14086

Last change on this file since 14086 was 3824, checked in by Henrik Bettermann, 16 years ago

implement configuration object (step 1)

Configuration file must be created with create_configuration_file.py

  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1##parameters=type_name, datamodel
2# $Id: waeup_document_create_do.py 3824 2008-12-19 15:44:45Z henrik $
3"""
4Create an empty object in the context according to the datamodel.
5
6Datamodel may be examined to create a suitable id.
7
8Returns the created object (usually a proxy).
9"""
10from Products.CMFCore.utils import getToolByName
11request = context.REQUEST
12
13if type_name in ("StudyLevel","StudentStudyLevel","WAeUPDocument","StudentPastoralReport","WAeUPConfiguration"):
14    id = datamodel.get('code')
15else:
16    id = datamodel.get('code').upper()
17    datamodel.set('code',id)
18##if not id:
19##    id = 'my ' + type_name
20##id = context.computeId(compute_from=id) # XXX shouldn't use a skin
21##
22language = datamodel.get('Language')
23if not language:
24    ts = getToolByName(context, 'translation_service')
25    language = ts.getSelectedLanguage()
26
27ttool = getToolByName(context, 'portal_types')
28ti = ttool[type_name]
29allow_discussion = ti.allowDiscussion()
30
31# Datamodel is passed so that flexti can initialize the object.
32new_id = context.invokeFactory(type_name, id, datamodel=datamodel,
33                               language=language,
34                               allow_discussion=allow_discussion)
35if new_id is not None:
36    id = new_id
37if type_name == "xxxCourse": # disabled handled by event
38    d = {}
39    ptl = request.get('PATH_TRANSLATED').split('/')
40    ai = ptl.index('academics')
41    d['faculty'] = ptl[ai+1]
42    d['department'] = ptl[ai+2]
43    from_dm = ('code','title','semester','credits',)
44    for f in from_dm:
45        d[f] = datamodel.get(f)
46    context.courses_catalog.addRecord(**d)
47ob = getattr(context, id)
48ob.getContent().edit(mapping=datamodel)
49
50context.notifyCPSDocumentCreation(ob=ob) # BBB obsolete in CPS 3.5.0
51
52return ob
Note: See TracBrowser for help on using the repository browser.