Skip to content

Commit 45d43da

Browse files
authored
Fix API create for Dexterity types (#1829)
1 parent ae9ad24 commit 45d43da

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
1.3.5 (unreleased)
55
------------------
66

7+
- #1829 Fix API create for Dexterity types
78
- #1827 Fix categories don't show up automatically on Analysis Service creation
89
- #1825 Fix TypeError when creating Dynamic Analysis Specifications
910
- #1825 Fix dynamic analysis specification listing error for empty excel columns

bika/lims/api/__init__.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,41 +130,36 @@ def create(container, portal_type, *args, **kwargs):
130130
:returns: The new created object
131131
"""
132132
from bika.lims.utils import tmpID
133-
if kwargs.get("title") is None:
134-
kwargs["title"] = "New {}".format(portal_type)
135133

136-
# generate a temporary ID
137-
tmp_id = tmpID()
134+
id = kwargs.pop("id", tmpID())
135+
title = kwargs.pop("title", "New {}".format(portal_type))
138136

139137
# get the fti
140138
types_tool = get_tool("portal_types")
141139
fti = types_tool.getTypeInfo(portal_type)
142140

143141
if fti.product:
144-
obj = _createObjectByType(portal_type, container, tmp_id)
142+
obj = _createObjectByType(portal_type, container, id)
143+
obj.processForm()
144+
obj.edit(title=title, **kwargs)
145+
modified(obj)
145146
else:
146147
# newstyle factory
147148
factory = getUtility(IFactory, fti.factory)
148-
obj = factory(tmp_id, *args, **kwargs)
149+
obj = factory(id, *args, **kwargs)
149150
if hasattr(obj, '_setPortalTypeName'):
150151
obj._setPortalTypeName(fti.getId())
152+
# set the title
153+
obj.title = safe_unicode(title)
154+
# notify that the object was created
151155
notify(ObjectCreatedEvent(obj))
152156
# notifies ObjectWillBeAddedEvent, ObjectAddedEvent and
153157
# ContainerModifiedEvent
154-
container._setObject(tmp_id, obj)
158+
container._setObject(id, obj)
155159
# we get the object here with the current object id, as it might be
156160
# renamed already by an event handler
157161
obj = container._getOb(obj.getId())
158162

159-
# handle AT Content
160-
if is_at_content(obj):
161-
obj.processForm()
162-
163-
# Edit after processForm; processForm does AT unmarkCreationFlag.
164-
obj.edit(**kwargs)
165-
166-
# explicit notification
167-
modified(obj)
168163
return obj
169164

170165

0 commit comments

Comments
 (0)