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
|
2008-11-14 07:17:24 +00:00
|
|
|
|
|
2008-12-05 14:54:49 +00:00
|
|
|
|
class Wiki(osv.osv):
|
2010-03-17 08:36:08 +00:00
|
|
|
|
""" wiki """
|
|
|
|
|
_name = "wiki.wiki"
|
|
|
|
|
|
2008-12-05 14:54:49 +00:00
|
|
|
|
Wiki()
|
|
|
|
|
|
2008-11-21 15:09:23 +00:00
|
|
|
|
class WikiGroup(osv.osv):
|
2010-03-16 14:01:43 +00:00
|
|
|
|
""" Wiki Groups """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2008-11-21 15:09:23 +00:00
|
|
|
|
_name = "wiki.groups"
|
2010-03-17 08:36:08 +00:00
|
|
|
|
_description = "Wiki Groups"
|
2008-11-21 12:53:55 +00:00
|
|
|
|
_order = 'name'
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
|
|
_columns = {
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'name':fields.char('Wiki Group', size=256, select=True, required=True),
|
|
|
|
|
'page_ids':fields.one2many('wiki.wiki', 'group_id', 'Pages'),
|
|
|
|
|
'notes':fields.text("Description"),
|
|
|
|
|
'create_date':fields.datetime("Created Date", select=True),
|
|
|
|
|
'template': fields.text('Wiki Template'),
|
|
|
|
|
'section': fields.boolean("Make Section ?"),
|
2010-03-17 08:36:08 +00:00
|
|
|
|
'method':fields.selection([('list', 'List'), ('page', 'Home Page'), \
|
2010-04-12 12:41:47 +00:00
|
|
|
|
('tree', 'Tree')], 'Display Method'),
|
|
|
|
|
'home':fields.many2one('wiki.wiki', '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
|
|
|
|
|
2010-07-12 06:39:51 +00:00
|
|
|
|
def open_wiki_page(self, cr, uid, ids, context):
|
|
|
|
|
|
|
|
|
|
""" Opens Wiki Page of Group
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: List of open wiki group’s IDs
|
|
|
|
|
@return: dictionay of open wiki window on give group id
|
|
|
|
|
"""
|
|
|
|
|
if not context:
|
|
|
|
|
context = {}
|
|
|
|
|
if type(ids) in (int,long,):
|
|
|
|
|
ids = [ids]
|
|
|
|
|
group_id = False
|
|
|
|
|
if ids:
|
|
|
|
|
group_id = ids[0]
|
|
|
|
|
if not group_id:
|
|
|
|
|
return {}
|
|
|
|
|
value = {
|
|
|
|
|
'name': 'Wiki Page',
|
|
|
|
|
'view_type': 'form',
|
|
|
|
|
'view_mode': 'form,tree',
|
|
|
|
|
'res_model': 'wiki.wiki',
|
|
|
|
|
'view_id': False,
|
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
|
'nodestroy': True,
|
|
|
|
|
}
|
|
|
|
|
group = self.browse(cr, uid, group_id, context=context)
|
|
|
|
|
value['domain'] = "[('group_id','=',%d)]" % (group.id)
|
|
|
|
|
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':
|
|
|
|
|
view_id = self.pool.get('ir.ui.view').search(cr, uid, [('name', '=', 'wiki.wiki.tree.childs')])
|
|
|
|
|
value['view_id'] = view_id
|
|
|
|
|
value['domain'] = [('group_id', '=', group.id), ('parent_id', '=', False)]
|
|
|
|
|
value['view_type'] = 'tree'
|
|
|
|
|
|
|
|
|
|
return value
|
2008-11-21 15:09:23 +00:00
|
|
|
|
WikiGroup()
|
2008-11-14 07:17:24 +00:00
|
|
|
|
|
2010-03-16 14:01:43 +00:00
|
|
|
|
|
2010-06-30 15:19:35 +00:00
|
|
|
|
class Wiki2(osv.osv):
|
2010-03-17 08:36:08 +00:00
|
|
|
|
""" Wiki Page """
|
|
|
|
|
|
|
|
|
|
_inherit = "wiki.wiki"
|
|
|
|
|
_description = "Wiki Page"
|
2008-11-21 18:12:32 +00:00
|
|
|
|
_order = 'section,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),
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'text_area': fields.text("Content"),
|
|
|
|
|
'create_uid': fields.many2one('res.users', 'Author', select=True),
|
|
|
|
|
'create_date': fields.datetime("Created on", select=True),
|
|
|
|
|
'write_date': fields.datetime("Modification Date", select=True),
|
2010-06-30 15:19:35 +00:00
|
|
|
|
'tags': fields.char('Tags', size=1024, select=True),
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'history_id': fields.one2many('wiki.wiki.history', 'wiki_id', 'History Lines'),
|
|
|
|
|
'minor_edit': fields.boolean('Minor edit', select=True),
|
|
|
|
|
'summary': fields.char('Summary', size=256),
|
2010-06-30 15:19:35 +00:00
|
|
|
|
'section': fields.char('Section', size=32, help="Use page section code like 1.2.1", select=True),
|
2010-07-12 06:39:51 +00:00
|
|
|
|
'group_id': fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null',
|
2010-06-30 15:19:35 +00:00
|
|
|
|
help="Topic, also called Wiki Group"),
|
2010-07-12 06:39:51 +00:00
|
|
|
|
'toc': fields.boolean('Table of Contents',
|
2010-06-30 15:19:35 +00:00
|
|
|
|
help="Indicates that this pages is a table of contents (linking to other pages)"),
|
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"),
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'parent_id': fields.many2one('wiki.wiki', 'Parent Page'),
|
|
|
|
|
'child_ids': fields.one2many('wiki.wiki', 'parent_id', 'Child Pages'),
|
2008-11-14 07:17:24 +00:00
|
|
|
|
}
|
2010-03-16 14:01:43 +00:00
|
|
|
|
|
2008-11-21 18:12:32 +00:00
|
|
|
|
def onchange_group_id(self, cr, uid, ids, group_id, content, context={}):
|
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,
|
|
|
|
|
@param ids: List of wiki page’s IDs
|
2010-03-17 09:27:12 +00:00
|
|
|
|
@return: dictionay of open wiki page on give page section """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2008-11-21 18:12:32 +00:00
|
|
|
|
if (not group_id) or content:
|
2008-11-21 17:15:13 +00:00
|
|
|
|
return {}
|
2008-11-21 18:12:32 +00:00
|
|
|
|
grp = self.pool.get('wiki.groups').browse(cr, uid, group_id)
|
2008-11-21 17:15:13 +00:00
|
|
|
|
section = '0'
|
2008-11-21 18:12:32 +00:00
|
|
|
|
for page in grp.page_ids:
|
|
|
|
|
if page.section: section = page.section
|
2008-11-21 17:17:04 +00:00
|
|
|
|
s = section.split('.')
|
2008-11-21 18:12:32 +00:00
|
|
|
|
template = grp.template
|
2008-11-21 17:22:36 +00:00
|
|
|
|
try:
|
|
|
|
|
s[-1] = str(int(s[-1])+1)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
2008-11-21 17:17:04 +00:00
|
|
|
|
section = '.'.join(s)
|
2008-11-21 17:15:13 +00:00
|
|
|
|
return {
|
|
|
|
|
'value':{
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'text_area': template,
|
2008-11-21 17:15:13 +00:00
|
|
|
|
'section': section
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
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,
|
|
|
|
|
@param id: Give wiki page's ID """
|
|
|
|
|
|
|
|
|
|
return super(Wiki, self).copy_data(cr, uid, id, {'wiki_id': False}, context)
|
2008-11-27 10:32:36 +00:00
|
|
|
|
|
2009-03-19 06:28:58 +00:00
|
|
|
|
def create(self, cr, uid, 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, """
|
|
|
|
|
|
2010-03-17 09:27:12 +00:00
|
|
|
|
id = super(Wiki, self).create(cr, uid, vals, context)
|
2009-03-19 06:28:58 +00:00
|
|
|
|
history = self.pool.get('wiki.wiki.history')
|
2010-03-17 08:36:08 +00:00
|
|
|
|
if vals.get('text_area'):
|
|
|
|
|
res = {
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'minor_edit': vals.get('minor_edit', True),
|
|
|
|
|
'text_area': vals.get('text_area', ''),
|
|
|
|
|
'write_uid': uid,
|
|
|
|
|
'wiki_id': id,
|
2010-03-17 09:27:12 +00:00
|
|
|
|
'summary':vals.get('summary', '')
|
2009-03-19 06:28:58 +00:00
|
|
|
|
}
|
|
|
|
|
history.create(cr, uid, res)
|
2010-03-17 08:36:08 +00:00
|
|
|
|
return 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, """
|
|
|
|
|
|
|
|
|
|
result = super(Wiki, self).write(cr, uid, ids, vals, context)
|
2008-11-24 06:49:47 +00:00
|
|
|
|
history = self.pool.get('wiki.wiki.history')
|
2008-11-14 07:17:24 +00:00
|
|
|
|
if vals.get('text_area'):
|
2008-11-24 06:49:47 +00:00
|
|
|
|
for id in ids:
|
|
|
|
|
res = {
|
2010-04-12 12:41:47 +00:00
|
|
|
|
'minor_edit': vals.get('minor_edit', True),
|
|
|
|
|
'text_area': vals.get('text_area', ''),
|
|
|
|
|
'write_uid': uid,
|
|
|
|
|
'wiki_id': id,
|
2010-03-17 09:27:12 +00:00
|
|
|
|
'summary': vals.get('summary', '')
|
2008-11-24 06:49:47 +00:00
|
|
|
|
}
|
|
|
|
|
history.create(cr, uid, res)
|
|
|
|
|
return result
|
|
|
|
|
|
2010-06-30 15:19:35 +00:00
|
|
|
|
Wiki2()
|
2008-11-14 07:17:24 +00:00
|
|
|
|
|
2010-03-16 14:01:43 +00:00
|
|
|
|
|
2008-11-14 07:17:24 +00:00
|
|
|
|
class History(osv.osv):
|
2010-03-16 14:01:43 +00:00
|
|
|
|
""" Wiki History """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
|
|
|
|
_name = "wiki.wiki.history"
|
|
|
|
|
_description = "Wiki 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),
|
|
|
|
|
'text_area': fields.text("Text area"),
|
|
|
|
|
'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),
|
|
|
|
|
'wiki_id': fields.many2one('wiki.wiki', 'Wiki Id', 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):
|
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, """
|
|
|
|
|
|
2008-11-21 12:30:50 +00:00
|
|
|
|
history_pool = self.pool.get('wiki.wiki.history')
|
2008-11-14 07:17:24 +00:00
|
|
|
|
text1 = history_pool.read(cr, uid, [v1], ['text_area'])[0]['text_area']
|
|
|
|
|
text2 = history_pool.read(cr, uid, [v2], ['text_area'])[0]['text_area']
|
2010-08-30 07:54:08 +00:00
|
|
|
|
line1 = line2 = ''
|
|
|
|
|
if text1:
|
|
|
|
|
line1 = text1.splitlines(1)
|
|
|
|
|
if text2:
|
|
|
|
|
line2 = text2.splitlines(1)
|
|
|
|
|
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
|
|
|
|
|
2008-11-21 16:37:59 +00:00
|
|
|
|
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:
|