diff options
| author | ajay javiya (OpenERP) <aja@tinyerp.com> | 2014-03-28 14:20:55 +0530 |
|---|---|---|
| committer | ajay javiya (OpenERP) <aja@tinyerp.com> | 2014-03-28 14:20:55 +0530 |
| commit | a5d783cf82dfe8f143264fb5cb8a70f616d8348d (patch) | |
| tree | 4f0d713bac7aa6bca16126df9bda2fd7c6a9fb00 | |
| parent | 660c812786980ede0b2a4af9e0ac727f99e6c70b (diff) | |
[ADD] : history feature
bzr revid: aja@tinyerp.com-20140328085055-kw0pplobbla2emjd
| -rw-r--r-- | addons/website_blog/__init__.py | 1 | ||||
| -rw-r--r-- | addons/website_blog/__openerp__.py | 5 | ||||
| -rw-r--r-- | addons/website_blog/models/website_blog.py | 57 | ||||
| -rw-r--r-- | addons/website_blog/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | addons/website_blog/tests/test_website_blog.yml | 33 | ||||
| -rw-r--r-- | addons/website_blog/views/website_blog_views.xml | 43 | ||||
| -rw-r--r-- | addons/website_blog/wizard/__init__.py | 24 | ||||
| -rw-r--r-- | addons/website_blog/wizard/document_page_show_diff.py | 61 | ||||
| -rw-r--r-- | addons/website_blog/wizard/document_page_show_diff_view.xml | 39 |
9 files changed, 261 insertions, 3 deletions
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 @@ </record> <menuitem id="menu_blog" parent="menu_wiki" name="Blogs" action="action_blog_blog" sequence="20"/> + <!-- History Tree view --> + <record model="ir.ui.view" id="view_blog_history_tree"> + <field name="name">blog.post.history.tree</field> + <field name="model">blog.post.history</field> + <field name="arch" type="xml"> + <tree string="Document History"> + <field name="create_date"/> + <field name="create_uid"/> + <field name="post_id"/> + </tree> + </field> + </record> + <!-- History Form view --> + <record model="ir.ui.view" id="view_blog_history_form"> + <field name="name">blog.post.history.form</field> + <field name="model">blog.post.history</field> + <field name="arch" type="xml"> + <form string="Blog Post History" version="7.0"> + <label for="post_id" class="oe_edit_only"/> + <h1><field name="post_id" select="1" /></h1> + <label for="create_date" class="oe_edit_only"/> + <field name="create_date" readonly="1"/> + <label for="content" class="oe_edit_only"/> + <field name="content" colspan="4"/> + </form> + </field> + </record> + <!-- History Action --> + <record model="ir.actions.act_window" id="action_history"> + <field name="name">Page history</field> + <field name="res_model">blog.post.history</field> + <field name="view_type">form</field> + <field name="view_mode">tree,form</field> + </record> + <menuitem id="menu_page_history" parent="menu_wiki" name="Pages history" action="action_history" sequence="30" groups="base.group_no_one"/> + <act_window + id="action_related_page_history" + context="{'search_default_post_id': [active_id], 'default_post_id': active_id}" + domain="[('post_id','=',active_id)]" + name="Page History" + res_model="blog.post.history" + src_model="blog.post"/> + </data> </openerp> 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 (<http://tiny.be>). +# +# 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 <http://www.gnu.org/licenses/>. +# +############################################################################## + +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 (<http://tiny.be>). +# +# 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 <http://www.gnu.org/licenses/>. +# +############################################################################## + +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 @@ +<?xml version="1.0" encoding="utf-8"?> +<openerp> + <data> + + <!-- Create Index Form view --> + <record id="view_wiki_show_diff" model="ir.ui.view"> + <field name="name">Show Difference</field> + <field name="model">blog.post.history.show_diff</field> + <field name="arch" type="xml"> + <form string="Difference" version="7.0"> + <field name="diff" widget="html" options='{"safe": True}'/> + <footer> + <button string="Cancel" class="oe_link" special="cancel" /> + </footer> + </form> + </field> + </record> + <!-- Create Index Action --> + <record id="action_view_wiki_show_diff" model="ir.actions.act_window"> + <field name="name">Difference</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">blog.post.history.show_diff</field> + <field name="view_type">form</field> + <field name="view_mode">form</field> + <field name="target">new</field> + </record> + <!-- Create Index Action Window --> + <act_window + id="action_view_wiki_show_diff_values" + key2="client_action_multi" + name="Difference" + res_model="blog.post.history.show_diff" + src_model="blog.post.history" + view_mode="form" + target="new" + view_type="form"/> + + </data> +</openerp> |
