Ordering fields from different behaviors

30 views
Skip to first unread message

Jonas Baumann

unread,
Nov 30, 2009, 11:05:37 AM11/30/09
to dexterity-...@googlegroups.com
Hi there

I'm having a little problem with ordering fields in my dexterity content type.

I have something like this:

class IMyBehavior(form.Schema):
 
    form.fieldset(
        u'stuff',
        label = u'Stuff',
        fields = [
                u'foo',
        ],
    )
    foo = schema.Text(
        title=u'Foo'
        required=False
    )
    form.order_before(foo='*')
alsoProvides(IDossier, IFormFieldProvider)


class IMySchema(form.Schema):
 
    form.fieldset(
        u'stuff',
        label = u'Stuff',
        fields = [
                u'bar',
        ],
    )
    bar = schema.Text(
        title=u'Bar'
        required=False
    )


<?xml version="1.0"?>
<object name="mytype" meta_type="Dexterity FTI">
...
  <property name="schema">IMySchema</property>
  <property name="behaviors">
    <element value="IMyBehavior" />
  </property>
...

</object>



Now I'd like to move the field "foo" (behavior) before the field
bar (schema).
Shouldn't that work with the order_before() I used?
It's not working with my code.

Thanks for help

jonas

Martin Aspeli

unread,
Nov 30, 2009, 7:36:44 PM11/30/09
to dexterity-...@googlegroups.com
2009/12/1 Jonas Baumann <tsch...@gmail.com>:
From a quick glance I think it should work.

What happens if you try:

form.order_before(foo='IMySchema.bar')

or

form.order_before(foo='bar')

?

Martin

Jonas Baumann

unread,
Dec 1, 2009, 5:04:14 AM12/1/09
to dexterity-...@googlegroups.com
That was not working. I also tried with ".bar" and all combinations and I tried to set it with "setTaggedValue" directly, but that didn't work either.

I noticed another thing: I think the problem is that the fields are not in the default fieldset:
If I use schema-fields and behavior fields in the default fieldset, I can move and order them in any combination.
If I use schema-fields and behavior-fields in a non-default fieldset, the schema-fields are always above the behavior-fields.

Is that a problem in plone.autoform?

cheers

2009/12/1 Martin Aspeli <opti...@gmail.com>

--

You received this message because you are subscribed to the Google Groups "Dexterity development" group.
To post to this group, send email to dexterity-...@googlegroups.com.
To unsubscribe from this group, send email to dexterity-develo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dexterity-development?hl=en.



Martin Aspeli

unread,
Dec 1, 2009, 6:09:40 AM12/1/09
to dexterity-development
2009/12/1 Jonas Baumann <tsch...@gmail.com>:
> That was not working. I also tried with ".bar" and all combinations and I
> tried to set it with "setTaggedValue" directly, but that didn't work either.

But the fieldsets work, right? That is, some of the directives are
being processed, just not the re-ordering ones.

I don't suppose you could write a failing test for this in plone.autoform?

Did you try using the full dotted name to the field, e.g. my.package.IFoo.bar?

> I noticed another thing: I think the problem is that the fields are not in
> the default fieldset:
> If I use schema-fields and behavior fields in the default fieldset, I can
> move and order them in any combination.
> If I use schema-fields and behavior-fields in a non-default fieldset, the
> schema-fields are always above the behavior-fields.
> Is that a problem in plone.autoform?

It could well be. A failing test would go a long way towards making
this fixable. In any case, please raise a bug for it.

Martin

Thomas Buchberger

unread,
Dec 7, 2009, 4:53:28 AM12/7/09
to Dexterity development
This seems to be an issue in plone.z3cform.fieldsets.utils
Looking at the implementation of the move() method, only fields that
are not in a fieldset (group) are moved.
However if the relative field is in a fieldset, the field gets moved
into that fieldset.
As a workaround: Just don't put fields you want to reorder into a
fieldset. They will be moved into the same fieldset as the relative
field.

On 1 Dez., 12:09, Martin Aspeli <optil...@gmail.com> wrote:
> 2009/12/1 Jonas Baumann <tscho...@gmail.com>:

Martin Aspeli

unread,
Dec 7, 2009, 5:42:48 AM12/7/09
to dexterity-...@googlegroups.com
2009/12/7 Thomas Buchberger <thomas.b...@gmail.com>:
> This seems to be an issue in plone.z3cform.fieldsets.utils
> Looking at the implementation of the move() method, only fields that
> are not in a fieldset (group) are moved.
> However if the relative field is in a fieldset, the field gets moved
> into that fieldset.
> As a workaround: Just don't put fields you want to reorder into a
> fieldset. They will be moved into the same fieldset as the relative
> field.

We should still fix this, though. Do you want to attempt a patch (and
a test, please)? I can help you review + integrate.

Martin

Thomas Buchberger

unread,
Dec 7, 2009, 10:14:15 AM12/7/09
to Dexterity development
I created a patch. I do not have zope commit rights so I'm pasting it
here...

Index: plone.z3cform/plone/z3cform/fieldsets/utils.py
===================================================================
--- plone.z3cform/plone/z3cform/fieldsets/utils.py (Revision 106243)
+++ plone.z3cform/plone/z3cform/fieldsets/utils.py (Arbeitskopie)
@@ -%ld,%ld +%ld,%ld @@
relative = expandPrefix(relative_prefix) + relative

if field_name not in form.fields:
- raise KeyError("Field %s not found" % field_name)
+ found = False
+ for group in form.groups:
+ if field_name in group.fields:
+ found = True
+ break
+ if not found:
+ raise KeyError("Field %s not found" % field_name)

if relative != '*' and relative not in form.fields:
found = False
Index: plone.z3cform/plone/z3cform/fieldsets/README.txt
===================================================================
--- plone.z3cform/plone/z3cform/fieldsets/README.txt (Revision 106243)
+++ plone.z3cform/plone/z3cform/fieldsets/README.txt (Arbeitskopie)
@@ -%ld,%ld +%ld,%ld @@
... bar = schema.TextLine(title=u"Bar")
... baz = schema.TextLine(title=u"Baz")
... fub = schema.TextLine(title=u"Fub")
+ ... qux = schema.TextLine(title=u"Qux")

One plausible implementation is to use an annotation to store this
data.

@@ -%ld,%ld +%ld,%ld @@
... bar = u""
... baz = u""
... fub = u""
+ ... qux = u""

>>> ExtraBehavior = factory(ExtraBehavior)
>>> provideAdapter(ExtraBehavior)
@@ -%ld,%ld +%ld,%ld @@
...
... # Move 'baz' after 'bar'. This means it also moves
gropu.
... self.move('extra.baz', after='extra.bar')
+ ...
+ ... # Remove 'qux' and re-insert into 'Second' group,
+ ... # then move it before 'baz'
+ ... self.remove('qux', prefix='extra')
+ ... self.add(all_fields.select('qux', prefix='extra'),
group='Second')
+ ... self.move('qux', before='baz', prefix='extra',
relative_prefix='extra')


>>> provideAdapter(factory=ExtraBehaviorExtender,
name=u"test.extender")
@@ -%ld,%ld +%ld,%ld @@
This should have the group fields provided by the adapter as well.

>>> form.groups[0].fields.keys()
- ['extra.bar', 'extra.baz']
+ ['extra.bar', 'extra.qux', 'extra.baz']


On 7 Dez., 11:42, Martin Aspeli <optil...@gmail.com> wrote:
> 2009/12/7 Thomas Buchberger <thomas.buchber...@gmail.com>:

Martin Aspeli

unread,
Dec 7, 2009, 10:15:48 AM12/7/09
to dexterity-...@googlegroups.com
Great!

Would you mind raising an issue on
http://code.google.com/p/dexterity/issues if there isn't one already
and attaching this? That way, it won't get lost. :)

Martin

2009/12/7 Thomas Buchberger <thomas.b...@gmail.com>:

Thomas Buchberger

unread,
Dec 7, 2009, 10:30:59 AM12/7/09
to Dexterity development
done.

On 7 Dez., 16:15, Martin Aspeli <optil...@gmail.com> wrote:
> Great!
>
> Would you mind raising an issue onhttp://code.google.com/p/dexterity/issuesif there isn't one already
> and attaching this? That way, it won't get lost. :)
>
> Martin
>
> 2009/12/7 Thomas Buchberger <thomas.buchber...@gmail.com>:

Martin Aspeli

unread,
Dec 7, 2009, 10:34:05 AM12/7/09
to dexterity-...@googlegroups.com
Fantastic - thanks a lot!

2009/12/7 Thomas Buchberger <thomas.b...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages