2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-11-14 07:17:24 +00:00
|
|
|
##############################################################################
|
|
|
|
#
|
2010-07-12 06:39:51 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-11-14 07:17:24 +00:00
|
|
|
#
|
2010-07-12 06:39:51 +00:00
|
|
|
# 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.
|
2008-11-14 07:17:24 +00:00
|
|
|
#
|
2010-07-12 06:39:51 +00:00
|
|
|
# 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.
|
2008-11-14 07:17:24 +00:00
|
|
|
#
|
2010-07-12 06:39:51 +00:00
|
|
|
# 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/>.
|
2008-11-14 07:17:24 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
from osv import fields, osv
|
2010-04-12 13:27:25 +00:00
|
|
|
from tools.translate import _
|
2010-03-17 08:36:08 +00:00
|
|
|
import difflib
|
2011-03-09 06:08:47 +00:00
|
|
|
import tools
|
2008-11-14 07:17:24 +00:00
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
class document_page(osv.osv):
|
2012-08-03 17:17:59 +00:00
|
|
|
_inherit = "document.page"
|
|
|
|
_description = "Document Page"
|
2008-11-21 12:53:55 +00:00
|
|
|
_order = 'name'
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
_columns = {
|
2012-08-03 17:17:59 +00:00
|
|
|
'name': fields.char('Title', size=256, select=True, required=True),
|
|
|
|
'type':fields.selection([('normal','Content Page'), ('index','Index Page')], 'Type', help="Define the type of the document"),
|
2010-03-17 08:36:08 +00:00
|
|
|
|
2012-08-03 17:17:59 +00:00
|
|
|
'parent_id': fields.many2one('document.page', 'Section', select=1 , ondelete='set null'),
|
|
|
|
'child_ids': fields.one2many('document.page', 'parent_id', 'Children'),
|
2010-03-17 08:36:08 +00:00
|
|
|
|
2012-08-03 17:17:59 +00:00
|
|
|
'display_content': fields.text('Displayed Content'),
|
2012-08-03 15:46:41 +00:00
|
|
|
'content': fields.text("Content"),
|
2012-08-03 17:17:59 +00:00
|
|
|
'history_ids': fields.one2many('document.page.history', 'document_id', 'History'),
|
|
|
|
'menu_id': fields.many2one('ir.ui.menu', "Menu", readonly=True),
|
|
|
|
|
2010-10-11 10:17:26 +00:00
|
|
|
'create_date': fields.datetime("Created on", select=True, readonly=True),
|
|
|
|
'write_date': fields.datetime("Modification Date", select=True, readonly=True),
|
2012-08-03 17:17:59 +00:00
|
|
|
'write_uid': fields.many2one('res.users', "Last Contributor", select=True),
|
|
|
|
'create_uid': fields.many2one('res.users', 'Author', select=True, readonly=True),
|
|
|
|
|
|
|
|
'index': fields.char('Index', size=256),
|
2010-04-12 12:41:47 +00:00
|
|
|
'minor_edit': fields.boolean('Minor edit', select=True),
|
2012-08-03 15:46:41 +00:00
|
|
|
'edit_summary': fields.char('Summary', size=256),
|
2012-08-03 17:17:59 +00:00
|
|
|
'tags': fields.char('Keywords', size=1024, select=True),
|
|
|
|
|
2008-11-14 07:17:24 +00:00
|
|
|
}
|
2010-09-16 17:52:58 +00:00
|
|
|
_defaults = {
|
2012-08-03 15:46:41 +00:00
|
|
|
'type':'normal',
|
2010-09-16 17:52:58 +00:00
|
|
|
}
|
2010-03-16 14:01:43 +00:00
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
def onchange_parent_id(self, cr, uid, ids, parent_id, content, context=None):
|
|
|
|
if (not parent_id) or content:
|
2008-11-21 17:15:13 +00:00
|
|
|
return {}
|
2012-08-03 15:46:41 +00:00
|
|
|
grp = self.pool.get('document.page.type').browse(cr, uid, parent_id, context=context)
|
|
|
|
template = grp.content_template
|
2008-11-21 17:22:36 +00:00
|
|
|
try:
|
|
|
|
s[-1] = str(int(s[-1])+1)
|
|
|
|
except:
|
|
|
|
pass
|
2008-11-21 17:15:13 +00:00
|
|
|
return {
|
|
|
|
'value':{
|
2012-08-03 15:46:41 +00:00
|
|
|
'content': template,
|
2008-11-21 17:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-17 08:36:08 +00:00
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
def onchange_content(self, cr, uid, ids, content, context=None):
|
|
|
|
if content:
|
|
|
|
return {'value':{'summary': content}}
|
|
|
|
return {}
|
2010-03-17 08:36:08 +00:00
|
|
|
|
2012-08-03 17:17:59 +00:00
|
|
|
def copy_data(self, cr, uid, id, default=None, context=None):
|
2012-08-03 15:46:41 +00:00
|
|
|
return super(document_page2, self).copy_data(cr, uid, id, {'document_id': False}, context)
|
2010-09-17 04:09:40 +00:00
|
|
|
|
2010-09-16 17:52:58 +00:00
|
|
|
def create_history(self, cr, uid, ids, vals, context=None):
|
|
|
|
history_id = False
|
2012-08-03 15:46:41 +00:00
|
|
|
history = self.pool.get('document.page.history')
|
|
|
|
if vals.get('content'):
|
2010-03-17 08:36:08 +00:00
|
|
|
res = {
|
2012-08-03 15:46:41 +00:00
|
|
|
'content': vals.get('content', ''),
|
2010-04-12 12:41:47 +00:00
|
|
|
'write_uid': uid,
|
2012-08-03 15:46:41 +00:00
|
|
|
'document_id': ids[0],
|
|
|
|
'summary':vals.get('edit_summary', '')
|
2009-03-19 06:28:58 +00:00
|
|
|
}
|
2010-09-16 17:52:58 +00:00
|
|
|
history_id = history.create(cr, uid, res)
|
|
|
|
return history_id
|
2010-09-17 04:09:40 +00:00
|
|
|
|
2010-09-16 17:52:58 +00:00
|
|
|
def create(self, cr, uid, vals, context=None):
|
2012-08-03 17:17:59 +00:00
|
|
|
document_id = super(document_page2, self).create(cr, uid, vals, context)
|
2012-08-03 15:46:41 +00:00
|
|
|
self.create_history(cr, uid, [document_id], vals, context)
|
|
|
|
return document_id
|
2009-03-19 06:28:58 +00:00
|
|
|
|
2008-11-14 07:17:24 +00:00
|
|
|
def write(self, cr, uid, ids, vals, context=None):
|
2012-08-03 15:46:41 +00:00
|
|
|
result = super(document_page2, self).write(cr, uid, ids, vals, context)
|
2010-09-16 17:52:58 +00:00
|
|
|
self.create_history(cr, uid, ids, vals, context)
|
2008-11-24 06:49:47 +00:00
|
|
|
return result
|
|
|
|
|
2010-03-16 14:01:43 +00:00
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
class document_page_history(osv.osv):
|
|
|
|
_name = "document.page.history"
|
|
|
|
_description = "Document Page History"
|
2010-08-30 07:54:08 +00:00
|
|
|
_rec_name = "summary"
|
2008-11-14 07:17:24 +00:00
|
|
|
_order = 'id DESC'
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
_columns = {
|
2012-08-03 17:17:59 +00:00
|
|
|
'document_id': fields.many2one('document.page', 'Document Page', select=True)
|
2010-08-13 12:20:05 +00:00
|
|
|
'summary': fields.char('Summary', size=256, select=True),
|
2012-08-03 17:17:59 +00:00
|
|
|
'content': fields.text("Content"),
|
|
|
|
'create_date': fields.datetime("Date", select=True),
|
2010-08-13 12:20:05 +00:00
|
|
|
'write_uid': fields.many2one('res.users', "Modify By", select=True),
|
|
|
|
}
|
2010-03-17 08:36:08 +00:00
|
|
|
|
2008-11-14 07:17:24 +00:00
|
|
|
_defaults = {
|
2010-04-12 12:41:47 +00:00
|
|
|
'write_uid': lambda obj, cr, uid, context: uid,
|
2008-11-14 07:17:24 +00:00
|
|
|
}
|
2010-03-16 14:01:43 +00:00
|
|
|
|
2010-09-01 11:58:23 +00:00
|
|
|
def getDiff(self, cr, uid, v1, v2, context=None):
|
2012-08-03 15:46:41 +00:00
|
|
|
history_pool = self.pool.get('document.page.history')
|
|
|
|
text1 = history_pool.read(cr, uid, [v1], ['content'])[0]['content']
|
|
|
|
text2 = history_pool.read(cr, uid, [v2], ['content'])[0]['content']
|
2010-08-30 07:54:08 +00:00
|
|
|
line1 = line2 = ''
|
|
|
|
if text1:
|
2011-03-09 06:08:47 +00:00
|
|
|
line1 = tools.ustr(text1.splitlines(1))
|
2010-08-30 07:54:08 +00:00
|
|
|
if text2:
|
2011-03-09 06:08:47 +00:00
|
|
|
line2=tools.ustr(text2.splitlines(1))
|
2010-08-30 07:54:08 +00:00
|
|
|
if (not line1 and not line2) or (line1 == line2):
|
2010-09-01 11:58:23 +00:00
|
|
|
raise osv.except_osv(_('Warning !'), _('There are no changes in revisions'))
|
2008-11-14 07:17:24 +00:00
|
|
|
diff = difflib.HtmlDiff()
|
|
|
|
return diff.make_file(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=False)
|
2010-03-16 14:01:43 +00:00
|
|
|
|
|
|
|
|
2009-03-06 22:18:24 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|