mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
fix bg color
This commit is contained in:
@@ -23,8 +23,6 @@
|
||||
# description:
|
||||
|
||||
from . import base
|
||||
from . import fields
|
||||
from . import view_validation
|
||||
from . import ir_ui_view
|
||||
from . import ir_cron
|
||||
from . import res_users
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo.fields import Field, resolve_mro
|
||||
from odoo.fields import Selection as oldSelection
|
||||
from odoo.tools import merge_sequences
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
# 此处用猴子补丁,热更新,不影响后续继承
|
||||
class Selection(Field):
|
||||
def _setup_attrs_app(self, model, name):
|
||||
Field._setup_attrs(self, model, name)
|
||||
|
||||
# determine selection (applying 'selection_add' extensions)
|
||||
values = None
|
||||
labels = {}
|
||||
|
||||
for field in reversed(resolve_mro(model, name, self._can_setup_from)):
|
||||
# We cannot use field.selection or field.selection_add here
|
||||
# because those attributes are overridden by ``_setup_attrs``.
|
||||
if 'selection' in field.args:
|
||||
selection = field.args['selection']
|
||||
if isinstance(selection, list):
|
||||
if (
|
||||
values is not None
|
||||
and values != [kv[0] for kv in selection]
|
||||
):
|
||||
_logger.debug("%s: selection=%r overrides existing selection; use selection_add instead", self, selection)
|
||||
values = [kv[0] for kv in selection]
|
||||
labels = dict(selection)
|
||||
else:
|
||||
self.selection = selection
|
||||
values = None
|
||||
labels = {}
|
||||
|
||||
if 'selection_add' in field.args:
|
||||
selection_add = field.args['selection_add']
|
||||
assert isinstance(selection_add, list), \
|
||||
"%s: selection_add=%r must be a list" % (self, selection_add)
|
||||
assert values is not None, \
|
||||
"%s: selection_add=%r on non-list selection %r" % (self, selection_add, self.selection)
|
||||
values = merge_sequences(values, [kv[0] for kv in selection_add])
|
||||
labels.update(kv for kv in selection_add if len(kv) == 2)
|
||||
|
||||
if values is not None:
|
||||
self.selection = [(value, labels[value]) for value in values]
|
||||
|
||||
oldSelection._setup_attrs = Selection._setup_attrs_app
|
||||
@@ -10,14 +10,6 @@ from lxml import etree
|
||||
import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@validate('tree')
|
||||
def app_valid_field_in_tree(arch, **kwargs):
|
||||
# 增加 header
|
||||
return all(
|
||||
child.tag in ('field', 'button', 'control', 'groupby', 'header')
|
||||
for child in arch.xpath('/tree/*')
|
||||
)
|
||||
|
||||
def app_relaxng(view_type):
|
||||
""" Return a validator for the given view type, or None. """
|
||||
if view_type not in _relaxng_cache:
|
||||
@@ -35,21 +27,6 @@ def app_relaxng(view_type):
|
||||
_relaxng_cache[view_type] = None
|
||||
return _relaxng_cache[view_type]
|
||||
|
||||
def app_reset_valid_view(view_type):
|
||||
_relaxng_cache = view_validation._relaxng_cache
|
||||
for pred in _validators[view_type]:
|
||||
# 要pop掉函数 valid_field_in_tree
|
||||
if pred.__name__ == 'valid_field_in_tree':
|
||||
_validators[view_type].remove(pred)
|
||||
try:
|
||||
_relaxng_cache.pop(view_type, None)
|
||||
_relaxng_cache[view_type] = None
|
||||
except Exception:
|
||||
pass
|
||||
_relaxng_cache[view_type] = app_relaxng(view_type)
|
||||
|
||||
app_reset_valid_view('tree')
|
||||
view_validation.valid_field_in_tree = app_valid_field_in_tree
|
||||
view_validation.relaxng = app_relaxng
|
||||
|
||||
class View(models.Model):
|
||||
@@ -58,8 +35,6 @@ class View(models.Model):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(View, self).__init__(*args, **kwargs)
|
||||
view_validation.relaxng = app_relaxng
|
||||
# 重置 tree
|
||||
app_reset_valid_view('tree')
|
||||
|
||||
# todo: 有可能需要处理增加的 header等标签
|
||||
# 直接重写原生方法
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from odoo import tools, _
|
||||
from odoo.modules.module import get_resource_path
|
||||
from odoo.tools import view_validation
|
||||
from odoo.tools.view_validation import validate, _validators
|
||||
from lxml import etree
|
||||
import logging
|
||||
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
_relaxng_cache = view_validation._relaxng_cache
|
||||
_relaxng_cache['tree'] = None
|
||||
with tools.file_open(get_resource_path('app_common', 'rng', 'tree_view.rng')) as frng:
|
||||
try:
|
||||
text = frng.read()
|
||||
# with tools.file_open('addons/base/rng/common.rng') as common_rng:
|
||||
# common_txt = common_rng.read()
|
||||
# start_pos = common_txt.find('<rng:grammar')
|
||||
# start_pos = common_txt.find('>', start_pos)
|
||||
# end_pos = common_txt.find('</rng:grammar>')
|
||||
# common_content = common_txt[start_pos + 1: end_pos]
|
||||
#
|
||||
# # 从14中学习,最新 common
|
||||
# # <rng:optional><rng:attribute name="kanban_view_ref" />
|
||||
# old_content = '''
|
||||
# <rng:optional><rng:attribute name="kanban_view_ref" /></rng:optional>
|
||||
# '''
|
||||
# new_content = '''
|
||||
# <rng:optional><rng:attribute name="hierarchize"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="expand"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="enable_counters"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="limit"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="decoration-bf"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="decoration-it"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="decoration-danger"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="decoration-info"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="decoration-muted"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="decoration-primary"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="decoration-success"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="decoration-warning"/></rng:optional>
|
||||
# <rng:optional><rng:attribute name="kanban_view_ref" /></rng:optional>
|
||||
# '''
|
||||
# common_content = common_content.replace(old_content, new_content)
|
||||
# # common 替代
|
||||
# text = text.replace('<rng:include href=\"common.rng\"/>', common_content)
|
||||
# # tree 替代
|
||||
# old_content = '''<rng:ref name="control"/>'''
|
||||
# new_content = '''<rng:element name="header">
|
||||
# <rng:zeroOrMore>
|
||||
# <rng:ref name="button"/>
|
||||
# </rng:zeroOrMore>
|
||||
# </rng:element>
|
||||
# <rng:ref name="control"/>'''
|
||||
# text = text.replace(old_content, new_content)
|
||||
# # 增加 fx_tree_table 支持
|
||||
# text = text.replace('<rng:optional><rng:attribute name=\"js_class\"/></rng:optional>',
|
||||
# '<rng:optional><rng:attribute name=\"js_class\"/></rng:optional><rng:optional><rng:attribute name=\"options\"/></rng:optional>')
|
||||
|
||||
tmp_doc = etree.fromstring(text.encode('utf-8'))
|
||||
_relaxng_cache['tree'] = etree.RelaxNG(tmp_doc)
|
||||
_logger.warning('=========new tree done: %s' % _relaxng_cache['tree'])
|
||||
except Exception as error:
|
||||
_logger.exception('Failed to load RelaxNG XML schema for views validation, {error}'.format(
|
||||
error=error))
|
||||
_relaxng_cache['tree'] = None
|
||||
|
||||
|
||||
@validate('tree')
|
||||
def app_valid_field_in_tree(arch, **kwargs):
|
||||
# 增加 header
|
||||
return all(
|
||||
child.tag in ('field', 'button', 'control', 'groupby', 'header')
|
||||
for child in arch.xpath('/tree/*')
|
||||
)
|
||||
|
||||
view_validation.valid_field_in_tree = app_valid_field_in_tree
|
||||
@@ -1,63 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import ast
|
||||
from odoo.tools import view_validation
|
||||
from odoo.tools.view_validation import get_attrs_field_names as old_gafn
|
||||
from odoo.tools.view_validation import _get_attrs_symbols
|
||||
import logging
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
ATTRS_WITH_FIELD_NAMES2 = {
|
||||
'context',
|
||||
'domain',
|
||||
'decoration-bf',
|
||||
'decoration-it',
|
||||
'decoration-danger',
|
||||
'decoration-info',
|
||||
'decoration-muted',
|
||||
'decoration-primary',
|
||||
'decoration-success',
|
||||
'decoration-warning',
|
||||
'decoration-black',
|
||||
'decoration-white',
|
||||
'bg-danger',
|
||||
'bg-info',
|
||||
'bg-muted',
|
||||
'bg-primary',
|
||||
'bg-success',
|
||||
'bg-warning',
|
||||
'bg-black',
|
||||
'bg-white',
|
||||
}
|
||||
|
||||
def app_get_attrs_field_names(env, arch, model, editable):
|
||||
symbols = _get_attrs_symbols() | {None}
|
||||
result = []
|
||||
|
||||
def get_name(node):
|
||||
""" return the name from an AST node, or None """
|
||||
if isinstance(node, ast.Name):
|
||||
return node.id
|
||||
|
||||
def process_expr(expr, get, key, val):
|
||||
""" parse `expr` and collect triples """
|
||||
for node in ast.walk(ast.parse(expr.strip(), mode='eval')):
|
||||
name = get(node)
|
||||
if name not in symbols:
|
||||
result.append((name, key, val))
|
||||
|
||||
def add_bg(node, model, editable, get=get_name):
|
||||
for key, val in node.items():
|
||||
if not val:
|
||||
continue
|
||||
if key in ATTRS_WITH_FIELD_NAMES2:
|
||||
process_expr(val, get, key, val)
|
||||
|
||||
res = old_gafn(env, arch, model, editable)
|
||||
add_bg(arch, model, editable)
|
||||
res += result
|
||||
return res
|
||||
|
||||
# 使用猴子补丁方式更新
|
||||
view_validation.get_attrs_field_names = app_get_attrs_field_names
|
||||
@@ -268,7 +268,6 @@
|
||||
<rng:optional><rng:attribute name="write_field" /></rng:optional>
|
||||
<rng:optional><rng:attribute name="text" /></rng:optional>
|
||||
<rng:optional><rng:attribute name="optional" /></rng:optional>
|
||||
<rng:optional><rng:attribute name="kanban_view_ref" /></rng:optional>
|
||||
<rng:optional><rng:attribute name="decoration-bf"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="decoration-it"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="decoration-danger"/></rng:optional>
|
||||
@@ -287,6 +286,7 @@
|
||||
<rng:optional><rng:attribute name="bg-warning"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="bg-black"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="bg-white"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="kanban_view_ref" /></rng:optional>
|
||||
<rng:optional>
|
||||
<rng:attribute name="force_save">
|
||||
<rng:choice>
|
||||
@@ -348,6 +348,7 @@
|
||||
<rng:ref name="modifiable"/>
|
||||
<rng:optional><rng:attribute name="attrs"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="invisible"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="disabled"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="name" /></rng:optional>
|
||||
<rng:optional><rng:attribute name="icon" /></rng:optional>
|
||||
<rng:optional><rng:attribute name="string" /></rng:optional>
|
||||
@@ -421,7 +422,6 @@
|
||||
<rng:define name="create">
|
||||
<rng:element name="create">
|
||||
<rng:ref name="overload"/>
|
||||
<rng:ref name="access_rights"/>
|
||||
<rng:attribute name="string"/>
|
||||
<rng:attribute name="context"/>
|
||||
<rng:ref name="modifiable"/>
|
||||
|
||||
@@ -19,18 +19,6 @@
|
||||
</rng:element>
|
||||
</rng:define>
|
||||
|
||||
<rng:define name="superbar">
|
||||
<rng:element name="superbar">
|
||||
<rng:ref name="overload"/>
|
||||
<rng:optional><rng:attribute name="view_types"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="class"/></rng:optional>
|
||||
<rng:optional><rng:attribute name="options"/></rng:optional>
|
||||
<rng:zeroOrMore>
|
||||
<rng:ref name="field" />
|
||||
</rng:zeroOrMore>
|
||||
</rng:element>
|
||||
</rng:define>
|
||||
|
||||
<rng:define name="search">
|
||||
<rng:element name="search">
|
||||
<rng:ref name="overload"/>
|
||||
@@ -44,7 +32,6 @@
|
||||
<rng:element name="newline"><rng:empty/></rng:element>
|
||||
<rng:optional><rng:attribute name="options"/></rng:optional>
|
||||
<rng:ref name="searchpanel"/>
|
||||
<rng:ref name="superbar"/>
|
||||
</rng:choice>
|
||||
</rng:zeroOrMore>
|
||||
</rng:element>
|
||||
|
||||
Reference in New Issue
Block a user