summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJeremy Kersten <jke@odoo.com>2015-02-02 14:14:35 +0100
committerJeremy Kersten <jke@odoo.com>2015-02-02 15:30:22 +0100
commit2833d87dfb7996400feaadbd8aaba06a8be7c22f (patch)
tree87b94783793404d5acfc122c425d0c71074ebf90 /addons
parentdd23586e16f8938f4fac6a73978e8771e3804198 (diff)
[FIX] blog: don't rewrite old uniq name and clean comment(s) linked to a deleted path
Diffstat (limited to 'addons')
-rw-r--r--addons/website_blog/models/website_blog.py42
1 files changed, 27 insertions, 15 deletions
diff --git a/addons/website_blog/models/website_blog.py b/addons/website_blog/models/website_blog.py
index 8cea7eb0d68..e1f0803c387 100644
--- a/addons/website_blog/models/website_blog.py
+++ b/addons/website_blog/models/website_blog.py
@@ -141,6 +141,8 @@ class BlogPost(osv.Model):
:return result: (html, mappin), where html is the updated html with ID
and mapping is a list of (old_ID, new_ID), where old_ID
is None is the paragraph is a new one. """
+
+ existing_attributes = []
mapping = []
if not html:
return html, mapping
@@ -148,7 +150,6 @@ class BlogPost(osv.Model):
tags = ['p']
if attribute is None:
attribute = 'data-unique-id'
- counter = 0
# form a tree
root = lxml.html.fragment_fromstring(html, create_parent='div')
@@ -159,17 +160,22 @@ class BlogPost(osv.Model):
# - img src -> check URL
# - a href -> check URL
for node in root.iter():
- if not node.tag in tags:
+ if node.tag not in tags:
continue
ancestor_tags = [parent.tag for parent in node.iterancestors()]
- if ancestor_tags:
- ancestor_tags.pop()
- ancestor_tags.append('counter_%s' % counter)
- new_attribute = '/'.join(reversed(ancestor_tags))
+
old_attribute = node.get(attribute)
- node.set(attribute, new_attribute)
- mapping.append((old_attribute, counter))
- counter += 1
+ new_attribute = old_attribute
+ if old_attribute in existing_attributes:
+ if ancestor_tags:
+ ancestor_tags.pop()
+ counter = random.randint(10000, 99999)
+ ancestor_tags.append('counter_%s' % counter)
+ new_attribute = '/'.join(reversed(ancestor_tags))
+ node.set(attribute, new_attribute)
+
+ existing_attributes.append(new_attribute)
+ mapping.append((old_attribute, new_attribute))
html = lxml.html.tostring(root, pretty_print=False, method='html')
# this is ugly, but lxml/etree tostring want to put everything in a 'div' that breaks the editor -> remove that
@@ -182,12 +188,17 @@ class BlogPost(osv.Model):
content = self.browse(cr, uid, id, context=context).content
if content is False:
return content
+
content, mapping = self.html_tag_nodes(content, attribute='data-chatter-id', tags=['p'], context=context)
- for old_attribute, new_attribute in mapping:
- if not old_attribute:
- continue
- msg_ids = self.pool['mail.message'].search(cr, SUPERUSER_ID, [('path', '=', old_attribute)], context=context)
- self.pool['mail.message'].write(cr, SUPERUSER_ID, msg_ids, {'path': new_attribute}, context=context)
+ if id: # not creating
+ existing = [x[0] for x in mapping if x[0]]
+ msg_ids = self.pool['mail.message'].search(cr, SUPERUSER_ID, [
+ ('res_id', '=', id),
+ ('model', '=', self._name),
+ '|', ('path', 'not in', existing), ('path', '=', False)
+ ], context=context)
+ self.pool['mail.message'].unlink(cr, SUPERUSER_ID, msg_ids, context=context)
+
return content
def create_history(self, cr, uid, ids, vals, context=None):
@@ -232,12 +243,13 @@ class BlogPost(osv.Model):
def write(self, cr, uid, ids, vals, context=None):
if 'content' in vals:
- vals['content'] = self._postproces_content(cr, uid, None, vals['content'], context=context)
+ vals['content'] = self._postproces_content(cr, uid, ids[0], vals['content'], context=context)
result = super(BlogPost, self).write(cr, uid, ids, vals, context)
self.create_history(cr, uid, ids, vals, context)
self._check_for_publication(cr, uid, ids, vals, context=context)
return result
+
class BlogPostHistory(osv.Model):
_name = "blog.post.history"
_description = "Blog Post History"