Skip to main content

Customizable personalize form for Plone

Project description

Introduction

This package was created after encountering a problem with the plone.app.users.userdataschema.IUserDataSchemaProvider utilty override. As this utility is unnamed, you can override it only once in all packages. We had to add extra fields on our personal-information form from various packages, so this package was created with the idea of managing multiple sources overrides of the personal-information form and properties.

This eggs allows to override as many times as you want the personal preferences of your users by adding extra fields by using adapters. By adding extra fields, you can specify your own getters & setters if you don’t want your field to be manage as a user property. You’ll also be able to add comptabile widgets for the personal preferences’ form fields.

The docs directory contains all necessary steps about server configuration before to install this egg. These documents can be distributed separately under the specified license in each of them.

These package was initiated by Quadra Informatique <plone@quadra-informatique.fr>.

How-to

There are three interfaces you need to know:

collective.customizablePersonalizeForm.adapters.interfaces.IExtendedUserDataSchema(Interface):

def getSchema(self,):

collective.customizablePersonalizeForm.adapters.interfaces.IExtendedUserDataPanel(Interface):

def getProperties(self,):

collective.customizablePersonalizeForm.adapters.interfaces.IExtendedUserDataWidgets(Interface):

def getWidgets(self,):

An adapter providing the IExtendedUserDataSchema allows to add additional fields by returning an Interface through its getSchema method.

Carefull ! If you ever add a field on your form, you’ll also need to declare a property with the same name as your field, allowing you to get and set your property. That’s why we use IExtendedUserDataPanel. An adapter providing this interface will return a list of strings through the getProperties method. These strings are the names of the fields provided by your custom interface, like ‘portrait’ or ‘fullname’. By default the getters and setters of your fields will use Plone’s member.getProperty and member.setProperty methods, using the memberdata to store the values. If you ever need to use your own getters and setters, you can return a dict instead of the name of your field, using this format:

{‘name’ : ‘your_field_name’, ‘getter’: your_own_getter_method, ‘setter’: your_own_setter_method}

Simple Override Example

A simple interface providing our field:

class ITestAdditionalDataSchema(Interface):

test_field = schema.Bool(

title=_(u’label_test_field_title’, default=u’Test field’), description=_(u’label_test_field_description’, default=u’’), required=False, )

A simple adapter that adapts the context and request, returning our interface

class TestSchemaAdapter(object):

adapts(object, IBrowserRequest) implements(IExtendedUserDataSchema)

def __init__(self, context, request):

self.context = context self.request = request

def getSchema(self):

return ITestAdditionalDataSchema

Now we create an adapter that will declare a ‘test_field’ property, we didn’t specify a getter and setter so this property will act as a memberdata property (be sure to declare it via memberdata_properties.xml)

class TestPropertiesAdapter(object):

adapts(object, IBrowserRequest) implements(IExtendedUserDataPanel)

def __init__(self, context, request):

self.context = context self.request = request

def getProperties(self):

return [‘test_field’]

Let’s susbscribe to the collective.customizablePersonalizeForm’s interfaces to provide the personal-information form with our field

<adapter factory=”.adapters.TestSchemaAdapter”

name=”test.ExtraField”/>

<adapter factory=”.adapters.TestPropertiesAdapter”

name=”test.ExtraProperties”/>

Congratulations, a simple boolean field named ‘test_field’ should now be displayed in your form.

Custom Widgets

You may want to use a widget for your field. It can be done through the IExtendedUserDataWidgets interface. All you have to do is mapping a field id with a valid custom_widget factory like the following example.

class TestWidgetAdapter(object):

adapts(object, IBrowserRequest) implements(IExtendedUserDataWidgets)

def __init__(self, context, request):

self.context = context self.request = request

def getWidgets(self):
return [{‘field’: ‘test_field’, ‘factory’CheckBoxWidget},

]

<adapter factory=”.adapters.TestWidgetAdapter”

name=”test.ExtraWidgets”/>

Your test_field will now use the widget factory you declared in the getWidgets method. You can also override the default Plone fields widgets using this method if you ever need to.

Changelog

2.0 (2011-09-07)

  • Now working for Plone 4.x [jstegle]

  • Added 3 interfaces for subscription, provider schema, properties and widgets overrides [jstegle]

  • Overrides the default personal-information to manage widget customization [jstegle]

  • Overrides the default IUserDataSchemaProvider [jstegle]

  • Overrides the account-macro view to manage FileUpload fields that handles pictures [jstegle]

  • Added isImage constraint on the portrait field, allowing only images to be uploaded [jstegle]

  • Added tests and examples [jstegle]

1.0.1 (2011-05-04)

  • Added documentation [jstegle]

1.0 (2011-04-XX)

  • Added viewletmanager for the personalize_form [jstegle]

  • Added adaptor interfaces for validators and actions [jstegle]

  • Added self personalize_form, validation and action scripts [jstegle]

  • Works for Plone 3.x [jstegle]

Project details


Release history Release notifications | RSS feed

This version

2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

File details

Details for the file collective.customizablePersonalizeForm-2.0.tar.gz.

File metadata

File hashes

Hashes for collective.customizablePersonalizeForm-2.0.tar.gz
Algorithm Hash digest
SHA256 4f89082e248cbd779073be4b6db05c3dc9810e3c459b1659d2cfcc7e86cdf1cb
MD5 d3f09ac5d5bea684e2d2b21aaa992787
BLAKE2b-256 b0e87e30b637e0e92c5d3d40d814a41a96d195c3a6559efd6ac28b01d2e974da

See more details on using hashes here.

File details

Details for the file collective.customizablePersonalizeForm-2.0-py2.6.egg.

File metadata

File hashes

Hashes for collective.customizablePersonalizeForm-2.0-py2.6.egg
Algorithm Hash digest
SHA256 41d04687afcc79e62cb86f9b8ef2f9a7718e6f6db24db8359316f443e1938703
MD5 1e27f417fb893fc11fb9b0e167b1b9e3
BLAKE2b-256 fbd84434316e4b494df715e0907233d9c29c988c3076f1c7c4fc3c2ea487d0f0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page