new portal users get the portal menu and groups as defaults
bzr revid: rco@openerp.com-20110328145854-qc20llamomvv46o4
This commit is contained in:
parent
2d49c8d67d
commit
842d5919dd
|
@ -139,6 +139,22 @@ class users(osv.osv):
|
|||
'portal_id': fields.many2one('res.portal', string='Portal',
|
||||
help='If given, the portal defines customized menu and access rules'),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
""" override default values of menu_id and groups_id for portal users """
|
||||
others = {}
|
||||
# How it works: the values of 'menu_id' and 'groups_id' are passed in
|
||||
# context by the portal form view
|
||||
if ('menu_id' in context) and ('menu_id' in fields):
|
||||
fields.remove('menu_id')
|
||||
others['menu_id'] = context['menu_id']
|
||||
if ('groups_id' in context) and ('groups_id' in fields):
|
||||
fields.remove('groups_id')
|
||||
others['groups_id'] = get_many2many(context['groups_id'])
|
||||
# the remaining fields use inherited defaults
|
||||
defs = super(users, self).default_get(cr, uid, fields, context)
|
||||
defs.update(others)
|
||||
return defs
|
||||
|
||||
users()
|
||||
|
||||
|
@ -151,6 +167,11 @@ def get_browse_ids(objs):
|
|||
""" return the ids of a list of browse() objects """
|
||||
return map(get_browse_id, objs)
|
||||
|
||||
def get_many2many(arg):
|
||||
""" get the list of ids from a many2many 'values' field """
|
||||
assert len(arg) == 1 and arg[0][0] == 6 # arg = [(6, _, IDs)]
|
||||
return arg[0][2]
|
||||
|
||||
def copy_random(name):
|
||||
""" return "name [N]" for some random integer N """
|
||||
return "%s [%s]" % (name, random.choice(xrange(1000000)))
|
||||
|
|
|
@ -32,7 +32,8 @@ added to (resp. removed from) the portal's users.
|
|||
<field name="name" colspan="4"/>
|
||||
<field name="menu_id" domain="[('usage','=','menu')]" colspan="2"/>
|
||||
<separator string="Users and groups" colspan="4"/>
|
||||
<field name="user_ids" nolabel="1" colspan="2">
|
||||
<field name="user_ids" nolabel="1" colspan="2"
|
||||
context="{'menu_id': menu_id, 'groups_id': group_ids}">
|
||||
<tree string="Users">
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
|
|
Loading…
Reference in New Issue