Skip to content

Commit f364816

Browse files
committed
Make parent formid a part of autogenerated oid
#394
1 parent f8529d8 commit f364816

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

deform/field.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ def __init__(
187187
):
188188
self.counter = counter or itertools.count()
189189
self.order = next(self.counter)
190-
self.oid = getattr(schema, "oid", "deformField%s" % self.order)
191190
self.schema = schema
192191
self.typ = schema.typ # required by Invalid exception
193192
self.name = schema.name
@@ -225,6 +224,8 @@ def __init__(
225224
if parent is not None:
226225
parent = weakref.ref(parent)
227226
self._parent = parent
227+
oid_prefix = getattr(self.get_root(), "formid", "deform")
228+
self.oid = getattr(schema, "oid", f"{oid_prefix}Field{self.order}")
228229
self.__dict__.update(kw)
229230

230231
first_input_index = -1

deform/form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def __init__(
139139
# Use kwargs to pass flags to descendant fields; saves cluttering
140140
# the constructor
141141
kw["focus"] = self.focus
142+
self.formid = formid
142143
field.Field.__init__(self, schema, **kw)
143144
_buttons = []
144145
for button in buttons:
@@ -148,7 +149,6 @@ def __init__(
148149
self.action = action
149150
self.method = method
150151
self.buttons = _buttons
151-
self.formid = formid
152152
self.use_ajax = use_ajax
153153
self.ajax_options = Markup(ajax_options.strip())
154154
form_widget = getattr(schema, "widget", None)

deform/tests/test_form.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,25 @@ def test_issue_71(self):
162162
1,
163163
)
164164

165+
def test_issue_394(self):
166+
# Pyramid
167+
import colander
168+
169+
# Deform
170+
import deform
171+
172+
class FooForm(colander.Schema):
173+
foo_field = colander.SchemaNode(colander.String())
174+
175+
class BarForm(colander.Schema):
176+
bar_field = colander.SchemaNode(colander.String())
177+
178+
foo_form = deform.Form(FooForm(), formid="fooForm")
179+
bar_form = deform.Form(BarForm(), formid="barForm")
180+
self.assertNotEqual(
181+
foo_form["foo_field"].oid, bar_form["bar_field"].oid
182+
)
183+
165184

166185
class TestButton(unittest.TestCase):
167186
def _makeOne(self, **kw):

0 commit comments

Comments
 (0)