问题
So I have a form (just getting the example from plone.directives.form):
from plone.directives import form
from zope import schema
class IMySchema(form.Schema):
title = schema.TextLine(title=u"Title")
@form.default_value(field=IMySchema['title'])
def default_title(data):
return data.context.suggested_title
Which works fine only for add forms.
So the question is: how can I make this same method be also used on an edit form? I do not generate the edit form by myself if that's relevant to the matter.
Edit: I forgot something that it's quite relevant: the value entered in the field is stored elsewhere, and that already works thanks to an event handler, so that's why I need to be able to provide always a default value (the current value extracted from that place where is stored) and allow the user (a system administrator) to change that value, but mostly to lookup it (i.e. what value has that field).
The use case here is letting system administrator see the email field of members. The email is saved in portal_membership, but we augmented the regular member edit profile to allow only system administrators to see their email and be able to change it.
来源:https://stackoverflow.com/questions/11138524/provide-a-default-value-on-a-field-also-on-edit-form