Line | |
---|
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 | id = datamodel.get('code').upper() |
---|
13 | datamodel.set('code',id) |
---|
14 | ##if not id: |
---|
15 | ## id = 'my ' + type_name |
---|
16 | ##id = context.computeId(compute_from=id) # XXX shouldn't use a skin |
---|
17 | ## |
---|
18 | language = datamodel.get('Language') |
---|
19 | if not language: |
---|
20 | ts = getToolByName(context, 'translation_service') |
---|
21 | language = ts.getSelectedLanguage() |
---|
22 | |
---|
23 | ttool = getToolByName(context, 'portal_types') |
---|
24 | ti = ttool[type_name] |
---|
25 | allow_discussion = ti.allowDiscussion() |
---|
26 | |
---|
27 | # Datamodel is passed so that flexti can initialize the object. |
---|
28 | new_id = context.invokeFactory(type_name, id, datamodel=datamodel, |
---|
29 | language=language, |
---|
30 | allow_discussion=allow_discussion) |
---|
31 | if new_id is not None: |
---|
32 | id = new_id |
---|
33 | |
---|
34 | ob = getattr(context, id) |
---|
35 | ob.getContent().edit(mapping=datamodel) |
---|
36 | |
---|
37 | context.notifyCPSDocumentCreation(ob=ob) # BBB obsolete in CPS 3.5.0 |
---|
38 | |
---|
39 | return ob |
---|
Note: See
TracBrowser for help on using the repository browser.