Is it possitble to set 'default user' in XML for a choice field?
I want the default value to be 'current user'
<field name="select_user" type="zope.schema.Choice">
<vocabulary>plone.app.vocabularies.Users</vocabulary>
</field>
Is it possitble to set 'default user' in XML for a choice field?
I want the default value to be 'current user'
<field name="select_user" type="zope.schema.Choice">
<vocabulary>plone.app.vocabularies.Users</vocabulary>
</field>
What happens when you insert a <defaultFactory>mypackage.myFunction</defaultFactory>
element
with the dotted name of your custom value provider as the parameter?
See Dexterity XML — Plone Documentation v4.3 - this should still work...
Should probably work (but I need to figure out 'what is expected for default ' (user id or something else).
That said: I assume there must be something avalable already (isnt this used 'many other places' ?
UPDATE:
Something like this should work (I think using something else than plone.api is faster, and the check for 'Authenticated' feels a bit strage (done to avoid errors with zope users). Probably dont need to be 'ContextAware' either.
<defaultFactory>my.addon.current_user.getUserId</defaultFactory>
from zope.interface import provider
from zope.schema.interfaces import IContextAwareDefaultFactory
from plone import api
#@provider(IDefaultFactory)
@provider(IContextAwareDefaultFactory)
def getUserId(context):
current_user = api.user.get_current()
user_groups = current_user.getGroups()
if 'AuthenticatedUsers' in user_groups:
return current_user.id
return None