Remove some class instances and move it in the __init__

This make inheritance easier
This commit is contained in:
Cédric Krier committed 2008-03-04 11:49:32 +01:00
1 parent db410a3fc8
commit c66b3c9755
10 files changed
+103 -82

No files matched your search

+7 -4
View File
@@ -171,10 +171,13 @@ class ActionReport(OSV):
fnct_inv='report_content_inv', type='binary',
string='Content')
action = fields.Many2One('ir.action', 'Action', required=True)
_sql_constraints = [
('report_name_uniq', 'unique (report_name)',
'The internal name must be unique!'),
]
def __init__(self):
super(ActionReport, self).__init__()
self._sql_constraints += [
('report_name_uniq', 'unique (report_name)',
'The internal name must be unique!'),
]
def default_type(self, cursor, user, context=None):
return 'ir.action.report'
+8 -5
View File
@@ -22,11 +22,14 @@ class Attachment(OSV):
collision = fields.Integer('Collision')
datas_size = fields.Function('datas', type='integer',
string='Datas size')
_sql_constraints = [
('res_model_res_id_name',
'UNIQUE (res_model, res_id, name)',
'Error! You can not create attachment with the same name!'),
]
def __init__(self):
super(Attachment, self).__init__()
self._sql_constraints += [
('res_model_res_id_name',
'UNIQUE (res_model, res_id, name)',
'Error! You can not create attachment with the same name!'),
]
def default_collision(self, cursor, user, context=None):
return 0
+13 -13
View File
@@ -66,10 +66,13 @@ class ModelAccess(OSV):
perm_create = fields.Boolean('Create Access')
perm_unlink = fields.Boolean('Delete Permission')
description = fields.Text('Description')
_sql_constraints = [
('model_group_uniq', 'UNIQUE("model", "group")',
'Only on record by model and group is allowed!'),
]
def __init__(self):
super(ModelAccess, self).__init__()
self._sql_constraints += [
('model_group_uniq', 'UNIQUE("model", "group")',
'Only on record by model and group is allowed!'),
]
def check(self, cursor, user, model_name, mode='read',
raise_exception=True):
@@ -158,19 +161,16 @@ class ModelData(OSV):
date_update = fields.DateTime('Update Date')
date_init = fields.DateTime('Init Date')
values = fields.Text('Values')
_sql_constraints = [
('fs_id_module_uniq', 'UNIQUE("fs_id", "module")',
'The couple (fs_id, module) must be unique!'),
]
def default_date_init(self, cursor, user, context=None):
return time.strftime('%Y-%m-%d %H:%M:%S')
def __init__(self):
super(ModelData, self).__init__()
self.fs2db = None
self.fs2values = None
self._sql_constraints = [
('fs_id_module_uniq', 'UNIQUE("fs_id", "module")',
'The couple (fs_id, module) must be unique!'),
]
def default_date_init(self, cursor, user, context=None):
return time.strftime('%Y-%m-%d %H:%M:%S')
def get_id(self, cursor, user, module, fs_id):
"""
+7 -4
View File
@@ -149,10 +149,13 @@ class Module(OSV):
('Other proprietary', 'Other proprietary')], string='License',
readonly=True)
_order = 'name'
_sql_constraints = [
('name_uniq', 'unique (name)',
'The name of the module must be unique!'),
]
def __init__(self):
super(Module, self).__init__()
self._sql_constraints = [
('name_uniq', 'unique (name)',
'The name of the module must be unique!'),
]
def default_state(self, cursor, user, context=None):
return 'uninstalled'
+7 -4
View File
@@ -40,15 +40,18 @@ class Translation(OSV, Cacheable):
fuzzy = fields.Boolean('Fuzzy')
model = fields.Function('get_model', fnct_search='model_search',
type='char', string='Model')
_sql_constraints = [
('translation_uniq', 'UNIQUE (name, res_id, lang, type, src)',
'Translation must be unique'),
]
_sql = """
CREATE INDEX ir_translation_ltn ON ir_translation (lang, type, name);
CREATE INDEX ir_translation_res_id ON ir_translation (res_id);
"""
def __init__(self):
super(Translation, self).__init__()
self._sql_constraints += [
('translation_uniq', 'UNIQUE (name, res_id, lang, type, src)',
'Translation must be unique'),
]
def default_fuzzy(self, cursor, user, context=None):
return 0
+6 -3
View File
@@ -21,9 +21,12 @@ class View(OSV):
field_childs = fields.Char('Childs Field',size=64)
module = fields.Char('Module', size=128, readonly=True)
_order = "priority"
_constraints = [
('check_xml', 'Invalid XML for View Architecture!', ['arch'])
]
def __init__(self):
super(View, self).__init__()
self._constraints += [
('check_xml', 'Invalid XML for View Architecture!', ['arch'])
]
def default_arch(self, cursor, user, context=None):
return '<?xml version="1.0"?>\n' \
+6 -6
View File
@@ -235,8 +235,6 @@ class ORM(object):
- relations (one2many, many2one, many2many)
- functions
"""
_sql_constraints = []
_constraints = []
_log_access = True
_table = None
_name = None
@@ -244,13 +242,12 @@ class ORM(object):
_parent_name = 'parent'
_date_name = 'date'
_order = 'id'
_inherits = {}
_inherits = {} #XXX remove from class instance
_sequence = None
_description = ''
_auto = True
_obj = None
_sql = ''
_inherit_fields = []
pool = None
__columns = None
__defaults = None
@@ -769,10 +766,13 @@ class ORM(object):
'import_data',
'search_count',
]
# reinit the cachel on _columns and _defaults
self._sql_constraints = []
self._constraints = []
self._inherit_fields = []
# reinit the cache on _columns and _defaults
self.__columns = None
self.__defaults = None
if not self._table:
self._table = self._name.replace('.', '_')
if not self._description:
+6 -3
View File
@@ -14,9 +14,12 @@ class Group(OSV):
domain="[('global', '<>', True)]")
menu_access = fields.Many2Many('ir.ui.menu', 'ir_ui_menu_group_rel',
'gid', 'menu_id', 'Access Menu')
_sql_constraints = [
('name_uniq', 'unique (name)', 'The name of the group must be unique!')
]
def __init__(self):
super(Group, self).__init__()
self._sql_constraints += [
('name_uniq', 'unique (name)', 'The name of the group must be unique!')
]
def write(self, cursor, user, ids, vals, context=None):
res = super(Group, self).write(cursor, user, ids, vals,
+24 -24
View File
@@ -27,22 +27,30 @@ class User(OSV):
domain="[('global', '<>', True)]")
language = fields.Selection('languages', 'Language')
timezone = fields.Selection('timezones', 'Timezone')
_sql_constraints = [
('login_key', 'UNIQUE (login)',
'You can not have two users with the same login!')
]
_preferences_fields = [
'name',
'password',
'signature',
'menu',
'action',
]
_context_fields = [
'language',
'timezone',
'groups',
]
def __init__(self):
super(User, self).__init__()
self._rpc_allowed += [
'get_preferences',
'set_preferences',
'get_preferences_fields_view',
]
self._sql_constraints = [
('login_key', 'UNIQUE (login)',
'You can not have two users with the same login!')
]
self._preferences_fields = [
'name',
'password',
'signature',
'menu',
'action',
]
self._context_fields = [
'language',
'timezone',
'groups',
]
def default_password(self, cursor, user, context=None):
return ''
@@ -68,14 +76,6 @@ class User(OSV):
def default_action(self, cursor, user, context=None):
return self.default_menu(cursor, user, context=context)
def __init__(self):
super(User, self).__init__()
self._rpc_allowed += [
'get_preferences',
'set_preferences',
'get_preferences_fields_view',
]
def _convert_vals(self, cursor, user, vals, context=None):
vals = vals.copy()
action_obj = self.pool.get('ir.action')
+19 -16
View File
@@ -16,22 +16,25 @@ class Directory(OSV):
childs = fields.One2Many('webdav.directory', 'parent', 'Childs')
model = fields.Many2One('ir.model', 'Model')
domain = fields.Char('Domain', size=250)
_sql_constraints = [
('name_parent_uniq', 'UNIQUE (name, parent)',
'The directory name must be unique inside a directory!'),
]
_parent_name = 'parent'
_constraints = [
('check_recursion',
'Error! You can not create recursive directories.', ['parent']),
('check_attachment',
'Error! You can not create a directory \n' \
'with the same name of an existing file \n' \
'inside the same directory.', ['name']),
]
ext2mime = {
'.png': 'image/png',
}
def __init__(self):
super(Directory, self).__init__()
self._sql_constraints += [
('name_parent_uniq', 'UNIQUE (name, parent)',
'The directory name must be unique inside a directory!'),
]
self._constraints += [
('check_recursion',
'Error! You can not create recursive directories.', ['parent']),
('check_attachment',
'Error! You can not create a directory \n' \
'with the same name of an existing file \n' \
'inside the same directory.', ['name']),
]
self.ext2mime = {
'.png': 'image/png',
}
def default_domain(self, cursor, user, context=None):
return '[]'
@@ -299,7 +302,7 @@ class Attachment(OSV):
def __init__(self):
super(Attachment, self).__init__()
self._constraints = self._constraints + [
self._constraints += [
('check_directory',
'Error! You can not create a attachment \n' \
'on a directory that have the same name \n' \