[FIX] blog: don't rewrite old uniq name and clean comment(s) linked to a deleted path
This commit is contained in:
parent
dd23586e16
commit
2833d87dfb
|
@ -141,6 +141,8 @@ class BlogPost(osv.Model):
|
||||||
:return result: (html, mappin), where html is the updated html with ID
|
: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
|
and mapping is a list of (old_ID, new_ID), where old_ID
|
||||||
is None is the paragraph is a new one. """
|
is None is the paragraph is a new one. """
|
||||||
|
|
||||||
|
existing_attributes = []
|
||||||
mapping = []
|
mapping = []
|
||||||
if not html:
|
if not html:
|
||||||
return html, mapping
|
return html, mapping
|
||||||
|
@ -148,7 +150,6 @@ class BlogPost(osv.Model):
|
||||||
tags = ['p']
|
tags = ['p']
|
||||||
if attribute is None:
|
if attribute is None:
|
||||||
attribute = 'data-unique-id'
|
attribute = 'data-unique-id'
|
||||||
counter = 0
|
|
||||||
|
|
||||||
# form a tree
|
# form a tree
|
||||||
root = lxml.html.fragment_fromstring(html, create_parent='div')
|
root = lxml.html.fragment_fromstring(html, create_parent='div')
|
||||||
|
@ -159,17 +160,22 @@ class BlogPost(osv.Model):
|
||||||
# - img src -> check URL
|
# - img src -> check URL
|
||||||
# - a href -> check URL
|
# - a href -> check URL
|
||||||
for node in root.iter():
|
for node in root.iter():
|
||||||
if not node.tag in tags:
|
if node.tag not in tags:
|
||||||
continue
|
continue
|
||||||
ancestor_tags = [parent.tag for parent in node.iterancestors()]
|
ancestor_tags = [parent.tag for parent in node.iterancestors()]
|
||||||
|
|
||||||
|
old_attribute = node.get(attribute)
|
||||||
|
new_attribute = old_attribute
|
||||||
|
if old_attribute in existing_attributes:
|
||||||
if ancestor_tags:
|
if ancestor_tags:
|
||||||
ancestor_tags.pop()
|
ancestor_tags.pop()
|
||||||
|
counter = random.randint(10000, 99999)
|
||||||
ancestor_tags.append('counter_%s' % counter)
|
ancestor_tags.append('counter_%s' % counter)
|
||||||
new_attribute = '/'.join(reversed(ancestor_tags))
|
new_attribute = '/'.join(reversed(ancestor_tags))
|
||||||
old_attribute = node.get(attribute)
|
|
||||||
node.set(attribute, new_attribute)
|
node.set(attribute, new_attribute)
|
||||||
mapping.append((old_attribute, counter))
|
|
||||||
counter += 1
|
existing_attributes.append(new_attribute)
|
||||||
|
mapping.append((old_attribute, new_attribute))
|
||||||
|
|
||||||
html = lxml.html.tostring(root, pretty_print=False, method='html')
|
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
|
# 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
|
content = self.browse(cr, uid, id, context=context).content
|
||||||
if content is False:
|
if content is False:
|
||||||
return content
|
return content
|
||||||
|
|
||||||
content, mapping = self.html_tag_nodes(content, attribute='data-chatter-id', tags=['p'], context=context)
|
content, mapping = self.html_tag_nodes(content, attribute='data-chatter-id', tags=['p'], context=context)
|
||||||
for old_attribute, new_attribute in mapping:
|
if id: # not creating
|
||||||
if not old_attribute:
|
existing = [x[0] for x in mapping if x[0]]
|
||||||
continue
|
msg_ids = self.pool['mail.message'].search(cr, SUPERUSER_ID, [
|
||||||
msg_ids = self.pool['mail.message'].search(cr, SUPERUSER_ID, [('path', '=', old_attribute)], context=context)
|
('res_id', '=', id),
|
||||||
self.pool['mail.message'].write(cr, SUPERUSER_ID, msg_ids, {'path': new_attribute}, context=context)
|
('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
|
return content
|
||||||
|
|
||||||
def create_history(self, cr, uid, ids, vals, context=None):
|
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):
|
def write(self, cr, uid, ids, vals, context=None):
|
||||||
if 'content' in vals:
|
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)
|
result = super(BlogPost, self).write(cr, uid, ids, vals, context)
|
||||||
self.create_history(cr, uid, ids, vals, context)
|
self.create_history(cr, uid, ids, vals, context)
|
||||||
self._check_for_publication(cr, uid, ids, vals, context=context)
|
self._check_for_publication(cr, uid, ids, vals, context=context)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class BlogPostHistory(osv.Model):
|
class BlogPostHistory(osv.Model):
|
||||||
_name = "blog.post.history"
|
_name = "blog.post.history"
|
||||||
_description = "Blog Post History"
|
_description = "Blog Post History"
|
||||||
|
|
Loading…
Reference in New Issue