-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
##############################################################################
#
-# Copyright (c) 2004-2006 TINY SPRL. (http://axelor.com) All Rights Reserved.
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
-# WARNING: This program as such is intended to be used by professional
-# programmers who take the whole responsability of assessing all potential
-# consequences resulting from its eventual inadequacies and bugs
-# End users who are looking for a ready-to-use solution with commercial
-# garantees and support are strongly adviced to contract a Free Software
-# Service Company
+# 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 Free Software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# 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.
#
-# 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 General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# 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 osv import fields, osv
-import time
-from StringIO import StringIO
-from HTMLParser import HTMLParser
+from tools.translate import _
+import difflib
+import tools
+
+class wiki_wiki(osv.osv):
+ """ wiki """
+ _name = "wiki.wiki"
+
+wiki_wiki()
+
+class wiki_group(osv.osv):
+ """ Wiki Groups """
-class WikiGroup(osv.osv):
_name = "wiki.groups"
- _description="Wiki Groups"
+ _description = "Wiki Groups"
_order = 'name'
- _columns={
- 'name':fields.char('Name', size=256, select=True, required=True),
- 'notes':fields.text("Description", select=True),
- 'create_date':fields.datetime("Created on", select=True),
+
+ _columns = {
+ '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 ?"),
+ 'method':fields.selection([('list', 'List'), ('page', 'Home Page'), \
+ ('tree', 'Tree')], 'Display Method', help="Define the default behaviour of the menu created on this group"),
+ 'home':fields.many2one('wiki.wiki', 'Home Page', help="Required to select home page if display method is Home Page"),
+ 'menu_id': fields.many2one('ir.ui.menu', "Menu", readonly=True),
}
-WikiGroup()
+ _defaults = {
+ 'method': lambda *a: 'page',
+ }
-class Wiki(osv.osv):
- _name="wiki.wiki"
- _description="Wiki"
- _order = 'name'
- _columns={
- 'group_id':fields.many2one('wiki.groups', 'Group'),
- 'name':fields.char('Title', size=256, select=True, required=True),
- 'write_uid':fields.many2one('res.users',"Last Modify By"),
- 'text_area':fields.text("Content", select=True),
- 'create_uid':fields.many2one('res.users','Authour', select=True),
- 'create_date':fields.datetime("Created on", select=True),
- 'write_date':fields.datetime("Last modified", select=True),
- 'tags':fields.char('Tags', size=1024),
- 'history_id':fields.one2many('wiki.wiki.history','history_wiki_id','History Lines'),
- 'minor_edit':fields.boolean('Thisd is a minor edit', select=True),
- 'summary':fields.char('Summary',size=256, select=True),
+ def open_wiki_page(self, cr, uid, ids, context=None):
+
+ """ 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 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.children')])
+ value['view_id'] = view_id
+ value['domain'] = [('group_id', '=', group.id), ('parent_id', '=', False)]
+ value['view_type'] = 'tree'
+
+ return value
+wiki_group()
+
+
+class wiki_wiki2(osv.osv):
+ """ Wiki Page """
+
+ _inherit = "wiki.wiki"
+ _description = "Wiki Page"
+ _order = 'section,create_date desc'
+
+ _columns = {
+ 'name': fields.char('Title', size=256, select=True, required=True),
+ 'write_uid': fields.many2one('res.users', "Last Contributor", select=True),
+ 'text_area': fields.text("Content"),
+ 'create_uid': fields.many2one('res.users', 'Author', select=True, readonly=True),
+ 'create_date': fields.datetime("Created on", select=True, readonly=True),
+ 'write_date': fields.datetime("Modification Date", select=True, readonly=True),
+ 'tags': fields.char('Keywords', size=1024, select=True),
+ '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),
+ 'section': fields.char('Section', size=32, help="Use page section code like 1.2.1", select=True),
+ 'group_id': fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null',
+ help="Topic, also called Wiki Group"),
+ 'toc': fields.boolean('Table of Contents',
+ help="Indicates that this pages have a table of contents or not"),
+ 'review': fields.boolean('Needs Review', select=True,
+ help="Indicates that this page should be reviewed, raising the attention of other contributors"),
+ 'parent_id': fields.many2one('wiki.wiki', 'Parent Page', help="Allows you to link with the other page with in the current topic"),
+ 'child_ids': fields.one2many('wiki.wiki', 'parent_id', 'Child Pages'),
+ }
+ _defaults = {
+ 'toc': True,
+ 'review': True,
+ 'minor_edit': True,
}
- def __init__(self, cr, pool):
- super(Wiki, self).__init__(cr, pool)
- self.oldmodel = None
-
- def read(self, cr, uid, cids, fields=None, context=None, load='_classic_read'):
- ids = []
- for id in cids:
- if type(id) == type(1):
- ids.append(id)
- elif type(id) == type(u''):
- ids.append(10)
-
- result = super(Wiki, self).read(cr, uid, ids, fields, None, load='_classic_read')
- return result
+ def onchange_group_id(self, cr, uid, ids, group_id, content, context=None):
+
+ """ @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
+ @return: dictionay of open wiki page on give page section """
+
+ if (not group_id) or content:
+ return {}
+ grp = self.pool.get('wiki.groups').browse(cr, uid, group_id, context=context)
+ section = '0'
+ for page in grp.page_ids:
+ if page.section: section = page.section
+ s = section.split('.')
+ template = grp.template
+ try:
+ s[-1] = str(int(s[-1])+1)
+ except:
+ pass
+ section = '.'.join(s)
+ return {
+ 'value':{
+ 'text_area': template,
+ 'section': section
+ }
+ }
+
+ def copy_data(self, cr, uid, id, default=None, context=None):
+
+ """ @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_wiki2, self).copy_data(cr, uid, id, {'wiki_id': False}, context)
+
+ def create_history(self, cr, uid, ids, vals, context=None):
+ history_id = False
+ history = self.pool.get('wiki.wiki.history')
+ if vals.get('text_area'):
+ res = {
+ 'minor_edit': vals.get('minor_edit', True),
+ 'text_area': vals.get('text_area', ''),
+ 'write_uid': uid,
+ 'wiki_id': ids[0],
+ 'summary':vals.get('summary', '')
+ }
+ history_id = history.create(cr, uid, res)
+ return history_id
def create(self, cr, uid, vals, context=None):
- if not vals.has_key('minor_edit'):
- return super(Wiki,self).create(cr, uid, vals, context)
- vals['history_id']=[[0,0,{'minor_edit':vals['minor_edit'],'text_area':vals['text_area'],'summary':vals['summary']}]]
- return super(Wiki,self).create(cr, uid, vals, context)
+
+ """ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks, """
+ wiki_id = super(wiki_wiki2, self).create(cr, uid,
+ vals, context)
+ self.create_history(cr, uid, [wiki_id], vals, context)
+ return wiki_id
def write(self, cr, uid, ids, vals, context=None):
- if vals.get('text_area'):
- if vals.has_key('minor_edit') and vals.has_key('summary'):
- vals['history_id']=[[0,0,{'minor_edit':vals['minor_edit'],'text_area':vals['text_area'],'modify_by':uid,'summary':vals['summary']}]]
- elif vals.has_key('minor_edit'):
- vals['history_id']=[[0,0,{'minor_edit':vals['minor_edit'],'text_area':vals['text_area'],'modify_by':uid,'summary':wiki_data['summary']}]]
- elif vals.has_key('summary'):
- vals['history_id']=[[0,0,{'minor_edit':wiki_data['summary'],'text_area':vals['text_area'],'modify_by':uid,'summary':vals['summary']}]]
- else:
- vals['history_id']=[[0,0,{'minor_edit':wiki_data['minor_edit'],'text_area':vals['text_area'],'modify_by':uid,'summary':wiki_data['summary']}]]
- return super(Wiki,self).write(cr, uid, ids, vals, context)
-Wiki()
-
-class History(osv.osv):
- _name="wiki.wiki.history"
- _description="Wiki History"
- _rec_name="date_time"
+
+ """ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks, """
+ result = super(wiki_wiki2, self).write(cr, uid, ids, vals, context)
+ self.create_history(cr, uid, ids, vals, context)
+ return result
+
+wiki_wiki2()
+
+
+class wiki_history(osv.osv):
+ """ Wiki History """
+
+ _name = "wiki.wiki.history"
+ _description = "Wiki History"
+ _rec_name = "summary"
_order = 'id DESC'
- _columns={
- 'date_time':fields.datetime("Date",select=True),
- 'text_area':fields.text("Text area",select=True),
- 'minor_edit':fields.boolean('This is a major edit ?',select=True),
- 'summary':fields.char('Summary',size=256, select=True),
- 'modify_by':fields.many2one('res.users',"Modify By", select=True),
- 'hist_write_date':fields.datetime("Last modified", select=True),
- 'history_wiki_id':fields.many2one('wiki.wiki','Wiki Id', select=True)
+
+ _columns = {
+ '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)
}
+
_defaults = {
- 'hist_write_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
- 'modify_by': lambda obj,cr,uid,context: uid,
+ 'write_uid': lambda obj, cr, uid, context: uid,
}
-
- def getDiff(self, cr, uid, v1, v2, context={}):
- import difflib
-
+
+ def getDiff(self, cr, uid, v1, v2, context=None):
+
+ """ @param cr: the current row, from the database cursor,
+ @param uid: the current user’s ID for security checks, """
+
history_pool = self.pool.get('wiki.wiki.history')
-
text1 = history_pool.read(cr, uid, [v1], ['text_area'])[0]['text_area']
text2 = history_pool.read(cr, uid, [v2], ['text_area'])[0]['text_area']
-
- line1 = text1.splitlines(1)
- line2 = text2.splitlines(1)
-
+ line1 = line2 = ''
+ if text1:
+ line1 = tools.ustr(text1.splitlines(1))
+ if text2:
+ line2=tools.ustr(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_file(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=False)
-History()
\ No newline at end of file
+
+wiki_history()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: