[MERGE] [IMP] tools: mail: improved html_email_clean

- 'read more' links are now in the last container, not after, allowing to have read more
links embedded inside shortened paragraphs
- added expand_options dict allowing to customize the read more

[ADD] qweb: wrapper node for more field types

[FIX] ir_ui_view: don't try to set attributes on comments, it makes no sense

bzr revid: tde@openerp.com-20130923154235-fz0ksnd7i63qqrmu
This commit is contained in:
Thibault Delavallée 2013-09-23 17:42:35 +02:00
commit be1e5bbfed
3 changed files with 28 additions and 6 deletions

View File

@ -254,7 +254,7 @@ class view(osv.osv):
return None
def inherit_branding(self, specs_tree, view_id):
for node in specs_tree:
for node in specs_tree.iterchildren(tag=etree.Element):
xpath = node.getroottree().getpath(node)
if node.tag == 'data' or node.tag == 'xpath':
self.inherit_branding(node, view_id)

View File

@ -99,7 +99,7 @@ def html_sanitize(src, silent=True):
# HTML Cleaner
#----------------------------------------------------------
def html_email_clean(html, remove=False, shorten=False, max_length=300):
def html_email_clean(html, remove=False, shorten=False, max_length=300, expand_options=None):
""" html_email_clean: clean the html by doing the following steps:
- try to strip email quotes, by removing blockquotes or having some client-
@ -170,6 +170,9 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300):
iteration += 1
new_node = _insert_new_node(node, -1, new_node_tag, text[idx:] + (cur_node.tail or ''), None, {})
if expand_options is None:
expand_options = {}
if not html or not isinstance(html, basestring):
return html
html = ustr(html)
@ -252,14 +255,26 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300):
stop_idx = len(outertext)
node.text = innertext + outertext[0:stop_idx]
# create <span> ... <a href="#">read more</a></span> node
read_more_node = _create_node('span', ' ... ', None, {'class': 'oe_mail_expand'})
read_more_link_node = _create_node('a', 'read more', None, {'href': '#', 'class': 'oe_mail_expand'})
read_more_node = _create_node(
'span',
' ... ',
None,
{'class': expand_options.get('oe_expand_span_class', 'oe_mail_expand')}
)
read_more_link_node = _create_node(
'a',
'read more',
None,
{
'href': expand_options.get('oe_expand_href', '#'),
'class': expand_options.get('oe_expand_a_class', 'oe_mail_expand'),
}
)
read_more_node.append(read_more_link_node)
# create outertext node
new_node = _create_node('span', outertext[stop_idx:])
# add newly created nodes in dom
node.addnext(new_node)
node.addnext(read_more_node)
node.append(read_more_node)
# tag node
new_node.set('in_overlength', '1')

View File

@ -358,7 +358,14 @@ DEFAULT_TAG_BY_TYPE = {
'integer': 'span',
'float': 'span',
'char': 'span',
'date': 'span',
'datetime': 'span',
'time': 'span',
'many2one': 'span',
'text': 'p',
'html': 'div',
}
# leave this, al.