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 _
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', 'Home Page'),
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 Contributor", select=True),
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, select=True),
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('Section', size=32, help="Use page section code like 1.2.1", select=True),
99 'group_id': fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null',
100 help="Topic, also called Wiki Group"),
101 'toc': fields.boolean('Table of Contents',
102 help="Indicates that this pages is a table of contents (linking to other pages)"),
103 'review': fields.boolean('Needs Review', select=True,
104 help="Indicates that this page should be reviewed, raising the attention of other contributors"),
105 'parent_id': fields.many2one('wiki.wiki', 'Parent Page'),
106 'child_ids': fields.one2many('wiki.wiki', 'parent_id', 'Child Pages'),
109 def onchange_group_id(self, cr, uid, ids, group_id, content, context={}):
111 """ @param cr: the current row, from the database cursor,
112 @param uid: the current user’s ID for security checks,
113 @param ids: List of wiki page’s IDs
114 @return: dictionay of open wiki page on give page section """
116 if (not group_id) or content:
118 grp = self.pool.get('wiki.groups').browse(cr, uid, group_id)
120 for page in grp.page_ids:
121 if page.section: section = page.section
122 s = section.split('.')
123 template = grp.template
125 s[-1] = str(int(s[-1])+1)
128 section = '.'.join(s)
131 'text_area': template,
136 def copy_data(self, cr, uid, id, default=None, context=None):
138 """ @param cr: the current row, from the database cursor,
139 @param uid: the current user’s ID for security checks,
140 @param id: Give wiki page's ID """
142 return super(Wiki, self).copy_data(cr, uid, id, {'wiki_id': False}, context)
144 def create(self, cr, uid, vals, context=None):
146 """ @param cr: the current row, from the database cursor,
147 @param uid: the current user’s ID for security checks, """
149 id = super(Wiki, self).create(cr, uid, vals, context)
150 history = self.pool.get('wiki.wiki.history')
151 if vals.get('text_area'):
153 'minor_edit': vals.get('minor_edit', True),
154 'text_area': vals.get('text_area', ''),
157 'summary':vals.get('summary', '')
159 history.create(cr, uid, res)
162 def write(self, cr, uid, ids, vals, context=None):
164 """ @param cr: the current row, from the database cursor,
165 @param uid: the current user’s ID for security checks, """
167 result = super(Wiki, self).write(cr, uid, ids, vals, context)
168 history = self.pool.get('wiki.wiki.history')
169 if vals.get('text_area'):
172 'minor_edit': vals.get('minor_edit', True),
173 'text_area': vals.get('text_area', ''),
176 'summary': vals.get('summary', '')
178 history.create(cr, uid, res)
184 class History(osv.osv):
187 _name = "wiki.wiki.history"
188 _description = "Wiki History"
189 _rec_name = "date_time"
193 'create_date': fields.datetime("Date", select=True),
194 'text_area': fields.text("Text area"),
195 'minor_edit': fields.boolean('This is a major edit ?', select=True),
196 'summary': fields.char('Summary', size=256, select=True),
197 'write_uid': fields.many2one('res.users', "Modify By", select=True),
198 'wiki_id': fields.many2one('wiki.wiki', 'Wiki Id', select=True)
202 'write_uid': lambda obj, cr, uid, context: uid,
205 def getDiff(self, cr, uid, v1, v2, context={}):
207 """ @param cr: the current row, from the database cursor,
208 @param uid: the current user’s ID for security checks, """
210 history_pool = self.pool.get('wiki.wiki.history')
211 text1 = history_pool.read(cr, uid, [v1], ['text_area'])[0]['text_area']
212 text2 = history_pool.read(cr, uid, [v2], ['text_area'])[0]['text_area']
213 line1 = text1.splitlines(1)
214 line2 = text2.splitlines(1)
215 diff = difflib.HtmlDiff()
216 return diff.make_file(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=False)
220 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: