diff --git a/addons/website_blog/__init__.py b/addons/website_blog/__init__.py
index 708d6ce4669..2d542504c81 100644
--- a/addons/website_blog/__init__.py
+++ b/addons/website_blog/__init__.py
@@ -21,3 +21,4 @@
import controllers
import models
+import wizard
diff --git a/addons/website_blog/__openerp__.py b/addons/website_blog/__openerp__.py
index c03ca7aac78..97c163945af 100644
--- a/addons/website_blog/__openerp__.py
+++ b/addons/website_blog/__openerp__.py
@@ -35,13 +35,16 @@ OpenERP Blog
'data/website_blog_data.xml',
'views/website_blog_views.xml',
'views/website_blog_templates.xml',
+ 'wizard/document_page_show_diff_view.xml',
'security/ir.model.access.csv',
'security/website_blog.xml',
],
'demo': [
'data/website_blog_demo.xml'
],
- 'test': [],
+ 'test': [
+ 'tests/test_website_blog.yml'
+ ],
'qweb': [
'static/src/xml/*.xml'
],
diff --git a/addons/website_blog/models/website_blog.py b/addons/website_blog/models/website_blog.py
index 2d1d4ac6030..00ede434fe9 100644
--- a/addons/website_blog/models/website_blog.py
+++ b/addons/website_blog/models/website_blog.py
@@ -92,6 +92,11 @@ class BlogPost(osv.Model):
string='Website Messages',
help="Website communication history",
),
+ 'history_ids': fields.one2many(
+ 'blog.post.history', 'post_id',
+ 'History', help='Last post modifications',
+ deprecated= 'Will be removed in v9.'
+ ),
# creation / update stuff
'create_date': fields.datetime(
'Created on',
@@ -118,16 +123,64 @@ class BlogPost(osv.Model):
'ranking': 0
}
+ def create_history(self, cr, uid, ids, vals, context=None):
+ 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)
+
def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
create_context = dict(context, mail_create_nolog=True)
- return super(BlogPost, self).create(cr, uid, vals, context=create_context)
+ post_id = super(BlogPost, self).create(cr, uid, vals, context=create_context)
+ self.create_history(cr, uid, [post_id], vals, context)
+ return post_id
+
+ def write(self, cr, uid, ids, vals, context=None):
+ result = super(BlogPost, self).write(cr, uid, ids, vals, context)
+ self.create_history(cr, uid, ids, vals, context)
+ return result
def copy(self, cr, uid, id, default=None, context=None):
- default = default or {}
+ if default is None:
+ default = {}
default.update({
+ 'website_message_ids': [],
'website_published': False,
+ 'website_published_datetime': False,
})
return super(BlogPost, self).copy(cr, uid, id, default=default, context=context)
+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'),
+ 'summary': fields.char('Summary', size=256, select=True),
+ '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)
+
diff --git a/addons/website_blog/security/ir.model.access.csv b/addons/website_blog/security/ir.model.access.csv
index 1ca50fc0c2c..cb0498a958b 100644
--- a/addons/website_blog/security/ir.model.access.csv
+++ b/addons/website_blog/security/ir.model.access.csv
@@ -2,5 +2,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
blog_blog_all,blog.blog,model_blog_blog,,1,0,0,0
blog_post_all,blog.post,model_blog_post,,1,0,0,0
blog_post,blog.post,model_blog_post,base.group_document_user,1,1,1,1
+blog_post_history,blog.post.history,model_blog_post_history,base.group_document_user,1,0,1,0
blog_tag,blog.tag,model_blog_tag,,1,0,0,0
blog_tag_edition,blog.tag,model_blog_tag,base.group_document_user,1,1,1,1
diff --git a/addons/website_blog/tests/test_website_blog.yml b/addons/website_blog/tests/test_website_blog.yml
new file mode 100644
index 00000000000..db70b286bc8
--- /dev/null
+++ b/addons/website_blog/tests/test_website_blog.yml
@@ -0,0 +1,33 @@
+-
+ In order to test the document_page in OpenERP, I create a new page to blog blog_blog_1
+-
+ !record {model: blog.post, id: test_page0}:
+ name: Test Page0
+ blog_id: blog_blog_1
+ content: 'Test content
+
+ The Open ERP wiki allows you to manage your enterprise contents using wiki
+
+ restructured texts. This module provides a collaborative way to manage internal
+
+ FAQs, quality manuals, technical references, etc.'
+
+-
+ !record {model: blog.post, id: test_page0}:
+ content: 'Test updated content
+
+ The Open ERP wiki allows you to manage your enterprise contents using wiki
+
+ restructured texts. This module provides a collaborative way to manage internal
+
+ FAQs, quality manuals, technical references, etc.
+
+ Wiki text can easily be edited
+ '
+-
+ I check the page history for the current page by clicking on "Page History".After that find difference between history.
+-
+ !python {model: blog.post.history.show_diff}: |
+ hist_obj = model.pool.get('blog.post.history')
+ ids = hist_obj.search(cr, uid, [('post_id', '=', ref("test_page0"))])
+ model.get_diff(cr, uid, {'active_ids': ids[:] })
diff --git a/addons/website_blog/views/website_blog_views.xml b/addons/website_blog/views/website_blog_views.xml
index 78d6b73f818..52528dcaa46 100644
--- a/addons/website_blog/views/website_blog_views.xml
+++ b/addons/website_blog/views/website_blog_views.xml
@@ -119,5 +119,48 @@
+
+
+ blog.post.history.tree
+ blog.post.history
+
+
+
+
+
+
+
+
+
+
+ blog.post.history.form
+ blog.post.history
+
+
+
+
+
+
+ Page history
+ blog.post.history
+ form
+ tree,form
+
+
+
+
diff --git a/addons/website_blog/wizard/__init__.py b/addons/website_blog/wizard/__init__.py
new file mode 100644
index 00000000000..1c7a3a5b458
--- /dev/null
+++ b/addons/website_blog/wizard/__init__.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+import document_page_show_diff
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/website_blog/wizard/document_page_show_diff.py b/addons/website_blog/wizard/document_page_show_diff.py
new file mode 100644
index 00000000000..49056fd826b
--- /dev/null
+++ b/addons/website_blog/wizard/document_page_show_diff.py
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+##############################################################################
+
+from openerp.osv import fields, osv
+from openerp.tools.translate import _
+
+
+class showdiff(osv.osv_memory):
+ """ Disp[ay Difference for History """
+
+ _name = 'blog.post.history.show_diff'
+
+ def get_diff(self, cr, uid, context=None):
+ if context is None:
+ context = {}
+ history = self.pool.get('blog.post.history')
+ ids = context.get('active_ids', [])
+
+ diff = ""
+ if len(ids) == 2:
+ if ids[0] > ids[1]:
+ diff = history.getDiff(cr, uid, ids[1], ids[0])
+ else:
+ diff = history.getDiff(cr, uid, ids[0], ids[1])
+
+ elif len(ids) == 1:
+ old = history.browse(cr, uid, ids[0])
+ nids = history.search(cr, uid, [('post_id', '=', old.post_id.id)])
+ nids.sort()
+ diff = history.getDiff(cr, uid, ids[0], nids[-1])
+ else:
+ raise osv.except_osv(_('Warning!'), _('You need to select minimum one or maximum two history revisions!'))
+ return diff
+
+ _columns = {
+ 'diff': fields.text('Diff', readonly=True),
+ }
+
+ _defaults = {
+ 'diff': get_diff
+ }
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/website_blog/wizard/document_page_show_diff_view.xml b/addons/website_blog/wizard/document_page_show_diff_view.xml
new file mode 100644
index 00000000000..3693af7caad
--- /dev/null
+++ b/addons/website_blog/wizard/document_page_show_diff_view.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+ Show Difference
+ blog.post.history.show_diff
+
+
+
+
+
+
+ Difference
+ ir.actions.act_window
+ blog.post.history.show_diff
+ form
+ form
+ new
+
+
+
+
+
+