Browse Source

[8.0][IMP] add export feature for help online

pull/46/head
Cédric Pigeon 10 years ago
parent
commit
ebe5ede397
  1. 18
      help_online/__openerp__.py
  2. 9
      help_online/data/help_auto_backup.xml
  3. 25
      help_online/data/ir_config_parameter_data.xml
  4. 16
      help_online/models/__init__.py
  5. 285
      help_online/models/export_help_wizard.py
  6. 27
      help_online/models/help_online.py
  7. 81
      help_online/models/ir_model.py
  8. BIN
      help_online/static/description/icon.png
  9. 1
      help_online/static/description/index.html
  10. BIN
      help_online/static/src/img/snippet/snippet_thumbs.png
  11. 35
      help_online/tests/__init__.py
  12. 78
      help_online/tests/data/help_test_data.xml
  13. 169
      help_online/tests/test_export_help_wizard.py
  14. 56
      help_online/views/export_help_wizard_view.xml
  15. 28
      help_online/views/ir_ui_view_view.xml

18
help_online/__openerp__.py

@ -3,11 +3,19 @@
#
# Authors: Nemry Jonathan
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -45,9 +53,13 @@ help page.
The help pages are created and managed via the website Module.
""",
'data': [
'data/help_auto_backup.xml', # must always be the first
'security/help_online_groups.xml',
'views/help_online_view.xml',
'views/website_help_online.xml',
'views/ir_ui_view_view.xml',
'views/export_help_wizard_view.xml',
'data/ir_config_parameter_data.xml',
],
'qweb': [
'static/src/xml/help_online.xml',

9
help_online/data/help_auto_backup.xml

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="wz_auto_backup" model="export.help.wizard">
</record>
<function model="export.help.wizard" name="auto_backup"/>
</data>
</openerp>

25
help_online/data/ir_config_parameter_data.xml

@ -0,0 +1,25 @@
<?xml version='1.0' encoding='UTF-8' ?>
<openerp>
<data noupdate="0">
<record id="help_online_autobackup_path" model="ir.config_parameter">
<field name="key">help_online_autobackup_path</field>
<field name="value">False</field>
</record>
</data>
<data noupdate="0">
<record id="help_online_page_prefix" model="ir.config_parameter">
<field name="key">help_online_page_prefix</field>
<field name="value">help</field>
</record>
</data>
<data noupdate="0">
<record id="help_online_template_prefix" model="ir.config_parameter">
<field name="key">help_online_template_prefix</field>
<field name="value">help-template</field>
</record>
</data>
</openerp>

16
help_online/models/__init__.py

@ -3,11 +3,19 @@
#
# Authors: Nemry Jonathan
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -19,3 +27,5 @@
#
##############################################################################
from . import help_online
from . import export_help_wizard
from . import ir_model

285
help_online/models/export_help_wizard.py

@ -0,0 +1,285 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Cédric Pigeon
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
import base64
import time
import copy
from lxml import etree as ET
from xml.dom import minidom as minidom
from openerp import models, fields, api, exceptions
from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
PAGE_PREFIX_PARAMETER = 'help_online_page_prefix'
TEMPLATE_PREFIX_PARAMETER = 'help_online_template_prefix'
AUTOBACKUP_PARAMETER = 'help_online_autobackup_path'
HELP_ONLINE_SNIPPET_IMAGE_PATH = '/help_online/static/src/'\
'img/snippet/snippet_thumbs.png'
class ExportHelpWizard(models.TransientModel):
_name = "export.help.wizard"
_description = 'Export Help Online'
data = fields.Binary('XML', readonly=True)
export_filename = fields.Char('Export XML Filename', size=128)
def _manage_images_on_page(self, page_node, data_node):
'''
- Extract images from page and generate a xml node
- Replace db id in url with xml id
'''
def substitute_id_by_xml_id():
new_src = False
attach_id = False
if 'id=' in img_src:
id_pos = img_src.index('id=') + 3
attach_id = img_elem.get('src')[id_pos:]
new_src = img_src.replace(attach_id, xml_id)
else:
fragments = img_src.split('ir.attachment/')
attach_id, trail = fragments[1].split('_', 1)
new_src = "/website/image/ir.attachment/%s|%s" % \
(xml_id, trail)
return new_src, attach_id
i_img = 0
img_model = 'ir.attachment'
for img_elem in page_node.iter('img'):
if img_model in img_elem.get('src'):
i_img += 1
xml_id = "%s_img_%s" % \
(page_node.attrib['name'], str(i_img).rjust(2, '0'))
img_src = img_elem.get('src')
new_src, attach_id = substitute_id_by_xml_id()
if not attach_id:
continue
image = self.env[img_model].browse(int(attach_id))
if not image:
continue
img_elem.attrib['src'] = new_src
img_node = ET.SubElement(data_node,
'record',
attrib={'id': xml_id,
'model': img_model})
field_node = ET.SubElement(img_node,
'field',
attrib={'name': 'datas'})
field_node.text = str(image.datas)
field_node = ET.SubElement(img_node,
'field',
attrib={'name': 'datas_fname'})
field_node.text = image.datas_fname
field_node = ET.SubElement(img_node,
'field',
attrib={'name': 'name'})
field_node.text = image.name
field_node = ET.SubElement(img_node,
'field',
attrib={'name': 'res_model'})
field_node.text = image.res_model
field_node = ET.SubElement(img_node,
'field',
attrib={'name': 'mimetype'})
field_node.text = image.mimetype
data_node.append(img_node)
def _clean_href_urls(self, page_node, page_prefix, template_prefix):
'''
Remove host address for href urls
'''
for a_elem in page_node.iter('a'):
if not a_elem.get('href'):
continue
href = a_elem.get('href')
if not href.startswith('http:'):
continue
page_url = '/page/%s' % page_prefix
template_url = '/page/%s' % template_prefix
if not page_url in href and not template_url in href:
continue
elif page_url in href and not template_url in href:
pass
elif not page_url in href and template_url in href:
page_url = template_url
else:
if page_prefix in template_prefix:
page_url = template_url
else:
pass
if page_url:
trail = href.split(page_url, 1)[1]
a_elem.attrib['href'] = page_url + trail
def _generate_snippet_from_template(self, page_node,
template_id, template_prefix):
'''
Generate a website snippet from a template
'''
page = copy.deepcopy(page_node)
snippet = ET.Element('template')
snippet.attrib['id'] = template_id + '_snippet'
snippet.attrib['inherit_id'] = 'website.snippets'
snippet.attrib['name'] = page_node.attrib['name']
xpath = ET.SubElement(snippet,
'xpath',
attrib={'expr': "//div[@id='snippet_structure']",
'position': 'inside'})
main_div = ET.SubElement(xpath,
'div')
thumbnail = ET.SubElement(main_div,
'div',
attrib={'class': 'oe_snippet_thumbnail'})
img = ET.SubElement(thumbnail,
'img',
attrib={'class': 'oe_snippet_thumbnail_img',
'src': HELP_ONLINE_SNIPPET_IMAGE_PATH})
span = ET.SubElement(thumbnail,
'span',
attrib={'class': 'oe_snippet_thumbnail_title'})
span.text = page_node.attrib['name'].replace(template_prefix, '')
body = ET.SubElement(main_div,
'section',
attrib={'class': 'oe_snippet_body '\
'mt_simple_snippet'})
template = page.find(".//div[@id='wrap']")
for node in template.getchildren():
body.append(node)
return snippet
def _get_qweb_views_data(self):
parameter_model = self.env['ir.config_parameter']
page_prefix = parameter_model.get_param(PAGE_PREFIX_PARAMETER,
False)
template_prefix = parameter_model.get_param(TEMPLATE_PREFIX_PARAMETER,
False)
if not page_prefix or not template_prefix:
return False
domain = [('type', '=', 'qweb'),
('page', '=', True),
'|',
('name', 'like', '%s%%' % page_prefix),
('name', 'like', '%s%%' % template_prefix)]
view_data_list = self.env['ir.ui.view'].search_read(domain,
['arch', 'name'],
order='name')
xml_to_export = ET.Element('openerp')
data_node = ET.SubElement(xml_to_export, 'data')
for view_data in view_data_list:
parser = ET.XMLParser(remove_blank_text=True)
root = ET.XML(view_data['arch'], parser=parser)
root.tag = 'template'
template_id = root.attrib.pop('t-name')
root.attrib['name'] = view_data['name'].replace('website.', '')
root.attrib['id'] = template_id
root.attrib['page'] = 'True'
self._manage_images_on_page(root, data_node)
self._clean_href_urls(root, page_prefix, template_prefix)
data_node.append(root)
if root.attrib['name'].startswith(template_prefix):
snippet = self._generate_snippet_from_template(root,
template_id,
template_prefix)
data_node.append(snippet)
if len(view_data_list) > 0:
rough_string = ET.tostring(xml_to_export, encoding='utf-8',
xml_declaration=True)
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent=" ", encoding='utf-8')
else:
return False
@api.multi
def export_help(self):
"""
Export all Qweb views related to help online in a Odoo
data XML file
"""
xml_data = self._get_qweb_views_data()
if not xml_data:
raise exceptions.Warning(_('No data to export !'))
out = base64.encodestring(xml_data)
self.write({'data': out,
'export_filename': 'help_online_data.xml'})
return {
'name': 'Help Online Export',
'type': 'ir.actions.act_window',
'res_model': self._name,
'view_mode': 'form',
'view_type': 'form',
'res_id': self.id,
'views': [(False, 'form')],
'target': 'new',
}
@api.model
def auto_backup(self):
"""
Export data to a file on home directory of user
"""
parameter_model = self.env['ir.config_parameter']
autobackup_path = parameter_model.get_param(AUTOBACKUP_PARAMETER,
False)
if autobackup_path:
xml_data = self._get_qweb_views_data()
try:
timestr = time.strftime("%Y%m%d-%H%M%S")
filename = '%s/help_online_backup-%s.xml' % (autobackup_path,
timestr)
backup_file = open(filename,
'w')
backup_file.write(xml_data)
backup_file.close
except:
_logger.warning(_('Unable to write autobackup file '\
'in given directory: %s'
% autobackup_path))

27
help_online/models/help_online.py

@ -3,11 +3,19 @@
#
# Authors: Laurent Mignon
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -18,15 +26,20 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
from openerp import models, exceptions
from openerp.tools.translate import _
class HelpOnline(orm.TransientModel):
class HelpOnline(models.TransientModel):
_name = 'help.online'
def _get_view_name(self, model, view_type, domain=None, context=None):
name = 'help-%s' % model.replace('.', '-')
parameter_model = self.env['ir.config_parameter']
page_prefix = parameter_model.get_param('help_online_page_prefix',
False)
if not page_prefix:
raise exceptions.Warning(_('No page prefix parameter specified !'))
name = '%s-%s' % (page_prefix, model.replace('.', '-'))
return name
def page_exists(self, name):
@ -40,7 +53,7 @@ class HelpOnline(orm.TransientModel):
ir_model = self.env['ir.model']
description = self.env[model]._description
res = ir_model.name_search(model, operator='=')
if res:
if(res):
description = res[0][1]
name = self._get_view_name(model, view_type, domain, context)
if self.page_exists(name):

81
help_online/models/ir_model.py

@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Cédric Pigeon
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, api
from lxml import etree as ET
class ir_model_data(models.Model):
_inherit = 'ir.model.data'
@api.model
def _update(self, model, module, values, xml_id=False, store=True,
noupdate=False, mode='init', res_id=False):
if model == 'ir.ui.view':
parameter_model = self.env['ir.config_parameter']
page_prefix = parameter_model.get_param('help_online_page_prefix',
False)
if page_prefix and xml_id.startswith('website.%s' % page_prefix):
xml_str = self.manageImageReferences(values['arch'], module)
values['arch'] = xml_str
return super(ir_model_data, self)._update(model,
module,
values,
xml_id=xml_id,
store=store,
noupdate=noupdate,
mode=mode,
res_id=res_id)
def manageImageReferences(self, xml_str, module):
parser = ET.XMLParser(remove_blank_text=True)
root = ET.XML(xml_str, parser=parser)
img_model = 'ir.attachment'
for img_elem in root.iter('img'):
if img_model in img_elem.get('src'):
img_src = img_elem.get('src')
try:
if '/ir.attachment/' in img_src:
fragments = img_src.split('/ir.attachment/')
xml_id = fragments[1].split('|')[0]
img_src = img_src.replace("|", "_")
else:
id_pos = img_src.index('id=') + 3
xml_id = img_elem.get('src')[id_pos:]
img_id = self.get_object_reference(module,
xml_id)
img_elem.attrib['src'] = img_src.replace(xml_id,
str(img_id[1]))
except:
continue
return ET.tostring(root, encoding='utf-8', xml_declaration=False)

BIN
help_online/static/description/icon.png

After

Width: 225  |  Height: 218  |  Size: 79 KiB

1
help_online/static/description/index.html

@ -12,5 +12,6 @@
<img alt="help_online_create_page.png" src="help_online_create_page.png" width="80%" height="80%"/>
<p>The help pages are created and managed via the website Module.</p>
<br/>
<p>If you want to export your work, you simply have to use the export wizard through the settings menu.</p>
</div>
</div>

BIN
help_online/static/src/img/snippet/snippet_thumbs.png

After

Width: 169  |  Height: 180  |  Size: 42 KiB

35
help_online/tests/__init__.py

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_export_help_wizard
fast_suite = [
]
checks = [
test_export_help_wizard,
]

78
help_online/tests/data/help_test_data.xml

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="test_img_1" model="ir.attachment">
<field name="datas">iVBORw0KGgoAAAANSUhEUgAAANwAAAAzCAIAAABzKvGBAAAOOUlEQVR42u1beVRU5xWfYcZh3wao
cSnLAIMRIw1WZVdTPTGLadIsoqB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APuAdaenp5z5swhc8GGjFgD5/3EdX9/f0dHh3koP3XLnu8aKp95
dm3s2ucDA3zx74HXASjUvI40FCiIdnBw0AjvwI7ghYwjp5nSGlaF0WbTSyOev9vx3Z3OrrWxybt2
bv5FSLA1RKWmgSnNsDsZsR5BoIQPqri0dFBqwoDyJyc4KFnWikt2W1ub6VYYeYQkLHINDkrWFC53
7ki1HlwyoPzJiQYoFQpFR0fn+vg068ElWyKRWEVvy2hzaVVQ4u8Lt3d0bkpIhzoesnC+xSPEmNIa
MsVos+nwqBcQKHFEoqfcwJfJqbusApfAlJZma0bMKgiUGojEcfnbbTkWr+Ps+vp6S2eJEbPKcy8k
IFBqIBJJZ2dX+vY97x7KtWCEbOp3ARn949PefotuSi4jRLa33/Hy8gAsrovbogqLzz+roMsjetXc
YFBaQ6YYbTbt679Y0nIRIfKXS1d/8J7oqRWRGxO2b92S+NyzK2n3aAwoCf/7jpEfsQAoxU3nESI/
+0/5lq2Zn35yDKp2Usqbl+t1vUVuuIyMjBh6y/8Bzpl/yXfWC20AAAAASUVORK5CYII=
</field>
<field name="index_content">image</field>
<field name="datas_fname">test.png</field>
<field name="name">test.png</field>
<field name="res_model">ir.ui.view</field>
<field name="mimetype">image/png</field>
</record>
</data>
</openerp>

169
help_online/tests/test_export_help_wizard.py

@ -0,0 +1,169 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Cédric Pigeon
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
# All Rights Reserved
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs.
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contact a Free Software
# Service Company.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
import base64
from lxml import etree as ET
from anybox.testing.openerp import SharedSetupTransactionCase
_logger = logging.getLogger(__name__)
class test_export_help_wizard(object):
_data_files = ('data/help_test_data.xml',)
_module_ns = 'help_online'
def createPage(self, pageName, imgXmlId=False):
imgId = False
if imgXmlId:
imgId = self.ref('%s.%s' % (self._module_ns, imgXmlId))
rootNode = ET.Element('t')
rootNode.attrib['name'] = pageName
rootNode.attrib['t-name'] = "website.%s" % pageName
tNode = ET.SubElement(rootNode,
't',
attrib={'t-call': 'website.layout'})
structDivNode = ET.SubElement(tNode,
'div',
attrib={'class': 'oe_structure oe_empty',
'id': 'wrap'})
sectionNode = ET.SubElement(structDivNode,
'section',
attrib={'class': 'mt16 mb16'})
containerNode = ET.SubElement(sectionNode,
'div',
attrib={'class': 'container'})
rowNode = ET.SubElement(containerNode,
'div',
attrib={'class': 'row'})
bodyDivNode = ET.SubElement(rowNode,
'div',
attrib={'class': 'col-md-12 '\
'text-center mt16 mb32'})
style = "font-family: 'Helvetica Neue', Helvetica,"\
" Arial, sans-serif; color: rgb(51, 51, 51);"\
" text-align: left;"
h2Node = ET.SubElement(bodyDivNode,
'h2',
attrib={'style': style})
h2Node.text = "Test Sample Title"
if imgId:
imgDivNode = ET.SubElement(bodyDivNode,
'div',
attrib={'style': 'text-align: left;'})
src = "/website/image?field=datas&"\
"model=ir.attachment&id=%s" % str(imgId)
imgNode = ET.SubElement(imgDivNode,
'img',
attrib={'class': 'img-thumbnail',
'src': src})
imgDivNode = ET.SubElement(bodyDivNode,
'div',
attrib={'style': 'text-align: left;'})
src = "/website/image/ir.attachment/%s_ccc838d/datas" % str(imgId)
imgNode = ET.SubElement(imgDivNode,
'img',
attrib={'class': 'img-thumbnail',
'src': src})
arch = ET.tostring(rootNode, encoding='utf-8', xml_declaration=False)
vals = {
'name': pageName,
'type': 'qweb',
'arch': arch,
'page': True,
}
view_id = self.env['ir.ui.view'].create(vals)
return view_id.id
def setUp(self):
super(test_export_help_wizard, self).setUp()
self.pageName = False
self.imgXmlId = False
self.pageTemplate = False
def test_export_help(self):
'''
Export help data
'''
self.createPage(pageName=self.pageName, imgXmlId=self.imgXmlId)
wizardPool = self.env['export.help.wizard']
wizard = wizardPool.create({})
wizard.export_help()
xmlData = base64.decodestring(wizard.data)
parser = ET.XMLParser(remove_blank_text=True)
rootXml = ET.XML(xmlData, parser=parser)
xPath = ".//template[@id='website.%s']" % self.pageName
templateNodeList = rootXml.findall(xPath)
self.assertEqual(len(templateNodeList), 1)
self.assertNotIn("website.", templateNodeList[0].attrib['name'])
if self.imgXmlId:
xPath = ".//record[@id='%s_img_01']" % self.pageName
imgNodeList = rootXml.findall(xPath)
self.assertEqual(len(imgNodeList), 1)
for imgElem in templateNodeList[0].iter('img'):
imgSrc = imgElem.get('src')
if '/ir.attachment/' in imgSrc:
self.assertIn("/ir.attachment/%s_img_02|" \
% self.pageName, imgSrc)
else:
self.assertIn("id=%s_img_01" % self.pageName, imgSrc)
if self.pageTemplate:
xPath = ".//template[@id='website.%s_snippet']" % self.pageName
templateNodeList = rootXml.findall(xPath)
self.assertEqual(len(templateNodeList), 1)
self.assertNotIn("website.", templateNodeList[0].attrib['name'])
class test_export_help_with_image(test_export_help_wizard,
SharedSetupTransactionCase):
def setUp(self):
super(test_export_help_with_image, self).setUp()
parameter_model = self.env['ir.config_parameter']
page_prefix = parameter_model.get_param('help_online_page_prefix')
self.pageName = '%stest-page' % page_prefix
self.imgXmlId = 'test_img_1'
class test_export_help_template(test_export_help_wizard,
SharedSetupTransactionCase):
def setUp(self):
super(test_export_help_template, self).setUp()
parameter_model = self.env['ir.config_parameter']
template_prefix = parameter_model.get_param(
'help_online_template_prefix')
self.pageName = '%stest-template' % template_prefix
self.pageTemplate = True

56
help_online/views/export_help_wizard_view.xml

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="export_help_wizard_view">
<field name="name">export.help.wizard.view</field>
<field name="model">export.help.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Export Help Data">
<group colspan="2">
<field name="export_filename"
invisible="1"/>
</group>
<group>
<p>
This wizard allow you to export all QWeb views
related to help online. The result will be an Odoo
data xml file.
</p>
</group>
<group>
<field name="data"
nolabel="1"
readonly="1"
filename="export_filename" />
</group>
<footer>
<span name="go-wizard" attrs="{'invisible': [('export_filename', '!=', False)]}">
<button name="export_help"
string="Export"
type="object"
icon="gtk-execute"
class="oe_highlight" />
or
</span>
<button string="Close" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_export_help_wizard">
<field name="name">Export Help</field>
<field name="res_model">export.help.wizard</field>
<field name="view_id" ref="export_help_wizard_view"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="type">ir.actions.act_window</field>
</record>
<menuitem id="menu_help" name="Help Online" parent="base.menu_administration" sequence="30" groups="help_online_group_writer"/>
<menuitem id="menu_help_export" name="Export Help Online" parent="menu_help" action="action_export_help_wizard"/>
</data>
</openerp>

28
help_online/views/ir_ui_view_view.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="view_view_search" model="ir.ui.view">
<field name="name">ir.ui.view search (help_online)</field>
<field name="inherit_id" ref="base.view_view_search"/>
<field name="model">ir.ui.view</field>
<field name="arch" type="xml">
<xpath expr="//filter[@string='QWeb']" position="after">
<filter string="Website Page" domain="[('type', '=', 'qweb'),('page', '=', True)]"/>
</xpath>
</field>
</record>
<record id="view_view_form" model="ir.ui.view">
<field name="name">ir.ui.view form (help_online)</field>
<field name="inherit_id" ref="base.view_view_form"/>
<field name="model">ir.ui.view</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='type']" position="after">
<field name="page" string="Website Page?" readonly="1" attrs="{'invisible': [('type', '!=', 'qweb')]}"/>
</xpath>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save