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
39 class WikiGroup(osv.osv):
43 _description = "Wiki Groups"
47 'name':fields.char('Wiki Group', size=256, select=True, required=True),
48 'page_ids':fields.one2many('wiki.wiki', 'group_id', 'Pages'),
49 'notes':fields.text("Description"),
50 'create_date':fields.datetime("Created Date", select=True),
51 'template': fields.text('Wiki Template'),
52 'section': fields.boolean("Make Section ?"),
53 'method':fields.selection([('list', 'List'), ('page', 'Home Page'), \
54 ('tree', 'Tree')], 'Display Method'),
55 'home':fields.many2one('wiki.wiki', 'Pages'),
59 'method': lambda *a: 'page',
65 class GroupLink(osv.osv):
66 """ Apply Group Link """
68 _name = "wiki.groups.link"
69 _description = "Wiki Groups Links"
70 _rec_name = 'action_id'
73 'group_id': fields.many2one('wiki.groups', 'Parent Group', ondelete='set null'),
74 'action_id': fields.many2one('ir.ui.menu', 'Menu')
83 _inherit = "wiki.wiki"
84 _description = "Wiki Page"
85 _order = 'section,create_date desc'
88 'name': fields.char('Title', size=256, select=True, required=True),
89 'write_uid': fields.many2one('res.users',"Last Author"),
90 'text_area': fields.text("Content"),
91 'create_uid': fields.many2one('res.users','Author', select=True),
92 'create_date': fields.datetime("Created on", select=True),
93 'write_date': fields.datetime("Modification Date", select=True),
94 'tags': fields.char('Tags', size=1024),
95 'history_id': fields.one2many('wiki.wiki.history','wiki_id','History Lines'),
96 'minor_edit': fields.boolean('Minor edit', select=True),
97 'summary': fields.char('Summary',size=256),
98 'section': fields.char('Sequence', size=32, help="Use page section code like 1.2.1"),
99 'group_id': fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null'),
100 'toc': fields.boolean('Table of Contents'),
101 'review': fields.boolean('Need Review'),
102 'parent_id': fields.many2one('wiki.wiki', 'Parent Page'),
103 'child_ids': fields.one2many('wiki.wiki', 'parent_id', 'Child Pages'),
106 def onchange_group_id(self, cr, uid, ids, group_id, content, context={}):
108 """ @param cr: the current row, from the database cursor,
109 @param uid: the current user’s ID for security checks,
110 @param ids: List of wiki page’s IDs
111 @return : dictionay of open wiki page on give page section """
113 if (not group_id) or content:
115 grp = self.pool.get('wiki.groups').browse(cr, uid, group_id)
117 for page in grp.page_ids:
118 if page.section: section = page.section
119 s = section.split('.')
120 template = grp.template
122 s[-1] = str(int(s[-1])+1)
125 section = '.'.join(s)
128 'text_area': template,
133 def copy_data(self, cr, uid, id, default=None, context=None):
135 """ @param cr: the current row, from the database cursor,
136 @param uid: the current user’s ID for security checks,
137 @param id: Give wiki page's ID """
139 return super(Wiki, self).copy_data(cr, uid, id, {'wiki_id': False}, context)
141 def create(self, cr, uid, vals, context=None):
143 """ @param cr: the current row, from the database cursor,
144 @param uid: the current user’s ID for security checks, """
146 id = super(Wiki,self).create(cr, uid, vals, context)
147 history = self.pool.get('wiki.wiki.history')
148 if vals.get('text_area'):
150 'minor_edit':vals.get('minor_edit', True),
151 'text_area':vals.get('text_area',''),
154 'summary':vals.get('summary','')
156 history.create(cr, uid, res)
159 def write(self, cr, uid, ids, vals, context=None):
161 """ @param cr: the current row, from the database cursor,
162 @param uid: the current user’s ID for security checks, """
164 result = super(Wiki, self).write(cr, uid, ids, vals, context)
165 history = self.pool.get('wiki.wiki.history')
166 if vals.get('text_area'):
169 'minor_edit':vals.get('minor_edit', True),
170 'text_area':vals.get('text_area',''),
173 'summary':vals.get('summary','')
175 history.create(cr, uid, res)
181 class History(osv.osv):
184 _name = "wiki.wiki.history"
185 _description = "Wiki History"
186 _rec_name = "date_time"
190 'create_date': fields.datetime("Date",select=True),
191 'text_area': fields.text("Text area"),
192 'minor_edit': fields.boolean('This is a major edit ?',select=True),
193 'summary': fields.char('Summary',size=256, select=True),
194 'write_uid': fields.many2one('res.users',"Modify By", select=True),
195 'wiki_id': fields.many2one('wiki.wiki','Wiki Id', select=True)
199 'write_uid': lambda obj,cr,uid,context: uid,
202 def getDiff(self, cr, uid, v1, v2, context={}):
204 """ @param cr: the current row, from the database cursor,
205 @param uid: the current user’s ID for security checks, """
207 history_pool = self.pool.get('wiki.wiki.history')
208 text1 = history_pool.read(cr, uid, [v1], ['text_area'])[0]['text_area']
209 text2 = history_pool.read(cr, uid, [v2], ['text_area'])[0]['text_area']
210 line1 = text1.splitlines(1)
211 line2 = text2.splitlines(1)
212 diff = difflib.HtmlDiff()
213 return diff.make_file(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=False)
217 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: