Fix model name when the docstring starts with an empty line
review565002
This commit is contained in:
+14
-3
@@ -137,6 +137,17 @@ class Model(WarningErrorMixin, URLMixin):
|
||||
'Duplicate fields on %s: %s, %s'
|
||||
% (cls, field.name, name))
|
||||
|
||||
@classmethod
|
||||
def _get_name(cls):
|
||||
'''
|
||||
Returns the first non-empty line of the model docstring.
|
||||
'''
|
||||
lines= cls.__doc__.splitlines()
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
if line:
|
||||
return line
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
"""
|
||||
@@ -160,7 +171,7 @@ class Model(WarningErrorMixin, URLMixin):
|
||||
if not model_id:
|
||||
cursor.execute("INSERT INTO ir_model "
|
||||
"(model, name, info, module) VALUES (%s, %s, %s, %s)",
|
||||
(cls.__name__, cls.__doc__.splitlines()[0], cls.__doc__,
|
||||
(cls.__name__, cls._get_name(), cls.__doc__,
|
||||
module_name))
|
||||
Property._models_get_cache.clear()
|
||||
cursor.execute("SELECT id FROM ir_model WHERE model = %s",
|
||||
@@ -171,12 +182,12 @@ class Model(WarningErrorMixin, URLMixin):
|
||||
'SET name = %s, '
|
||||
'info = %s '
|
||||
'WHERE id = %s',
|
||||
(cls.__doc__.splitlines()[0], cls.__doc__, model_id))
|
||||
(cls._get_name(), cls.__doc__, model_id))
|
||||
|
||||
# Update translation of model
|
||||
if cls.__doc__:
|
||||
name = cls.__name__ + ',name'
|
||||
src = cls.__doc__.splitlines()[0]
|
||||
src = cls._get_name()
|
||||
cursor.execute('SELECT id FROM ir_translation ' \
|
||||
'WHERE lang = %s ' \
|
||||
'AND type = %s ' \
|
||||
|
||||
@@ -1048,7 +1048,7 @@ class ModelSQL(ModelStorage):
|
||||
rowcount = len(cursor.fetchall())
|
||||
if not rowcount == len({}.fromkeys(sub_ids)):
|
||||
cls.raise_user_error('access_error',
|
||||
cls.__doc__.splitlines()[0])
|
||||
cls._get_name())
|
||||
|
||||
cls.trigger_delete(records)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user