2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-11-14 07:17:24 +00:00
|
|
|
|
2014-03-28 06:35:23 +00:00
|
|
|
from datetime import datetime
|
2014-04-02 11:16:56 +00:00
|
|
|
import difflib
|
2014-04-03 11:26:56 +00:00
|
|
|
import lxml
|
2014-04-02 11:16:56 +00:00
|
|
|
import random
|
2013-09-20 14:27:01 +00:00
|
|
|
|
|
|
|
from openerp import tools
|
2014-04-03 11:26:56 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2014-10-08 05:52:51 +00:00
|
|
|
from openerp.addons.website.models.website import slug
|
2013-09-20 14:27:01 +00:00
|
|
|
from openerp.osv import osv, fields
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.tools.translate import _
|
2013-09-20 14:27:01 +00:00
|
|
|
|
2014-04-02 11:16:56 +00:00
|
|
|
|
2014-01-24 16:22:51 +00:00
|
|
|
class Blog(osv.Model):
|
|
|
|
_name = 'blog.blog'
|
|
|
|
_description = 'Blogs'
|
2013-10-18 09:28:20 +00:00
|
|
|
_inherit = ['mail.thread', 'website.seo.metadata']
|
2008-11-21 12:53:55 +00:00
|
|
|
_order = 'name'
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
_columns = {
|
2014-02-23 14:17:06 +00:00
|
|
|
'name': fields.char('Blog Name', required=True),
|
2014-02-23 17:15:32 +00:00
|
|
|
'subtitle': fields.char('Blog Subtitle'),
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
'description': fields.text('Description'),
|
|
|
|
}
|
|
|
|
|
2014-12-02 09:28:18 +00:00
|
|
|
def all_tags(self, cr, uid, ids, min_limit=1, context=None):
|
|
|
|
req = """
|
|
|
|
SELECT
|
|
|
|
p.blog_id, count(*), r.blog_tag_id
|
|
|
|
FROM
|
|
|
|
blog_post_blog_tag_rel r
|
|
|
|
join blog_post p on r.blog_post_id=p.id
|
|
|
|
WHERE
|
|
|
|
p.blog_id in %s
|
|
|
|
GROUP BY
|
|
|
|
p.blog_id,
|
|
|
|
r.blog_tag_id
|
|
|
|
ORDER BY
|
|
|
|
count(*) DESC
|
|
|
|
"""
|
|
|
|
cr.execute(req, [tuple(ids)])
|
|
|
|
tag_by_blog = {i: [] for i in ids}
|
|
|
|
for blog_id, freq, tag_id in cr.fetchall():
|
|
|
|
if freq >= min_limit:
|
|
|
|
tag_by_blog[blog_id].append(tag_id)
|
|
|
|
|
|
|
|
tag_obj = self.pool['blog.tag']
|
|
|
|
for blog_id in tag_by_blog:
|
|
|
|
tag_by_blog[blog_id] = tag_obj.browse(cr, uid, tag_by_blog[blog_id], context=context)
|
|
|
|
return tag_by_blog
|
|
|
|
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
|
|
|
|
class BlogTag(osv.Model):
|
|
|
|
_name = 'blog.tag'
|
|
|
|
_description = 'Blog Tag'
|
2013-10-18 09:28:20 +00:00
|
|
|
_inherit = ['website.seo.metadata']
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
_order = 'name'
|
2010-03-17 08:36:08 +00:00
|
|
|
_columns = {
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
'name': fields.char('Name', required=True),
|
2014-11-21 14:53:13 +00:00
|
|
|
'post_ids': fields.many2many(
|
|
|
|
'blog.post', string='Posts',
|
|
|
|
),
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 08:36:08 +00:00
|
|
|
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
class BlogPost(osv.Model):
|
|
|
|
_name = "blog.post"
|
|
|
|
_description = "Blog Post"
|
2013-10-18 09:28:20 +00:00
|
|
|
_inherit = ['mail.thread', 'website.seo.metadata']
|
2014-03-22 17:53:29 +00:00
|
|
|
_order = 'id DESC'
|
2014-03-28 06:35:23 +00:00
|
|
|
|
|
|
|
def _compute_ranking(self, cr, uid, ids, name, arg, context=None):
|
|
|
|
res = {}
|
|
|
|
for blog_post in self.browse(cr, uid, ids, context=context):
|
2014-04-02 11:16:56 +00:00
|
|
|
age = datetime.now() - datetime.strptime(blog_post.create_date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
|
|
|
|
res[blog_post.id] = blog_post.visits * (0.5+random.random()) / max(3, age.days)
|
2014-03-28 06:35:23 +00:00
|
|
|
return res
|
|
|
|
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
_columns = {
|
2014-01-26 13:32:56 +00:00
|
|
|
'name': fields.char('Title', required=True, translate=True),
|
2014-04-02 11:16:56 +00:00
|
|
|
'subtitle': fields.char('Sub Title', translate=True),
|
2014-04-02 14:02:00 +00:00
|
|
|
'author_id': fields.many2one('res.partner', 'Author'),
|
2014-04-17 15:39:48 +00:00
|
|
|
'background_image': fields.binary('Background Image', oldname='content_image'),
|
2014-01-24 16:22:51 +00:00
|
|
|
'blog_id': fields.many2one(
|
|
|
|
'blog.blog', 'Blog',
|
2013-09-23 15:40:39 +00:00
|
|
|
required=True, ondelete='cascade',
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
),
|
|
|
|
'tag_ids': fields.many2many(
|
2013-09-23 15:56:05 +00:00
|
|
|
'blog.tag', string='Tags',
|
[REF] document_page: refactored the module, towards using it in website_blog
Main modifications:
- category is now a blog.catory object, instead of a document.page with type='category'
- added blog.tag model, to be able to tag posts
- cleaned document.page, now blog.post model, removing type and unnecessary features
- added chatter on blog.post, blog.category
- added subtypes to enable direct follow of posts when following a category
- updated document.page.history (now blog.post.history)
- commented menu creation, because this does not seem to be necessary anymore considering the new website
- updated wizard.document.page.history.show_diff, now blog.post.history.show_diff
- updated all views accordingly, as well as demo data
- removed the use of document_user group, simplified rules on blog.post (not done for new models)
- misc cleaning
Next step: merge with website_mail
bzr revid: tde@openerp.com-20130920111221-qy3x5eoyih26axn8
2013-09-20 11:12:21 +00:00
|
|
|
),
|
2014-07-23 15:10:02 +00:00
|
|
|
'content': fields.html('Content', translate=True, sanitize=False),
|
2013-09-20 14:27:01 +00:00
|
|
|
# website control
|
|
|
|
'website_published': fields.boolean(
|
2014-07-06 14:44:26 +00:00
|
|
|
'Publish', help="Publish on the website", copy=False,
|
2013-09-20 14:27:01 +00:00
|
|
|
),
|
2014-03-13 11:14:52 +00:00
|
|
|
'website_message_ids': fields.one2many(
|
|
|
|
'mail.message', 'res_id',
|
|
|
|
domain=lambda self: [
|
2014-04-03 11:26:56 +00:00
|
|
|
'&', '&', ('model', '=', self._name), ('type', '=', 'comment'), ('path', '=', False)
|
2014-03-13 11:14:52 +00:00
|
|
|
],
|
|
|
|
string='Website Messages',
|
|
|
|
help="Website communication history",
|
|
|
|
),
|
2014-03-28 08:50:55 +00:00
|
|
|
'history_ids': fields.one2many(
|
|
|
|
'blog.post.history', 'post_id',
|
|
|
|
'History', help='Last post modifications',
|
|
|
|
),
|
2013-09-20 13:12:26 +00:00
|
|
|
# creation / update stuff
|
2013-09-23 15:40:39 +00:00
|
|
|
'create_date': fields.datetime(
|
|
|
|
'Created on',
|
|
|
|
select=True, readonly=True,
|
|
|
|
),
|
|
|
|
'create_uid': fields.many2one(
|
|
|
|
'res.users', 'Author',
|
|
|
|
select=True, readonly=True,
|
|
|
|
),
|
|
|
|
'write_date': fields.datetime(
|
|
|
|
'Last Modified on',
|
|
|
|
select=True, readonly=True,
|
|
|
|
),
|
|
|
|
'write_uid': fields.many2one(
|
|
|
|
'res.users', 'Last Contributor',
|
|
|
|
select=True, readonly=True,
|
|
|
|
),
|
2014-10-28 13:12:39 +00:00
|
|
|
'author_avatar': fields.related(
|
|
|
|
'author_id', 'image_small',
|
|
|
|
string="Avatar", type="binary"),
|
2014-04-02 11:16:56 +00:00
|
|
|
'visits': fields.integer('No of Views'),
|
2014-03-28 06:35:23 +00:00
|
|
|
'ranking': fields.function(_compute_ranking, string='Ranking', type='float'),
|
2008-11-14 07:17:24 +00:00
|
|
|
}
|
2014-04-02 11:16:56 +00:00
|
|
|
|
2013-11-16 09:53:01 +00:00
|
|
|
_defaults = {
|
2014-04-02 11:16:56 +00:00
|
|
|
'name': _('Blog Post Title'),
|
|
|
|
'subtitle': _('Subtitle'),
|
2014-04-02 14:02:00 +00:00
|
|
|
'author_id': lambda self, cr, uid, ctx=None: self.pool['res.users'].browse(cr, uid, uid, context=ctx).partner_id.id,
|
2013-11-16 09:53:01 +00:00
|
|
|
}
|
2014-03-05 11:00:00 +00:00
|
|
|
|
2014-04-03 11:26:56 +00:00
|
|
|
def html_tag_nodes(self, html, attribute=None, tags=None, context=None):
|
|
|
|
""" Processing of html content to tag paragraphs and set them an unique
|
|
|
|
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
|
|
|
|
is None is the paragraph is a new one. """
|
2015-02-02 13:14:35 +00:00
|
|
|
|
|
|
|
existing_attributes = []
|
2014-04-03 11:26:56 +00:00
|
|
|
mapping = []
|
|
|
|
if not html:
|
|
|
|
return html, mapping
|
|
|
|
if tags is None:
|
|
|
|
tags = ['p']
|
|
|
|
if attribute is None:
|
|
|
|
attribute = 'data-unique-id'
|
|
|
|
|
|
|
|
# form a tree
|
|
|
|
root = lxml.html.fragment_fromstring(html, create_parent='div')
|
|
|
|
if not len(root) and root.text is None and root.tail is None:
|
|
|
|
return html, mapping
|
|
|
|
|
|
|
|
# check all nodes, replace :
|
|
|
|
# - img src -> check URL
|
|
|
|
# - a href -> check URL
|
|
|
|
for node in root.iter():
|
2015-02-02 13:14:35 +00:00
|
|
|
if node.tag not in tags:
|
2014-04-03 11:26:56 +00:00
|
|
|
continue
|
|
|
|
ancestor_tags = [parent.tag for parent in node.iterancestors()]
|
2015-02-02 13:14:35 +00:00
|
|
|
|
2014-04-03 11:26:56 +00:00
|
|
|
old_attribute = node.get(attribute)
|
2015-02-02 13:14:35 +00:00
|
|
|
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))
|
2014-04-03 11:26:56 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
if html.startswith('<div>') and html.endswith('</div>'):
|
|
|
|
html = html[5:-6]
|
|
|
|
return html, mapping
|
|
|
|
|
|
|
|
def _postproces_content(self, cr, uid, id, content=None, context=None):
|
|
|
|
if content is None:
|
|
|
|
content = self.browse(cr, uid, id, context=context).content
|
|
|
|
if content is False:
|
|
|
|
return content
|
2015-02-02 13:14:35 +00:00
|
|
|
|
2014-04-03 11:26:56 +00:00
|
|
|
content, mapping = self.html_tag_nodes(content, attribute='data-chatter-id', tags=['p'], context=context)
|
2015-02-02 13:14:35 +00:00
|
|
|
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),
|
2015-02-03 11:01:44 +00:00
|
|
|
('path', 'not in', existing),
|
|
|
|
('path', '!=', False)
|
2015-02-02 13:14:35 +00:00
|
|
|
], context=context)
|
|
|
|
self.pool['mail.message'].unlink(cr, SUPERUSER_ID, msg_ids, context=context)
|
|
|
|
|
2014-04-03 11:26:56 +00:00
|
|
|
return content
|
|
|
|
|
2014-03-28 08:50:55 +00:00
|
|
|
def create_history(self, cr, uid, ids, vals, context=None):
|
2014-12-24 14:12:47 +00:00
|
|
|
if isinstance(ids, (int, long)):
|
|
|
|
ids = [ids]
|
2014-03-28 08:50:55 +00:00
|
|
|
for i in ids:
|
|
|
|
history = self.pool.get('blog.post.history')
|
|
|
|
if vals.get('content'):
|
|
|
|
res = {
|
|
|
|
'content': vals.get('content', ''),
|
|
|
|
'post_id': i,
|
|
|
|
}
|
|
|
|
history.create(cr, uid, res)
|
|
|
|
|
2014-10-08 05:52:51 +00:00
|
|
|
def _check_for_publication(self, cr, uid, ids, vals, context=None):
|
|
|
|
if vals.get('website_published'):
|
|
|
|
base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url')
|
|
|
|
for post in self.browse(cr, uid, ids, context=context):
|
|
|
|
post.blog_id.message_post(
|
|
|
|
body='<p>%(post_publication)s <a href="%(base_url)s/blog/%(blog_slug)s/post/%(post_slug)s">%(post_link)s</a></p>' % {
|
|
|
|
'post_publication': _('A new post %s has been published on the %s blog.') % (post.name, post.blog_id.name),
|
|
|
|
'post_link': _('Click here to access the post.'),
|
|
|
|
'base_url': base_url,
|
|
|
|
'blog_slug': slug(post.blog_id),
|
|
|
|
'post_slug': slug(post),
|
|
|
|
},
|
|
|
|
subtype='website_blog.mt_blog_blog_published',
|
|
|
|
context=context)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-03-05 11:00:00 +00:00
|
|
|
def create(self, cr, uid, vals, context=None):
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
2014-04-03 11:26:56 +00:00
|
|
|
if 'content' in vals:
|
|
|
|
vals['content'] = self._postproces_content(cr, uid, None, vals['content'], context=context)
|
2014-03-05 11:00:00 +00:00
|
|
|
create_context = dict(context, mail_create_nolog=True)
|
2014-03-28 08:50:55 +00:00
|
|
|
post_id = super(BlogPost, self).create(cr, uid, vals, context=create_context)
|
|
|
|
self.create_history(cr, uid, [post_id], vals, context)
|
2014-10-08 05:52:51 +00:00
|
|
|
self._check_for_publication(cr, uid, [post_id], vals, context=context)
|
2014-03-28 08:50:55 +00:00
|
|
|
return post_id
|
|
|
|
|
|
|
|
def write(self, cr, uid, ids, vals, context=None):
|
2015-03-27 15:27:44 +00:00
|
|
|
if isinstance(ids, (int, long)):
|
|
|
|
ids = [ids]
|
2014-04-03 11:26:56 +00:00
|
|
|
if 'content' in vals:
|
2015-02-02 13:14:35 +00:00
|
|
|
vals['content'] = self._postproces_content(cr, uid, ids[0], vals['content'], context=context)
|
2014-03-28 08:50:55 +00:00
|
|
|
result = super(BlogPost, self).write(cr, uid, ids, vals, context)
|
|
|
|
self.create_history(cr, uid, ids, vals, context)
|
2014-10-08 05:52:51 +00:00
|
|
|
self._check_for_publication(cr, uid, ids, vals, context=context)
|
2014-03-28 08:50:55 +00:00
|
|
|
return result
|
2014-03-05 11:00:00 +00:00
|
|
|
|
2015-02-02 13:14:35 +00:00
|
|
|
|
2014-03-28 08:50:55 +00:00
|
|
|
class BlogPostHistory(osv.Model):
|
|
|
|
_name = "blog.post.history"
|
|
|
|
_description = "Blog Post History"
|
|
|
|
_order = 'id DESC'
|
|
|
|
_rec_name = "create_date"
|
|
|
|
|
|
|
|
_columns = {
|
|
|
|
'post_id': fields.many2one('blog.post', 'Blog Post'),
|
2014-05-21 09:52:05 +00:00
|
|
|
'summary': fields.char('Summary', select=True),
|
2014-03-28 08:50:55 +00:00
|
|
|
'content': fields.text("Content"),
|
|
|
|
'create_date': fields.datetime("Date"),
|
|
|
|
'create_uid': fields.many2one('res.users', "Modified By"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def getDiff(self, cr, uid, v1, v2, context=None):
|
|
|
|
history_pool = self.pool.get('blog.post.history')
|
|
|
|
text1 = history_pool.read(cr, uid, [v1], ['content'])[0]['content']
|
|
|
|
text2 = history_pool.read(cr, uid, [v2], ['content'])[0]['content']
|
|
|
|
line1 = line2 = ''
|
|
|
|
if text1:
|
|
|
|
line1 = text1.splitlines(1)
|
|
|
|
if text2:
|
|
|
|
line2 = text2.splitlines(1)
|
|
|
|
if (not line1 and not line2) or (line1 == line2):
|
|
|
|
raise osv.except_osv(_('Warning!'), _('There are no changes in revisions.'))
|
|
|
|
diff = difflib.HtmlDiff()
|
|
|
|
return diff.make_table(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=True)
|