get field value from the actual local roles (#4492)

This commit is contained in:
Frédéric Péters 2014-03-18 13:31:52 +01:00
parent dc2ae2555f
commit 10b2aab7ac
1 changed files with 14 additions and 0 deletions

View File

@ -57,6 +57,20 @@ class LocalRolesToPrincipalsDataManager(AttributeField):
"""A data manager which set local roles when saving the field."""
adapts(Interface, ILocalRolesToPrincipals)
def get(self):
# get value from the actual local roles, in case it has been modified
# by an external process
roles_to_assign = frozenset(self.field.roles_to_assign)
value = []
for local_role in self.context.get_local_roles():
# a local_role is like ('Administrators', (u'Contributor', u'Reviewer'))
principal = local_role[0]
local_roles = frozenset(local_role[1])
if roles_to_assign.issubset(local_roles):
value.append(principal)
return value
def set(self, value):
"""See z3c.form.interfaces.IDataManager"""
# set local roles before setting the value so we still have access to the old value