1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-Today OpenERP SA (<http://www.openerp.com>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp.osv import fields, osv
23 from openerp.tools.translate import _
27 class BlogCategory(osv.Model):
28 _name = 'blog.category'
29 _description = 'Blog Category'
30 _inherit = ['mail.thread']
34 'name': fields.char('Name', required=True),
35 'description': fields.text('Description'),
36 'template': fields.text('Template'),
37 'blog_ids': fields.one2many(
38 'blog.post', 'category_id',
44 class BlogTag(osv.Model):
46 _description = 'Blog Tag'
50 'name': fields.char('Name', required=True),
54 class BlogPost(osv.Model):
56 _description = "Blog Post"
57 _inherit = ['mail.thread']
61 'name': fields.char('Title', required=True),
62 'category_id': fields.many2one(
63 'blog.category', 'Category',
66 'tag_ids': fields.many2many(
67 'blog.tag', 'blog_tag_rel',
71 'content': fields.text('Content'),
72 # technical stuff: history, menu (to keep ?)
73 'history_ids': fields.one2many(
74 'blog.post.history', 'post_id',
75 'History', help='Last post modifications'
77 'menu_id': fields.many2one('ir.ui.menu', "Menu", readonly=True),
78 # creation / update stuff
79 'create_date': fields.datetime("Created on", select=True, readonly=True),
80 'create_uid': fields.many2one('res.users', 'Author', select=True, readonly=True),
81 'write_date': fields.datetime("last Modified on", select=True, readonly=True),
82 'write_uid': fields.many2one('res.users', "Last Contributor", select=True, readonly=True),
85 def create_history(self, cr, uid, ids, vals, context=None):
87 history = self.pool.get('blog.post.history')
88 if vals.get('content'):
90 'content': vals.get('content', ''),
93 history.create(cr, uid, res)
95 def create(self, cr, uid, vals, context=None):
98 create_context = dict(context, mail_create_nolog=True)
99 post_id = super(BlogPost, self).create(cr, uid, vals, context=create_context)
100 self.create_history(cr, uid, [post_id], vals, context)
103 def write(self, cr, uid, ids, vals, context=None):
104 result = super(BlogPost, self).write(cr, uid, ids, vals, context)
105 self.create_history(cr, uid, ids, vals, context)
109 class BlogPostHistory(osv.Model):
110 _name = "blog.post.history"
111 _description = "Document Page History"
113 _rec_name = "create_date"
116 'post_id': fields.many2one('blog.post', 'Blog Post'),
117 'summary': fields.char('Summary', size=256, select=True),
118 'content': fields.text("Content"),
119 'create_date': fields.datetime("Date"),
120 'create_uid': fields.many2one('res.users', "Modified By"),
123 def getDiff(self, cr, uid, v1, v2, context=None):
124 history_pool = self.pool.get('document.page.history')
125 text1 = history_pool.read(cr, uid, [v1], ['content'])[0]['content']
126 text2 = history_pool.read(cr, uid, [v2], ['content'])[0]['content']
129 line1 = text1.splitlines(1)
131 line2 = text2.splitlines(1)
132 if (not line1 and not line2) or (line1 == line2):
133 raise osv.except_osv(_('Warning!'), _('There are no changes in revisions.'))
134 diff = difflib.HtmlDiff()
135 return diff.make_table(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=True)
137 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: