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
30 from tools.translate import _
40 class WikiGroup(osv.osv):
44 _description = "Wiki Groups"
48 'name':fields.char('Wiki Group', size=256, select=True, required=True),
49 'page_ids':fields.one2many('wiki.wiki', 'group_id', 'Pages'),
50 'notes':fields.text("Description"),
51 'create_date':fields.datetime("Created Date", select=True),
52 'template': fields.text('Wiki Template'),
53 'section': fields.boolean("Make Section ?"),
54 'method':fields.selection([('list', 'List'), ('page', 'Home Page'), \
55 ('tree', 'Tree')], 'Display Method'),
56 'home':fields.many2one('wiki.wiki', 'Home Page'),
60 'method': lambda *a: 'page',
66 class GroupLink(osv.osv):
67 """ Apply Group Link """
69 _name = "wiki.groups.link"
70 _description = "Wiki Groups Links"
71 _rec_name = 'action_id'
74 'group_id': fields.many2one('wiki.groups', 'Parent Group', ondelete='set null'),
75 'action_id': fields.many2one('ir.ui.menu', 'Menu')
84 _inherit = "wiki.wiki"
85 _description = "Wiki Page"
86 _order = 'section,create_date desc'
89 'name': fields.char('Title', size=256, select=True, required=True),
90 'write_uid': fields.many2one('res.users', "Last Author"),
91 'text_area': fields.text("Content"),
92 'create_uid': fields.many2one('res.users', 'Author', select=True),
93 'create_date': fields.datetime("Created on", select=True),
94 'write_date': fields.datetime("Modification Date", select=True),
95 'tags': fields.char('Tags', size=1024),
96 'history_id': fields.one2many('wiki.wiki.history', 'wiki_id', 'History Lines'),
97 'minor_edit': fields.boolean('Minor edit', select=True),
98 'summary': fields.char('Summary', size=256),
99 'section': fields.char('Sequence', size=32, help="Use page section code like 1.2.1"),
100 'group_id': fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null'),
101 'toc': fields.boolean('Table of Contents'),
102 'review': fields.boolean('Need Review'),
103 'parent_id': fields.many2one('wiki.wiki', 'Parent Page'),
104 'child_ids': fields.one2many('wiki.wiki', 'parent_id', 'Child Pages'),
107 def onchange_group_id(self, cr, uid, ids, group_id, content, context={}):
109 """ @param cr: the current row, from the database cursor,
110 @param uid: the current user’s ID for security checks,
111 @param ids: List of wiki page’s IDs
112 @return: dictionay of open wiki page on give page section """
114 if (not group_id) or content:
116 grp = self.pool.get('wiki.groups').browse(cr, uid, group_id)
118 for page in grp.page_ids:
119 if page.section: section = page.section
120 s = section.split('.')
121 template = grp.template
123 s[-1] = str(int(s[-1])+1)
126 section = '.'.join(s)
129 'text_area': template,
134 def copy_data(self, cr, uid, id, default=None, context=None):
136 """ @param cr: the current row, from the database cursor,
137 @param uid: the current user’s ID for security checks,
138 @param id: Give wiki page's ID """
140 return super(Wiki, self).copy_data(cr, uid, id, {'wiki_id': False}, context)
142 def create(self, cr, uid, vals, context=None):
144 """ @param cr: the current row, from the database cursor,
145 @param uid: the current user’s ID for security checks, """
147 id = super(Wiki, self).create(cr, uid, vals, context)
148 history = self.pool.get('wiki.wiki.history')
149 if vals.get('text_area'):
151 'minor_edit': vals.get('minor_edit', True),
152 'text_area': vals.get('text_area', ''),
155 'summary':vals.get('summary', '')
157 history.create(cr, uid, res)
160 def write(self, cr, uid, ids, vals, context=None):
162 """ @param cr: the current row, from the database cursor,
163 @param uid: the current user’s ID for security checks, """
165 result = super(Wiki, self).write(cr, uid, ids, vals, context)
166 history = self.pool.get('wiki.wiki.history')
167 if vals.get('text_area'):
170 'minor_edit': vals.get('minor_edit', True),
171 'text_area': vals.get('text_area', ''),
174 'summary': vals.get('summary', '')
176 history.create(cr, uid, res)
179 def open_wiki_page(self, cr, uid, ids, context):
181 """ Opens Wiki Page for Editing
182 @param cr: the current row, from the database cursor,
183 @param uid: the current user’s ID for security checks,
184 @param ids: List of wiki page’s IDs
187 pages = self.pool.get('wiki.wiki').search(cr, uid, [('name', '=', 'Basic Wiki Editing')])
189 raise osv.except_osv(_('Warning !'), _("No Help page is defined"))
192 'view_mode': 'form,tree',
193 'res_model': 'wiki.wiki',
196 'type': 'ir.actions.act_window',
204 class History(osv.osv):
207 _name = "wiki.wiki.history"
208 _description = "Wiki History"
209 _rec_name = "date_time"
213 'create_date': fields.datetime("Date", select=True),
214 'text_area': fields.text("Text area"),
215 'minor_edit': fields.boolean('This is a major edit ?', select=True),
216 'summary': fields.char('Summary', size=256, select=True),
217 'write_uid': fields.many2one('res.users', "Modify By", select=True),
218 'wiki_id': fields.many2one('wiki.wiki', 'Wiki Id', select=True)
222 'write_uid': lambda obj, cr, uid, context: uid,
225 def getDiff(self, cr, uid, v1, v2, context={}):
227 """ @param cr: the current row, from the database cursor,
228 @param uid: the current user’s ID for security checks, """
230 history_pool = self.pool.get('wiki.wiki.history')
231 text1 = history_pool.read(cr, uid, [v1], ['text_area'])[0]['text_area']
232 text2 = history_pool.read(cr, uid, [v2], ['text_area'])[0]['text_area']
233 line1 = text1.splitlines(1)
234 line2 = text2.splitlines(1)
235 diff = difflib.HtmlDiff()
236 return diff.make_file(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=False)
240 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: