from openerp import tools, api
from openerp.http import request
from openerp.osv import fields, osv, orm
-from openerp.tools import graph, SKIPPED_ELEMENT_TYPES
+from openerp.tools import config, graph, SKIPPED_ELEMENT_TYPES
+from openerp.tools.convert import _fix_multiple_roots
from openerp.tools.parse_version import parse_version
from openerp.tools.safe_eval import safe_eval as eval
from openerp.tools.view_validation import valid_view
return node_classes.issuperset(cls)
+def get_view_arch_from_file(filename, xmlid):
+ doc = etree.parse(filename)
+ node = None
+ for n in doc.xpath('//*[@id="%s"] | //*[@id="%s"]' % (xmlid, xmlid.split('.')[1])):
+ if n.tag in ('template', 'record'):
+ node = n
+ break
+ if node is not None:
+ if node.tag == 'record':
+ field = node.find('field[@name="arch"]')
+ _fix_multiple_roots(field)
+ inner = ''.join([etree.tostring(child) for child in field.iterchildren()])
+ return field.text + inner
+ elif node.tag == 'template':
+ # The following dom operations has been copied from convert.py's _tag_template()
+ if not node.get('inherit_id'):
+ node.set('t-name', xmlid)
+ node.tag = 't'
+ else:
+ node.tag = 'data'
+ node.attrib.pop('id', None)
+ return etree.tostring(node)
+ raise ValueError("Could not find view arch definition in file '%s' for xmlid '%s'" % (filename, xmlid))
+
xpath_utils = etree.FunctionNamespace(None)
xpath_utils['hasclass'] = _hasclass
data_ids = IMD.search_read(cr, uid, [('id', 'in', ids), ('model', '=', 'ir.ui.view')], ['res_id'], context=context)
return map(itemgetter('res_id'), data_ids)
+ def _arch_get(self, cr, uid, ids, name, arg, context=None):
+ result = {}
+ for view in self.browse(cr, uid, ids, context=context):
+ arch_fs = None
+ if config['dev_mode'] and view.arch_fs and view.xml_id:
+ arch_fs = get_view_arch_from_file(view.arch_fs, view.xml_id)
+ result[view.id] = arch_fs or view.arch_db
+ return result
+
+ def _arch_set(self, cr, uid, ids, field_name, field_value, args, context=None):
+ if not isinstance(ids, list):
+ ids = [ids]
+ if field_value:
+ for view in self.browse(cr, uid, ids, context=context):
+ data = dict(arch_db=field_value)
+ key = 'install_mode_data'
+ if context and key in context:
+ imd = context[key]
+ if self._model._name == imd['model'] and (not view.xml_id or view.xml_id == imd['xml_id']):
+ data['arch_fs'] = imd['xml_file']
+ self.write(cr, uid, ids, data, context=context)
+
+ return True
+
_columns = {
'name': fields.char('View Name', required=True),
'model': fields.char('Object', select=True),
('kanban', 'Kanban'),
('search','Search'),
('qweb', 'QWeb')], string='View Type'),
- 'arch': fields.text('View Architecture', required=True),
+ 'arch': fields.function(_arch_get, fnct_inv=_arch_set, string='View Architecture', type="text", nodrop=True),
+ 'arch_db': fields.text('Arch Blob'),
+ 'arch_fs': fields.text('Arch Filename'),
'inherit_id': fields.many2one('ir.ui.view', 'Inherited View', ondelete='cascade', select=True),
'inherit_children_ids': fields.one2many('ir.ui.view','inherit_id', 'Inherit Views'),
'field_parent': fields.char('Child Field'),
group = optparse.OptionGroup(parser, "Advanced options")
if os.name == 'posix':
group.add_option('--auto-reload', dest='auto_reload', action='store_true', my_default=False, help='enable auto reload')
+ group.add_option('--dev', dest='dev_mode', action='store_true', my_default=False, help='enable developper mode')
group.add_option('--debug', dest='debug_mode', action='store_true', my_default=False, help='enable debug mode')
group.add_option("--stop-after-init", action="store_true", dest="stop_after_init", my_default=False,
help="stop the server after its initialization")
# if defined but None take the configfile value
keys = [
'language', 'translate_out', 'translate_in', 'overwrite_existing_translations',
- 'debug_mode', 'smtp_ssl', 'load_language',
+ 'dev_mode', 'debug_mode', 'smtp_ssl', 'load_language',
'stop_after_init', 'logrotate', 'without_demo', 'xmlrpc', 'syslog',
'list_db', 'xmlrpcs', 'proxy_mode',
'test_file', 'test_enable', 'test_commit', 'test_report_directory',
rec_model = rec.get("model").encode('ascii')
model = self.pool[rec_model]
rec_id = rec.get("id",'').encode('ascii')
- rec_context = rec.get("context", None)
+ rec_context = rec.get("context", {})
if rec_context:
rec_context = unsafe_eval(rec_context)
+
+ if self.xml_filename and rec_id:
+ rec_context['install_mode_data'] = dict(
+ xml_file=self.xml_filename,
+ xml_id=rec_id,
+ model=rec_model,
+ )
+
self._test_xml_id(rec_id)
# in update mode, the record won't be updated if the data node explicitely
# opt-out using @noupdate="1". A second check will be performed in
raise ParseError, (misc.ustr(e), etree.tostring(rec).rstrip(), rec.getroottree().docinfo.URL, rec.sourceline), exc_info[2]
return True
- def __init__(self, cr, module, idref, mode, report=None, noupdate=False):
+ def __init__(self, cr, module, idref, mode, report=None, noupdate=False, xml_filename=None):
self.mode = mode
self.module = module
report = assertion_report.assertion_report()
self.assertion_report = report
self.noupdate = noupdate
+ self.xml_filename = xml_filename
self._tags = {
'menuitem': self._tag_menuitem,
'record': self._tag_record,
if idref is None:
idref={}
- obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate)
+ if isinstance(xmlfile, file):
+ xml_filename = xmlfile.name
+ else:
+ xml_filename = xmlfile
+ obj = xml_import(cr, module, idref, mode, report=report, noupdate=noupdate, xml_filename=xml_filename)
obj.parse(doc.getroot())
return True