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('prefix').upper() |
---|
13 | datamodel.set('prefix',id) |
---|
14 | bl = context.portal_catalog({'meta_type': "ScratchCardBatch"}) |
---|
15 | b_ids = [b.getId(), for b in bl] |
---|
16 | next = 1 |
---|
17 | while "%(prefix)s_%(next)d" % vars() in b_ids: |
---|
18 | next += 1 |
---|
19 | id = "%(prefix)s_%(next)d" % vars() |
---|
20 | ##if not id: |
---|
21 | ## id = 'my ' + type_name |
---|
22 | ##id = context.computeId(compute_from=id) # XXX shouldn't use a skin |
---|
23 | ## |
---|
24 | language = datamodel.get('Language') |
---|
25 | if not language: |
---|
26 | ts = getToolByName(context, 'translation_service') |
---|
27 | language = ts.getSelectedLanguage() |
---|
28 | |
---|
29 | # Datamodel is passed so that flexti can initialize the object. |
---|
30 | new_id = context.invokeFactory(type_name, id, datamodel=datamodel, |
---|
31 | language=language, |
---|
32 | ) |
---|
33 | if new_id is not None: |
---|
34 | id = new_id |
---|
35 | |
---|
36 | ob = getattr(context, id) |
---|
37 | ob.getContent().edit(mapping=datamodel) |
---|
38 | |
---|
39 | context.notifyCPSDocumentCreation(ob=ob) # BBB obsolete in CPS 3.5.0 |
---|
40 | |
---|
41 | return ob |
---|