1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2004-2006 TINY SPRL. (http://axelor.com) All Rights Reserved.
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ##############################################################################
29 from osv import fields, osv
31 from StringIO import StringIO
32 from HTMLParser import HTMLParser
38 class WikiGroup(osv.osv):
40 _description="Wiki Groups"
43 'name':fields.char('Wiki Group', size=256, select=True, required=True),
44 'page_ids':fields.one2many('wiki.wiki', 'group_id', 'Pages'),
45 'notes':fields.text("Description"),
46 'create_date':fields.datetime("Created Date", select=True),
47 'template': fields.text('Wiki Template'),
48 'section': fields.boolean("Make Section ?"),
49 'method':fields.selection([('list','List'),('page','Home Page'),('tree','Tree')],'Display Method'),
50 'home':fields.many2one('wiki.wiki', 'Pages'),
53 'method': lambda *a: 'page',
57 class GroupLink(osv.osv):
58 _name = "wiki.groups.link"
59 _description="Wiki Groups Links"
60 _rec_name = 'action_id'
62 'group_id':fields.many2one('wiki.groups', 'Parent Group', ondelete='set null'),
63 'action_id': fields.many2one('ir.ui.menu', 'Menu')
69 _description="Wiki Page"
70 _order = 'section,create_date desc'
72 'name':fields.char('Title', size=256, select=True, required=True),
73 'write_uid':fields.many2one('res.users',"Last Author"),
74 'text_area':fields.text("Content"),
75 'create_uid':fields.many2one('res.users','Author', select=True),
76 'create_date':fields.datetime("Created on", select=True),
77 'write_date':fields.datetime("Modification Date", select=True),
78 'tags':fields.char('Tags', size=1024),
79 'history_id':fields.one2many('wiki.wiki.history','wiki_id','History Lines'),
80 'minor_edit':fields.boolean('Minor edit', select=True),
81 'summary':fields.char('Summary',size=256),
82 'section': fields.char('Sequence', size=32, help="Use page section code like 1.2.1"),
83 'group_id':fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null'),
84 'toc':fields.boolean('Table of Contents'),
85 'review': fields.boolean('Need Review'),
86 'parent_id':fields.many2one('wiki.wiki', 'Parent Page'),
87 'child_ids':fields.one2many('wiki.wiki', 'parent_id', 'Child Pages'),
90 def onchange_group_id(self, cr, uid, ids, group_id, content, context={}):
91 if (not group_id) or content:
93 grp = self.pool.get('wiki.groups').browse(cr, uid, group_id)
95 for page in grp.page_ids:
96 if page.section: section = page.section
97 s = section.split('.')
98 template = grp.template
100 s[-1] = str(int(s[-1])+1)
103 section = '.'.join(s)
106 'text_area': template,
110 def copy_data(self, cr, uid, id, default=None, context=None):
111 return super(Wiki, self).copy_data(cr, uid, id, {'wiki_id':False}, context)
113 def create(self, cr, uid, vals, context=None):
114 id = super(Wiki,self).create(cr, uid, vals, context)
115 history = self.pool.get('wiki.wiki.history')
116 if vals.get('text_area'):
118 'minor_edit':vals.get('minor_edit', True),
119 'text_area':vals.get('text_area',''),
122 'summary':vals.get('summary','')
124 history.create(cr, uid, res)
127 def write(self, cr, uid, ids, vals, context=None):
128 result = super(Wiki,self).write(cr, uid, ids, vals, context)
129 history = self.pool.get('wiki.wiki.history')
130 if vals.get('text_area'):
133 'minor_edit':vals.get('minor_edit', True),
134 'text_area':vals.get('text_area',''),
137 'summary':vals.get('summary','')
139 history.create(cr, uid, res)
144 class History(osv.osv):
145 _name="wiki.wiki.history"
146 _description="Wiki History"
147 _rec_name="date_time"
150 'create_date':fields.datetime("Date",select=True),
151 'text_area':fields.text("Text area"),
152 'minor_edit':fields.boolean('This is a major edit ?',select=True),
153 'summary':fields.char('Summary',size=256, select=True),
154 'write_uid':fields.many2one('res.users',"Modify By", select=True),
155 'wiki_id':fields.many2one('wiki.wiki','Wiki Id', select=True)
158 'write_uid': lambda obj,cr,uid,context: uid,
160 def getDiff(self, cr, uid, v1, v2, context={}):
162 history_pool = self.pool.get('wiki.wiki.history')
163 text1 = history_pool.read(cr, uid, [v1], ['text_area'])[0]['text_area']
164 text2 = history_pool.read(cr, uid, [v2], ['text_area'])[0]['text_area']
165 line1 = text1.splitlines(1)
166 line2 = text2.splitlines(1)
167 diff = difflib.HtmlDiff()
168 return diff.make_file(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=False)
170 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: