1 # -*- encoding: 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
34 class WikiGroup(osv.osv):
36 _description="Wiki Groups"
39 'name':fields.char('Wiki Group', size=256, select=True, required=True),
40 'parent_id':fields.many2one('wiki.groups', 'Parent Group', ondelete='set null'),
41 'child_ids':fields.one2many('wiki.groups', 'parent_id', 'Child Groups'),
42 'page_ids':fields.one2many('wiki.wiki', 'group_id', 'Pages'),
43 'notes':fields.text("Description", select=True),
44 'create_date':fields.datetime("Created on", select=True),
45 'template': fields.text('Wiki Template')
52 _description="Wiki Page"
53 _order = 'section,name'
55 'name':fields.char('Title', size=256, select=True, required=True),
56 'write_uid':fields.many2one('res.users',"Last Modified By"),
57 'text_area':fields.text("Content", select=True),
58 'create_uid':fields.many2one('res.users','Author', select=True),
59 'create_date':fields.datetime("Created on", select=True),
60 'write_date':fields.datetime("Last modified", select=True),
61 'tags':fields.char('Tags', size=1024),
62 'history_id':fields.one2many('wiki.wiki.history','history_wiki_id','History Lines'),
63 'minor_edit':fields.boolean('Minor edit', select=True),
64 'summary':fields.char('Summary',size=256, select=True),
65 'section': fields.char('Section', size=32, help="Use page section code like 1.2.1"),
66 'group_id':fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null'),
68 def onchange_group_id(self, cr, uid, ids, group, content, context={}):
69 if (not group) or content:
71 group = self.pool.get('wiki.groups').browse(cr, uid, group, context)
73 for page in group.page_ids:
74 section = page.section
75 s = section.split('.')
77 s[-1] = str(int(s[-1])+1)
81 print 'SECTION', section, group, group.name
85 'text_area': group.template,
90 def read(self, cr, uid, cids, fields=None, context=None, load='_classic_read'):
93 if type(id) == type(1):
95 elif type(id) == type(u''):
97 result = super(Wiki, self).read(cr, uid, ids, fields, None, load='_classic_read')
100 def write(self, cr, uid, ids, vals, context=None):
101 if vals.get('text_area'):
102 vals['history_id']=[(0,0,{
103 'minor_edit':vals.get('minor_edit', False),
104 'text_area':vals['text_area'],
106 'summary':vals.get('summary','')
108 return super(Wiki,self).write(cr, uid, ids, vals, context)
111 class History(osv.osv):
112 _name="wiki.wiki.history"
113 _description="Wiki History"
114 _rec_name="date_time"
117 'date_time':fields.datetime("Date",select=True),
118 'text_area':fields.text("Text area",select=True),
119 'minor_edit':fields.boolean('This is a major edit ?',select=True),
120 'summary':fields.char('Summary',size=256, select=True),
121 'modify_by':fields.many2one('res.users',"Modify By", select=True),
122 'hist_write_date':fields.datetime("Last modified", select=True),
123 'history_wiki_id':fields.many2one('wiki.wiki','Wiki Id', select=True)
126 'hist_write_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
127 'modify_by': lambda obj,cr,uid,context: uid,
129 def getDiff(self, cr, uid, v1, v2, context={}):
131 history_pool = self.pool.get('wiki.wiki.history')
132 text1 = history_pool.read(cr, uid, [v1], ['text_area'])[0]['text_area']
133 text2 = history_pool.read(cr, uid, [v2], ['text_area'])[0]['text_area']
134 line1 = text1.splitlines(1)
135 line2 = text2.splitlines(1)
136 diff = difflib.HtmlDiff()
137 return diff.make_file(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=False)