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
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
2010-07-12 06:39:51 +00:00
|
|
|
|
|
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):
|
|
|
|
|
""" document.page """
|
|
|
|
|
_name = "document.page"
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
document_page()
|
2008-12-05 14:54:49 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
class document_page_type(osv.osv):
|
|
|
|
|
""" document page type """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
_name = "document.page.type"
|
|
|
|
|
_description = "Document page type"
|
2008-11-21 12:53:55 +00:00
|
|
|
|
_order = 'name'
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
|
|
_columns = {
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'name':fields.char('Document Page Type', size=256, select=True, required=True),
|
|
|
|
|
'page_ids':fields.one2many('document.page', 'parent_id', 'Pages'),
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'notes':fields.text("Description"),
|
|
|
|
|
'create_date':fields.datetime("Created Date", select=True),
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'content_template': fields.text('Document Page Template'),
|
2010-03-17 08:36:08 +00:00
|
|
|
|
'method':fields.selection([('list', 'List'), ('page', 'Home Page'), \
|
2010-09-16 17:52:58 +00:00
|
|
|
|
('tree', 'Tree')], 'Display Method', help="Define the default behaviour of the menu created on this group"),
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'home':fields.many2one('document.page', 'Home Page', help="Required to select home page if display method is Home Page"),
|
2010-07-12 06:39:51 +00:00
|
|
|
|
'menu_id': fields.many2one('ir.ui.menu', "Menu", readonly=True),
|
2009-09-24 10:46:21 +00:00
|
|
|
|
}
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2009-09-24 10:46:21 +00:00
|
|
|
|
_defaults = {
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'method': lambda *a: 'page',
|
2008-11-14 07:17:24 +00:00
|
|
|
|
}
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
def open_document_page(self, cr, uid, ids, context=None):
|
2010-07-12 06:39:51 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
""" Opens document Page of Group
|
2010-07-12 06:39:51 +00:00
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2012-08-03 15:46:41 +00:00
|
|
|
|
@param ids: List of open document group’s IDs
|
|
|
|
|
@return: dictionay of open Document window on give group id
|
2010-07-12 06:39:51 +00:00
|
|
|
|
"""
|
|
|
|
|
if type(ids) in (int,long,):
|
|
|
|
|
ids = [ids]
|
|
|
|
|
group_id = False
|
|
|
|
|
if ids:
|
|
|
|
|
group_id = ids[0]
|
|
|
|
|
if not group_id:
|
|
|
|
|
return {}
|
2010-09-17 04:09:40 +00:00
|
|
|
|
value = {
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'name': 'Document Page',
|
2010-07-12 06:39:51 +00:00
|
|
|
|
'view_type': 'form',
|
|
|
|
|
'view_mode': 'form,tree',
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'res_model': 'document.page',
|
2010-07-12 06:39:51 +00:00
|
|
|
|
'view_id': False,
|
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
|
'nodestroy': True,
|
|
|
|
|
}
|
|
|
|
|
group = self.browse(cr, uid, group_id, context=context)
|
2012-08-03 15:46:41 +00:00
|
|
|
|
value['domain'] = "[('parent_id','=',%d)]" % (group.id)
|
2010-07-12 06:39:51 +00:00
|
|
|
|
if group.method == 'page':
|
|
|
|
|
value['res_id'] = group.home.id
|
|
|
|
|
elif group.method == 'list':
|
|
|
|
|
value['view_type'] = 'form'
|
|
|
|
|
value['view_mode'] = 'tree,form'
|
|
|
|
|
elif group.method == 'tree':
|
2012-08-03 15:46:41 +00:00
|
|
|
|
view_id = self.pool.get('ir.ui.view').search(cr, uid, [('name', '=', 'document.page.tree.children')])
|
2010-07-12 06:39:51 +00:00
|
|
|
|
value['view_id'] = view_id
|
2012-08-03 15:46:41 +00:00
|
|
|
|
value['domain'] = [('parent_id', '=', group.id)]
|
2010-07-12 06:39:51 +00:00
|
|
|
|
value['view_type'] = 'tree'
|
2012-08-03 15:46:41 +00:00
|
|
|
|
value['view_mode'] = 'tree'
|
2010-07-12 06:39:51 +00:00
|
|
|
|
|
|
|
|
|
return value
|
2012-08-03 15:46:41 +00:00
|
|
|
|
document_page_type()
|
2008-11-14 07:17:24 +00:00
|
|
|
|
|
2010-03-16 14:01:43 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
class document_page2(osv.osv):
|
|
|
|
|
""" Document Page """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
_inherit = "document.page"
|
|
|
|
|
_description = "Document Page"
|
|
|
|
|
_order = 'create_date desc'
|
|
|
|
|
|
2010-03-17 08:36:08 +00:00
|
|
|
|
_columns = {
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'name': fields.char('Title', size=256, select=True, required=True),
|
2010-06-30 15:21:41 +00:00
|
|
|
|
'write_uid': fields.many2one('res.users', "Last Contributor", select=True),
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'content': fields.text("Content"),
|
|
|
|
|
'index': fields.char('Index', size=256),
|
2010-10-11 10:17:26 +00:00
|
|
|
|
'create_uid': fields.many2one('res.users', 'Author', select=True, readonly=True),
|
|
|
|
|
'create_date': fields.datetime("Created on", select=True, readonly=True),
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'content_template': fields.text('Document Template'),
|
2010-10-11 10:17:26 +00:00
|
|
|
|
'write_date': fields.datetime("Modification Date", select=True, readonly=True),
|
2010-09-16 17:52:58 +00:00
|
|
|
|
'tags': fields.char('Keywords', size=1024, select=True),
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'history_ids': fields.one2many('document.page.history', 'document_id', 'History Lines'),
|
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),
|
|
|
|
|
'type':fields.selection([('normal','Content Page'), ('index','Index Page')], 'Type', help="Define the type of the document"),
|
2010-07-12 06:39:51 +00:00
|
|
|
|
'review': fields.boolean('Needs Review', select=True,
|
2010-06-30 15:19:35 +00:00
|
|
|
|
help="Indicates that this page should be reviewed, raising the attention of other contributors"),
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'parent_id': fields.many2one('document.page.type', 'Parent Page', select=1 , ondelete='set null', help="Allows you to link with the topic"),
|
|
|
|
|
'child_ids': fields.one2many('document.page', 'parent_id', 'Child Pages'),
|
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',
|
2011-11-24 12:14:33 +00:00
|
|
|
|
'review': True,
|
|
|
|
|
'minor_edit': True,
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'index' : 1,
|
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):
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
|
|
""" @param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2012-08-03 15:46:41 +00:00
|
|
|
|
@param ids: List of document page’s IDs
|
|
|
|
|
@return: dictionay of open document page on give page section """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
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 {}
|
|
|
|
|
|
2009-02-04 13:12:10 +00:00
|
|
|
|
def copy_data(self, cr, uid, id, default=None, context=None):
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
|
|
""" @param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2012-08-03 15:46:41 +00:00
|
|
|
|
@param id: Give document page's ID """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
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 = {
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'minor_edit': vals.get('minor_edit', True),
|
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):
|
|
|
|
|
|
|
|
|
|
""" @param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks, """
|
2012-08-03 15:46:41 +00:00
|
|
|
|
document_id = super(document_page2, self).create(cr, uid,
|
2010-10-05 12:17:32 +00:00
|
|
|
|
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):
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
|
|
""" @param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks, """
|
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
|
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
document_page2()
|
2008-11-14 07:17:24 +00:00
|
|
|
|
|
2010-03-16 14:01:43 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
class document_page_history(osv.osv):
|
|
|
|
|
""" Document Page History """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
_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 = {
|
2010-08-13 12:20:05 +00:00
|
|
|
|
'create_date': fields.datetime("Date", select=True),
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'content': fields.text("Content"),
|
2010-08-13 12:20:05 +00:00
|
|
|
|
'minor_edit': fields.boolean('This is a major edit ?', select=True),
|
|
|
|
|
'summary': fields.char('Summary', size=256, select=True),
|
|
|
|
|
'write_uid': fields.many2one('res.users', "Modify By", select=True),
|
2012-08-03 15:46:41 +00:00
|
|
|
|
'document_id': fields.many2one('document.page', 'Document Page', select=True)
|
2010-08-13 12:20:05 +00:00
|
|
|
|
}
|
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):
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
|
|
""" @param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks, """
|
|
|
|
|
|
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
|
|
|
|
|
2012-08-03 15:46:41 +00:00
|
|
|
|
document_page_history()
|
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:
|