1 | ##parameters=type_name, datamodel |
---|
2 | # $Id: waeup_document_create_do.py 2013 2007-07-12 16:12:23Z henrik $ |
---|
3 | """ |
---|
4 | Create an empty object in the context according to the datamodel. |
---|
5 | |
---|
6 | Datamodel may be examined to create a suitable id. |
---|
7 | |
---|
8 | Returns the created object (usually a proxy). |
---|
9 | """ |
---|
10 | from Products.CMFCore.utils import getToolByName |
---|
11 | request = context.REQUEST |
---|
12 | |
---|
13 | if type_name in ("StudyLevel","StudentStudyLevel","WAeUPDocument"): |
---|
14 | id = datamodel.get('code') |
---|
15 | else: |
---|
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 | ## |
---|
22 | language = datamodel.get('Language') |
---|
23 | if not language: |
---|
24 | ts = getToolByName(context, 'translation_service') |
---|
25 | language = ts.getSelectedLanguage() |
---|
26 | |
---|
27 | ttool = getToolByName(context, 'portal_types') |
---|
28 | ti = ttool[type_name] |
---|
29 | allow_discussion = ti.allowDiscussion() |
---|
30 | |
---|
31 | # Datamodel is passed so that flexti can initialize the object. |
---|
32 | new_id = context.invokeFactory(type_name, id, datamodel=datamodel, |
---|
33 | language=language, |
---|
34 | allow_discussion=allow_discussion) |
---|
35 | if new_id is not None: |
---|
36 | id = new_id |
---|
37 | if 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) |
---|
47 | ob = getattr(context, id) |
---|
48 | ob.getContent().edit(mapping=datamodel) |
---|
49 | |
---|
50 | context.notifyCPSDocumentCreation(ob=ob) # BBB obsolete in CPS 3.5.0 |
---|
51 | |
---|
52 | return ob |
---|