The recently introduced `activity` view (see rev. odoo/odoo@1de9496 has not received all the consideration it deserves as a real view type (no RNG, not in the valid view `type`, no doc, etc.). It was currently only working based on a `_get_default_activity_view` method. Even if the RNG is currently really basic, its grammar could evolve in the future. This was causing an issue when opening Studio with this view as a default view with an invalid type was created.
31 lines
752 B
Python
31 lines
752 B
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
import os
|
|
|
|
from lxml import etree
|
|
|
|
from odoo.loglevels import ustr
|
|
from odoo.tools import misc, view_validation
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
_activity_validator = None
|
|
@view_validation.validate('activity')
|
|
def schema_activity(arch):
|
|
""" Check the activity view against its schema
|
|
|
|
:type arch: etree._Element
|
|
"""
|
|
global _activity_validator
|
|
|
|
if _activity_validator is None:
|
|
with misc.file_open(os.path.join('mail', 'views', 'activity.rng')) as f:
|
|
_activity_validator = etree.RelaxNG(etree.parse(f))
|
|
|
|
if _activity_validator.validate(arch):
|
|
return True
|
|
|
|
for error in _activity_validator.error_log:
|
|
_logger.error(ustr(error))
|
|
return False
|