add portal widgets; they are automatically assigned to users
bzr revid: rco@openerp.com-20110406102534-lutdafmi2vq6uqj1
This commit is contained in:
parent
f138d76a03
commit
5b75e199db
|
@ -39,6 +39,9 @@ class portal(osv.osv):
|
|||
'parent_menu_id': fields.many2one('ir.ui.menu',
|
||||
string='Parent Menu',
|
||||
help=_('The menu action opens the submenus of this menu item')),
|
||||
'widget_ids': fields.one2many('res.portal.widget', 'portal_id',
|
||||
string='Widgets',
|
||||
help=_('Widgets assigned to portal users')),
|
||||
}
|
||||
_sql_constraints = [
|
||||
('unique_group', 'UNIQUE(group_id)', _('Portals must have distinct groups.'))
|
||||
|
@ -66,7 +69,14 @@ class portal(osv.osv):
|
|||
for id in get_many2many(values['user_ids']):
|
||||
values['user_ids'].append((1, id, user_values))
|
||||
|
||||
return super(portal, self).create(cr, uid, values, context)
|
||||
# create portal
|
||||
portal_id = super(portal, self).create(cr, uid, values, context)
|
||||
|
||||
# assign widgets to users
|
||||
if 'user_ids' in values:
|
||||
self._assign_widgets_to_users(cr, uid, portal_id, context)
|
||||
|
||||
return portal_id
|
||||
|
||||
def name_get(self, cr, uid, ids, context=None):
|
||||
portals = self.browse(cr, uid, ids, context)
|
||||
|
@ -90,7 +100,7 @@ class portal(osv.osv):
|
|||
# if 'menu_action_id' has changed, set menu_id on users
|
||||
if 'menu_action_id' in values:
|
||||
user_values = {'menu_id': values['menu_action_id']}
|
||||
user_ids = [u.id for p in portals for u in p.user_ids]
|
||||
user_ids = [u.id for p in portals for u in p.user_ids if u.id != 1]
|
||||
self.pool.get('res.users').write(cr, uid, user_ids, user_values, context)
|
||||
|
||||
# if parent_menu_id has changed, apply the change on menu_action_id
|
||||
|
@ -100,6 +110,10 @@ class portal(osv.osv):
|
|||
action_values = {'domain': [('parent_id', '=', values['parent_menu_id'])]}
|
||||
act_window_obj.write(cr, uid, action_ids, action_values, context)
|
||||
|
||||
# assign portal widgets to users, if widgets or users changed
|
||||
if ('user_ids' in values) or ('widget_ids' in values):
|
||||
self._assign_widgets_to_users(cr, uid, ids, context)
|
||||
|
||||
return True
|
||||
|
||||
def _create_menu_action(self, cr, uid, values, context=None):
|
||||
|
@ -135,7 +149,19 @@ class portal(osv.osv):
|
|||
self.write(cr, uid, [p.id], {'parent_menu_id': menu_id}, context)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _assign_widgets_to_users(self, cr, uid, ids, context=None):
|
||||
""" assign portal widgets to users for the given portal ids """
|
||||
widget_user_obj = self.pool.get('res.widget.user')
|
||||
portals = self.browse(cr, uid, ids, context)
|
||||
for p in portals:
|
||||
for w in p.widget_ids:
|
||||
values = {'sequence': w.sequence, 'widget_id': w.widget_id.id}
|
||||
for u in p.user_ids:
|
||||
if u.id == 1: continue
|
||||
values['user_id'] = u.id
|
||||
widget_user_obj.create(cr, uid, values, context)
|
||||
|
||||
def onchange_group(self, cr, uid, ids, group_id, context=None):
|
||||
""" update the users list when the group changes """
|
||||
user_ids = False
|
||||
|
@ -174,6 +200,36 @@ users()
|
|||
|
||||
|
||||
|
||||
class portal_widget(osv.osv):
|
||||
"""
|
||||
Similar to res.widget.user (res_widget.py), but with a portal instead.
|
||||
New users in a portal are assigned the portal's widgets.
|
||||
"""
|
||||
_name='res.portal.widget'
|
||||
_description = 'Portal Widgets'
|
||||
_order = 'sequence'
|
||||
_columns = {
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'portal_id': fields.many2one('res.portal', select=1,
|
||||
string='Portal'),
|
||||
'widget_id': fields.many2one('res.widget', required=True, ondelete='cascade',
|
||||
string='Widget'),
|
||||
}
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
domain = [('portal_id', '=', values.get('portal_id')),
|
||||
('widget_id', '=', values.get('widget_id'))]
|
||||
existing = self.search(cr, uid, domain, context=context)
|
||||
if existing:
|
||||
res = existing[0]
|
||||
else:
|
||||
res = super(portal_widget, self).create(cr, uid, values, context=context)
|
||||
return res
|
||||
|
||||
portal_widget()
|
||||
|
||||
|
||||
|
||||
# utils
|
||||
def get_browse_id(obj):
|
||||
""" return the id of a browse() object, or None """
|
||||
|
|
|
@ -36,13 +36,26 @@ portal's users.
|
|||
<group name="user_panel" colspan="1"/>
|
||||
<!-- wizards insert buttons inside the group 'user_panel' -->
|
||||
</page>
|
||||
<page string="Menu">
|
||||
<field name="menu_action_id"/>
|
||||
<newline/>
|
||||
<field name="parent_menu_id"
|
||||
context="{'ir.ui.menu.full_list': True}"/>
|
||||
<button name="do_create_menu" type="object"
|
||||
string="Create Parent Menu"/>
|
||||
<page string="Menu & Widgets">
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Portal Menu" colspan="2"/>
|
||||
<group colspan="2" col="2">
|
||||
<field name="menu_action_id"/>
|
||||
<field name="parent_menu_id"
|
||||
context="{'ir.ui.menu.full_list': True}"/>
|
||||
</group>
|
||||
<button name="do_create_menu" type="object"
|
||||
string="Create Parent Menu"/>
|
||||
</group>
|
||||
<group colspan="2" col="2">
|
||||
<separator string="Portal Widgets" colspan="2"/>
|
||||
<field name="widget_ids" nolabel="1" rowspan="7">
|
||||
<tree string="Widgets" editable="bottom">
|
||||
<field name="sequence"/>
|
||||
<field name="widget_id"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue