constrain portal name to be unique, and override method copy()
bzr revid: rco@openerp.com-20110325144227-08wwe4mq1wn2195p
This commit is contained in:
parent
3a791662fe
commit
160c47f80b
|
@ -20,6 +20,7 @@
|
|||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
import random
|
||||
|
||||
class portal(osv.osv):
|
||||
_name = 'res.portal'
|
||||
|
@ -36,6 +37,21 @@ class portal(osv.osv):
|
|||
string='Groups',
|
||||
help='Users of this portal automatically belong to those groups'),
|
||||
}
|
||||
_sql_constraints = [
|
||||
('unique_name', 'UNIQUE(name)', 'Portals must have different names.')
|
||||
]
|
||||
|
||||
def copy(self, cr, uid, id, defaults, context=None):
|
||||
""" override copy() to not copy the portal users """
|
||||
# find an unused name of the form "old_name [N]" for some random N
|
||||
old_name = self.browse(cr, uid, id, context).name
|
||||
new_name = copy_random(old_name)
|
||||
while self.search(cr, uid, [('name', '=', new_name)], limit=1, context=context):
|
||||
new_name = copy_random(old_name)
|
||||
|
||||
defaults['name'] = new_name
|
||||
defaults['user_ids'] = []
|
||||
return super(portal, self).copy(cr, uid, id, defaults, context)
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
""" extend create() to assign the portal menu and groups to users """
|
||||
|
@ -94,3 +110,7 @@ def get_browse_ids(objs):
|
|||
""" return the ids of a list of browse() objects """
|
||||
return [(obj and obj.id or default) for obj in objs]
|
||||
|
||||
def copy_random(name):
|
||||
""" return "name [N]" for some random integer N """
|
||||
return "%s [%s]" % (name, random.choice(xrange(1000000)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue