[FIX][BACK FROM TRASH] mail: chatter: read more / read less
Read more / less feature is back (and probably ugly). It has probably been removed when refactoring the old chatter. [FIX] tools: html shortening: encoding issue
This commit is contained in:
@@ -185,8 +185,6 @@ class Message(models.Model):
|
||||
:param list messages: list of message, as get_dict result
|
||||
:param dict message_tree: {[msg.id]: msg browse record}
|
||||
"""
|
||||
pid = self.env.user.partner_id.id
|
||||
|
||||
# 1. Aggregate partners (author_id and partner_ids), attachments and tracking values
|
||||
partners = self.env['res.partner']
|
||||
attachments = self.env['ir.attachment']
|
||||
@@ -248,13 +246,13 @@ class Message(models.Model):
|
||||
tracking_value_ids.append(tracking_tree[tracking_value.id])
|
||||
|
||||
message_dict.update({
|
||||
#'is_author': pid == author[0],
|
||||
'author_id': author,
|
||||
'partner_ids': partner_ids,
|
||||
'attachment_ids': attachment_ids,
|
||||
'tracking_value_ids': tracking_value_ids,
|
||||
#'user_pid': pid
|
||||
})
|
||||
})
|
||||
body_short = tools.html_email_clean(message_dict['body'], remove=True)
|
||||
message_dict['body_short'] = body_short != message_dict['body'] and body_short or False
|
||||
|
||||
return True
|
||||
|
||||
@@ -326,6 +324,7 @@ class Message(models.Model):
|
||||
- int: number of messages read (status 'unread' to 'read')
|
||||
- list: list of threads [[messages_of_thread1], [messages_of_thread2]]
|
||||
"""
|
||||
# TDE note: seems deprecated, not used but however still kept - why ?
|
||||
assert thread_level in [0, 1], 'message_read() thread_level should be 0 (flat) or 1 (1 level of thread); given %s.' % thread_level
|
||||
|
||||
domain = domain if domain is not None else []
|
||||
|
||||
@@ -378,6 +378,7 @@ var ChatMailThread = Widget.extend(mail_thread.MailThreadMixin, ControlPanelMixi
|
||||
"click .o_mail_thread_show_more > button": "message_load_history",
|
||||
// events from MailThreadMixin
|
||||
"click .o_mail_redirect": "on_click_redirect",
|
||||
"click .o_mail_expand": "on_message_body_toggle",
|
||||
"click .o_mail_thread_message_star": "on_message_star",
|
||||
// events specific for ChatMailThread
|
||||
"click .o_mail_chat_channel_item": "on_click_channel",
|
||||
|
||||
@@ -273,6 +273,7 @@ var ChatterMailThread = form_common.AbstractField.extend(mail_thread.MailThreadM
|
||||
"click .o_mail_thread_message_star": "on_message_star",
|
||||
"click .o_mail_thread_message_needaction": "on_message_needaction",
|
||||
"click .o_mail_thread_show_more": "message_load_history",
|
||||
"click .o_mail_expand": "on_message_body_toggle",
|
||||
// toggle message composer (!! declaration order is important !!)
|
||||
"click .o_mail_chatter_button_new_message": "on_open_composer",
|
||||
"click .o_mail_chatter_button_log_note": "on_open_composer",
|
||||
|
||||
@@ -617,6 +617,16 @@ var MailThreadMixin = {
|
||||
*/
|
||||
on_reverse_breadcrumb: function(){
|
||||
|
||||
},
|
||||
/**
|
||||
* Toggle short / long body when present (hide signature / crop long
|
||||
messages)
|
||||
*/
|
||||
on_message_body_toggle: function (event) {
|
||||
event.preventDefault();
|
||||
var $source = this.$(event.currentTarget);
|
||||
$source.parents('.o_mail_thread_message_core').find('.o_mail_body_short').toggle();
|
||||
$source.parents('.o_mail_thread_message_core').find('.o_mail_body_long').toggle();
|
||||
},
|
||||
/**
|
||||
* Toggle a message as 'starred' (or not), by toggling the 'o_mail_message_starred' css class.
|
||||
|
||||
@@ -44,6 +44,9 @@
|
||||
> p {
|
||||
margin: 0 0 9px; // Required by the old design to override a general rule on p's
|
||||
}
|
||||
.o_mail_body_long {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.o_mail_thread_message_star, .o_mail_thread_message_needaction {
|
||||
cursor: pointer;
|
||||
|
||||
@@ -141,7 +141,19 @@
|
||||
</t>
|
||||
<!-- normal message -->
|
||||
<t t-if="!(message.tracking_value_ids && message.tracking_value_ids.length > 0)">
|
||||
<t t-raw="message.body"/>
|
||||
<t t-if="message.body_short">
|
||||
<div class="o_mail_body_short">
|
||||
<t t-raw="message.body_short"/>
|
||||
<span class="o_mail_expand"><a href="#">... read more</a></span>
|
||||
</div>
|
||||
<div class="o_mail_body_long">
|
||||
<t t-raw="message.body"/>
|
||||
<span class="o_mail_expand"><a href="#">... read less</a></span>
|
||||
</div>
|
||||
</t>
|
||||
<t t-if="! message.body_short">
|
||||
<t t-raw="message.body"/>
|
||||
</t>
|
||||
</t>
|
||||
<!-- Attachments -->
|
||||
<t t-foreach="message.attachment_ids" t-as="attachment">
|
||||
|
||||
@@ -316,7 +316,7 @@ class TestCleaner(unittest2.TestCase):
|
||||
for ext in test_mail_examples.BUG_1_IN:
|
||||
self.assertIn(ext, new_html, 'html_email_cleaner wrongly removed valid content')
|
||||
for ext in test_mail_examples.BUG_1_OUT:
|
||||
self.assertNotIn(ext, new_html, 'html_email_cleaner did not removed invalid content')
|
||||
self.assertNotIn(ext.decode('utf-8'), new_html, 'html_email_cleaner did not removed invalid content')
|
||||
|
||||
new_html = html_email_clean(test_mail_examples.BUG2, remove=True, shorten=True, max_length=250)
|
||||
for ext in test_mail_examples.BUG_2_IN:
|
||||
|
||||
+12
-7
@@ -307,13 +307,13 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300, expand_o
|
||||
|
||||
# html: ClEditor seems to love using <div><br /><div> -> replace with <br />
|
||||
br_div_tags = re.compile(r'(<div>\s*<br\s*\/>\s*<\/div>)', re.IGNORECASE)
|
||||
html = _replace_matching_regex(br_div_tags, html, '<br />')
|
||||
inner_html = _replace_matching_regex(br_div_tags, html, '<br />')
|
||||
|
||||
# form a tree
|
||||
root = lxml.html.fromstring(html)
|
||||
root = lxml.html.fromstring(inner_html)
|
||||
if not len(root) and root.text is None and root.tail is None:
|
||||
html = '<div>%s</div>' % html
|
||||
root = lxml.html.fromstring(html)
|
||||
inner_html = '<div>%s</div>' % inner_html
|
||||
root = lxml.html.fromstring(inner_html)
|
||||
|
||||
quote_tags = re.compile(r'(\n(>)+[^\n\r]*)')
|
||||
signature = re.compile(r'([-]{2,}[\s]?[\r\n]{1,2}[\s\S]+)')
|
||||
@@ -333,6 +333,7 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300, expand_o
|
||||
|
||||
# tree: tag nodes
|
||||
# signature_begin = False # try dynamic signature recognition
|
||||
quoted = False
|
||||
quote_begin = False
|
||||
overlength = False
|
||||
overlength_section_id = None
|
||||
@@ -381,9 +382,11 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300, expand_o
|
||||
if node.tag == 'blockquote' or node.get('text_quote') or node.get('text_signature'):
|
||||
# here no quote_begin because we want to be able to remove some quoted
|
||||
# text without removing all the remaining context
|
||||
quoted = True
|
||||
node.set('in_quote', '1')
|
||||
if node.getparent() is not None and node.getparent().get('in_quote'):
|
||||
# inside a block of removed text but not in quote_begin (see above)
|
||||
quoted = True
|
||||
node.set('in_quote', '1')
|
||||
|
||||
# shorten:
|
||||
@@ -445,12 +448,14 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300, expand_o
|
||||
node_class = node.get('class', '') + ' oe_mail_cleaned'
|
||||
node.set('class', node_class)
|
||||
|
||||
if not overlength and not quote_begin and not quoted:
|
||||
return html
|
||||
|
||||
# html: \n that were tail of elements have been encapsulated into <span> -> back to \n
|
||||
html = etree.tostring(root, pretty_print=False)
|
||||
html = etree.tostring(root, pretty_print=False, encoding='UTF-8')
|
||||
linebreaks = re.compile(r'<span[^>]*>([\s]*[\r\n]+[\s]*)<\/span>', re.IGNORECASE | re.DOTALL)
|
||||
html = _replace_matching_regex(linebreaks, html, '\n')
|
||||
|
||||
return html
|
||||
return ustr(html)
|
||||
|
||||
|
||||
#----------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user