How to replace a field in a plone.supermodel schema?

classic Classic list List threaded Threaded
6 messages Options
khink khink
Reply | Threaded
Open this post in threaded view
|

How to replace a field in a plone.supermodel schema?

I want to replace the 'subjects' field from p.a.dexterity's
ICategorization with collective.z3cform.keywordwidget.field.Keyword. My
goal is to have a nicer widget (than the lines field).

There's an example in
http://plone.293351.n2.nabble.com/overriding-widget-of-the-subjects-field-with-dexterity-td7457656.html 
but that doesn't work b/c ICategorization has no tagged value for
TEMP_KEY. ICategorization is a plone.supermodel schema.

Any clues?


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
David Glick (Plone) David Glick (Plone)
Reply | Threaded
Open this post in threaded view
|

Re: How to replace a field in a plone.supermodel schema?

On 10/16/13 3:26 AM, Kees Hink wrote:

> I want to replace the 'subjects' field from p.a.dexterity's
> ICategorization with collective.z3cform.keywordwidget.field.Keyword. My
> goal is to have a nicer widget (than the lines field).
>
> There's an example in
> http://plone.293351.n2.nabble.com/overriding-widget-of-the-subjects-field-with-dexterity-td7457656.html
> but that doesn't work b/c ICategorization has no tagged value for
> TEMP_KEY. ICategorization is a plone.supermodel schema.
>
> Any clues?
>
>
Don't rely on plone.supermodel/plone.autoform internals. You can do it
the same way that plone.app.widgets does:
https://github.com/plone/plone.app.widgets/blob/master/plone/app/widgets/dx_bbb.py#L21


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
khink khink
Reply | Threaded
Open this post in threaded view
|

Re: How to replace a field in a plone.supermodel schema?

Thanks for the pointer.

I tried this but wasn't able to get it to work in this manner.

I did succeed in registering the widget using a variant on the "dirty"
version (_directives_values[WIDGETS_KEY]['subjects'] =
'collective.z3cform.keywordwidget.widget.KeywordFieldWidget'). However
the form wasn't saved properly, i'm guessing because
collective.z3cform.keywordwidget also needs a different field type. And
i didn't find a way to change that.

I tried applying  in a behavior
(http://developer.plone.org/reference_manuals/external/plone.app.dexterity/behaviors/creating-and-registering-behaviors.html),
but in a quick try i didn't get that to work.

The example code on
https://pypi.python.org/pypi/collective.z3cform.keywordwidget doesn't
port well to the xml-model approach, when i added the field
collective.z3cform.keywordwidget.field.Keywords to the model_source, it
borked ("SupermodelParseError: Field type
collective.z3cform.keywordwidget.field.Keywords specified for field
keywords is not supported File "<unknown>", line 13 .")

What else could i try?

I'm also willing to use alternatives, main thing is to have a
nicer-looking keywords widget for dexterity types. Maybe it's worth
trying the behavior approach a bit more, and creating a behavior add-on
product in the collective (collective.behavior.keywordwidget?). I'm sure
our customer is not the only one who wants a nicer widget.

Kees

On 10/16/2013 06:26 PM, David Glick (Plone) wrote:

> On 10/16/13 3:26 AM, Kees Hink wrote:
>> I want to replace the 'subjects' field from p.a.dexterity's
>> ICategorization with collective.z3cform.keywordwidget.field.Keyword. My
>> goal is to have a nicer widget (than the lines field).
>>
>> There's an example in
>> http://plone.293351.n2.nabble.com/overriding-widget-of-the-subjects-field-with-dexterity-td7457656.html
>> but that doesn't work b/c ICategorization has no tagged value for
>> TEMP_KEY. ICategorization is a plone.supermodel schema.
>>
>> Any clues?
>>
>>
> Don't rely on plone.supermodel/plone.autoform internals. You can do it
> the same way that plone.app.widgets does:
> https://github.com/plone/plone.app.widgets/blob/master/plone/app/widgets/dx_bbb.py#L21
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
>



------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
c.ledermann c.ledermann
Reply | Threaded
Open this post in threaded view
|

Re: How to replace a field in a plone.supermodel schema?

On Thu, Oct 17, 2013 at 7:27 PM, Kees Hink <[hidden email]> wrote:

> Thanks for the pointer.
>
> I tried this but wasn't able to get it to work in this manner.
>
> I did succeed in registering the widget using a variant on the "dirty"
> version (_directives_values[WIDGETS_KEY]['subjects'] =
> 'collective.z3cform.keywordwidget.widget.KeywordFieldWidget'). However
> the form wasn't saved properly, i'm guessing because
> collective.z3cform.keywordwidget also needs a different field type. And
> i didn't find a way to change that.
>
> I tried applying  in a behavior
> (http://developer.plone.org/reference_manuals/external/plone.app.dexterity/behaviors/creating-and-registering-behaviors.html),
> but in a quick try i didn't get that to work.
>
> The example code on
> https://pypi.python.org/pypi/collective.z3cform.keywordwidget doesn't
> port well to the xml-model approach, when i added the field
> collective.z3cform.keywordwidget.field.Keywords to the model_source, it
> borked ("SupermodelParseError: Field type
> collective.z3cform.keywordwidget.field.Keywords specified for field
> keywords is not supported File "<unknown>", line 13 .")
>
> What else could i try?
>
> I'm also willing to use alternatives, main thing is to have a
> nicer-looking keywords widget for dexterity types. Maybe it's worth
> trying the behavior approach a bit more, and creating a behavior add-on
> product in the collective (collective.behavior.keywordwidget?). I'm sure
> our customer is not the only one who wants a nicer widget.

Yes this is correct, I want it too ;)

> Kees
>
> On 10/16/2013 06:26 PM, David Glick (Plone) wrote:
>> On 10/16/13 3:26 AM, Kees Hink wrote:
>>> I want to replace the 'subjects' field from p.a.dexterity's
>>> ICategorization with collective.z3cform.keywordwidget.field.Keyword. My
>>> goal is to have a nicer widget (than the lines field).
>>>
>>> There's an example in
>>> http://plone.293351.n2.nabble.com/overriding-widget-of-the-subjects-field-with-dexterity-td7457656.html
>>> but that doesn't work b/c ICategorization has no tagged value for
>>> TEMP_KEY. ICategorization is a plone.supermodel schema.
>>>
>>> Any clues?
>>>
>>>
>> Don't rely on plone.supermodel/plone.autoform internals. You can do it
>> the same way that plone.app.widgets does:
>> https://github.com/plone/plone.app.widgets/blob/master/plone/app/widgets/dx_bbb.py#L21
>>
>>
>> ------------------------------------------------------------------------------
>> October Webinars: Code for Performance
>> Free Intel webinars can help you accelerate application performance.
>> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
>> the latest Intel processors and coprocessors. See abstracts and register >
>> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
>>
>
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
> _______________________________________________
> Plone-Users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/plone-users



--
Best Regards,

Christian Ledermann

Nairobi - Kenya
Mobile : +254 702978914

<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don’t drive species to extinction

2) Don’t destroy a habitat that species rely on.

3) Don’t change the climate in ways that will result in the above.

}<(((*>

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
khink khink
Reply | Threaded
Open this post in threaded view
|

Re: How to replace a field in a plone.supermodel schema?

In reply to this post by khink
For the record, this worked:

from zope.i18nmessageid import MessageFactory

# Set up the i18n message factory for our package
MessageFactory = MessageFactory('intogreen.contenttypes')

# -*- coding: utf-8 -*-
from zope.i18nmessageid import MessageFactory
from plone.app.dexterity.behaviors.metadata import ICategorization
from plone.autoform.interfaces import WIDGETS_KEY
from plone.directives.form.schema import TEMP_KEY
from zope import schema as _schema


_ = MessageFactory('collective.z3cform.keywordwidget')

widget = 'collective.z3cform.keywordwidget.widget.KeywordFieldWidget'
# plone 4.3 not groked form
_widget_values = ICategorization.queryTaggedValue(WIDGETS_KEY, {})
_widget_values['subjects'] = widget
ICategorization.setTaggedValue(WIDGETS_KEY, _widget_values)

_schema.getFields(ICategorization)['subjects'].index_name = 'Subject'

On 10/17/2013 06:27 PM, Kees Hink wrote:

> Thanks for the pointer.
>
> I tried this but wasn't able to get it to work in this manner.
>
> I did succeed in registering the widget using a variant on the "dirty"
> version (_directives_values[WIDGETS_KEY]['subjects'] =
> 'collective.z3cform.keywordwidget.widget.KeywordFieldWidget'). However
> the form wasn't saved properly, i'm guessing because
> collective.z3cform.keywordwidget also needs a different field type. And
> i didn't find a way to change that.
>
> I tried applying  in a behavior
> (http://developer.plone.org/reference_manuals/external/plone.app.dexterity/behaviors/creating-and-registering-behaviors.html),
> but in a quick try i didn't get that to work.
>
> The example code on
> https://pypi.python.org/pypi/collective.z3cform.keywordwidget doesn't
> port well to the xml-model approach, when i added the field
> collective.z3cform.keywordwidget.field.Keywords to the model_source, it
> borked ("SupermodelParseError: Field type
> collective.z3cform.keywordwidget.field.Keywords specified for field
> keywords is not supported File "<unknown>", line 13 .")
>
> What else could i try?
>
> I'm also willing to use alternatives, main thing is to have a
> nicer-looking keywords widget for dexterity types. Maybe it's worth
> trying the behavior approach a bit more, and creating a behavior add-on
> product in the collective (collective.behavior.keywordwidget?). I'm sure
> our customer is not the only one who wants a nicer widget.
>
> Kees
>
> On 10/16/2013 06:26 PM, David Glick (Plone) wrote:
>> On 10/16/13 3:26 AM, Kees Hink wrote:
>>> I want to replace the 'subjects' field from p.a.dexterity's
>>> ICategorization with collective.z3cform.keywordwidget.field.Keyword. My
>>> goal is to have a nicer widget (than the lines field).
>>>
>>> There's an example in
>>> http://plone.293351.n2.nabble.com/overriding-widget-of-the-subjects-field-with-dexterity-td7457656.html
>>> but that doesn't work b/c ICategorization has no tagged value for
>>> TEMP_KEY. ICategorization is a plone.supermodel schema.
>>>
>>> Any clues?
>>>
>>>
>> Don't rely on plone.supermodel/plone.autoform internals. You can do it
>> the same way that plone.app.widgets does:
>> https://github.com/plone/plone.app.widgets/blob/master/plone/app/widgets/dx_bbb.py#L21
>>
>>
>> ------------------------------------------------------------------------------
>> October Webinars: Code for Performance
>> Free Intel webinars can help you accelerate application performance.
>> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
>> the latest Intel processors and coprocessors. See abstracts and register >
>> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
>>
>
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
>



------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users
Alessandro Pisa Alessandro Pisa
Reply | Threaded
Open this post in threaded view
|

Re: How to replace a field in a plone.supermodel schema?

On 18 October 2013 09:15, Kees Hink <[hidden email]> wrote:

> For the record, this worked:
>
> from zope.i18nmessageid import MessageFactory
>
> # Set up the i18n message factory for our package
> MessageFactory = MessageFactory('intogreen.contenttypes')
>
> # -*- coding: utf-8 -*-
> from zope.i18nmessageid import MessageFactory
> from plone.app.dexterity.behaviors.metadata import ICategorization
> from plone.autoform.interfaces import WIDGETS_KEY
> from plone.directives.form.schema import TEMP_KEY
> from zope import schema as _schema
>
>
> _ = MessageFactory('collective.z3cform.keywordwidget')
>
> widget = 'collective.z3cform.keywordwidget.widget.KeywordFieldWidget'
> # plone 4.3 not groked form
> _widget_values = ICategorization.queryTaggedValue(WIDGETS_KEY, {})
> _widget_values['subjects'] = widget
> ICategorization.setTaggedValue(WIDGETS_KEY, _widget_values)
>
> _schema.getFields(ICategorization)['subjects'].index_name = 'Subject'
>

Nice suggestion, I am using it :)
I had to add one line to correctly handle unicode characters:

ICategorization['subjects'].__class__ = Keywords

In this way the KeywordsDataConverter is pulled in.
Ciao
--
http://alepisa.blogspot.com
Esalando Prassi

------------------------------------------------------------------------------
_______________________________________________
Plone-Users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/plone-users