1 | ##parameters=type_name, datamodel |
---|
2 | # $Id: cpsdocument_create_do.py 34091 2006-03-06 18:37:08Z atchertchian $ |
---|
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 | |
---|
12 | if type_name == "StudyLevel": |
---|
13 | id = datamodel.get('code') |
---|
14 | else: |
---|
15 | id = datamodel.get('code').upper() |
---|
16 | datamodel.set('code',id) |
---|
17 | ##if not id: |
---|
18 | ## id = 'my ' + type_name |
---|
19 | ##id = context.computeId(compute_from=id) # XXX shouldn't use a skin |
---|
20 | ## |
---|
21 | language = datamodel.get('Language') |
---|
22 | if not language: |
---|
23 | ts = getToolByName(context, 'translation_service') |
---|
24 | language = ts.getSelectedLanguage() |
---|
25 | |
---|
26 | ttool = getToolByName(context, 'portal_types') |
---|
27 | ti = ttool[type_name] |
---|
28 | allow_discussion = ti.allowDiscussion() |
---|
29 | |
---|
30 | # Datamodel is passed so that flexti can initialize the object. |
---|
31 | new_id = context.invokeFactory(type_name, id, datamodel=datamodel, |
---|
32 | language=language, |
---|
33 | allow_discussion=allow_discussion) |
---|
34 | if new_id is not None: |
---|
35 | id = new_id |
---|
36 | |
---|
37 | ob = getattr(context, id) |
---|
38 | ob.getContent().edit(mapping=datamodel) |
---|
39 | |
---|
40 | context.notifyCPSDocumentCreation(ob=ob) # BBB obsolete in CPS 3.5.0 |
---|
41 | |
---|
42 | return ob |
---|