Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8326307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:43:09+00:00 2026-06-09T00:43:09+00:00

I have a Dexterity content type based on plone.directives.form.Schema which has a number of

  • 0

I have a Dexterity content type based on plone.directives.form.Schema which has a number of form hints for assigning defaults:

@form.default_value(field=ITrial['start_on'])
def default_start_on(data):
    return datetime.now()

Some of the defaults are more complex, passing back objects that are themselves instances of Dexterity types. These objects are essential for the main type’s setup, which is triggered by various events.

I’m now in the process of testing. Ideally, I’d like to be able to use something like:

item = createContentInContainer(folder, 'ctcc.model.trial', 'item')

That is, I’d like the defaults to be picked up by the item without having to be manually passed into the constructor.

If I was using zope.schema I could use FieldProperty to set up proxies to the schema fields. Is there something equivalent for Dexterity, or perhaps a function for pushing an object through form creation?

Solution: I ended up going with David’s option #1, intercepting ObjectCreatedEvent.

@grok.subscribe(ITrial, IObjectCreatedEvent)
def create_trial(trial, event):            
    if getattr(trial, 'start_on', None) is None:
        trial.start_on = default_start_on(None)

It stills feels like I’m replicating part of form behaviour, but at least it’s using the same functions that are providing the form defaults.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:43:11+00:00Added an answer on June 9, 2026 at 12:43 am

    As you’ve discovered, the @form.default_value decorator is respected by z3c.form forms, but not when items are created in other ways. You have several options:

    1. Write a handler for the ObjectCreatedEvent for your content type which sets up the necessary default values. This is the simplest approach to implement, but may not work if there are other handlers of this event that need the values in place.

    2. Create your own subclass of Dexterity’s generic Item class, and use it instead of Item as the basis for your content type. Then you can customize the __init__ method to set whatever you want. This would require migration of existing content items though, if you already have some.

    3. This is a more complicated option. Replace the factory utility used to construct the content type. createContentInContainer ends up looking for an IFactory utility with a name equal to the factory attribute of the content type’s FTI. The default implementation is in plone.dexterity.factory but you could replace it with a different one that does more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a site running Plone 4.1 which has a custom content type developed
I have a custom folderish Dexterity content-type in Plone. It can have only Documents
I have a Dexterity-based content type with the IRelatedItems behavior enabled using: <property name=behaviors>
We have a requirement for a dexterity content type to have exclude from navigation
I am writing a Dexterity content type which contains plain text and HTML fields.
I have two Dexterity content types - Participant & Criterion - the latter of
Have a simple one-off tasks which needs a progress bar. OpenSSL has a useful
I have lots of Dexterity content types, some of them are just containers and
I have a Plone (4.2) form that is grokked. I want to have a
I have created two Dexterity types: lab_equipment.py, class_activity.py. The class_activity type contains the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.