[ADD] : history feature

bzr revid: aja@tinyerp.com-20140328085055-kw0pplobbla2emjd
This commit is contained in:
ajay javiya (OpenERP) 2014-03-28 14:20:55 +05:30
parent 660c812786
commit a5d783cf82
9 changed files with 261 additions and 3 deletions

View File

@ -21,3 +21,4 @@
import controllers
import models
import wizard

View File

@ -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'
],

View File

@ -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)

View File

@ -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

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 blog_blog_all blog.blog model_blog_blog 1 0 0 0
3 blog_post_all blog.post model_blog_post 1 0 0 0
4 blog_post blog.post model_blog_post base.group_document_user 1 1 1 1
5 blog_post_history blog.post.history model_blog_post_history base.group_document_user 1 0 1 0
6 blog_tag blog.tag model_blog_tag 1 0 0 0
7 blog_tag_edition blog.tag model_blog_tag base.group_document_user 1 1 1 1

View File

@ -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[:] })

View File

@ -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>

View File

@ -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:

View File

@ -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:

View File

@ -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>