1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from osv import fields, osv
24 from tools.translate import _
33 class WikiGroup(osv.osv):
37 _description = "Wiki Groups"
41 'name':fields.char('Wiki Group', size=256, select=True, required=True),
42 'page_ids':fields.one2many('wiki.wiki', 'group_id', 'Pages'),
43 'notes':fields.text("Description"),
44 'create_date':fields.datetime("Created Date", select=True),
45 'template': fields.text('Wiki Template'),
46 'section': fields.boolean("Make Section ?"),
47 'method':fields.selection([('list', 'List'), ('page', 'Home Page'), \
48 ('tree', 'Tree')], 'Display Method'),
49 'home':fields.many2one('wiki.wiki', 'Home Page'),
50 'menu_id': fields.many2one('ir.ui.menu', "Menu", readonly=True),
54 'method': lambda *a: 'page',
57 def open_wiki_page(self, cr, uid, ids, context):
59 """ Opens Wiki Page of Group
60 @param cr: the current row, from the database cursor,
61 @param uid: the current user’s ID for security checks,
62 @param ids: List of open wiki group’s IDs
63 @return: dictionay of open wiki window on give group id
67 if type(ids) in (int,long,):
77 'view_mode': 'form,tree',
78 'res_model': 'wiki.wiki',
80 'type': 'ir.actions.act_window',
83 group = self.browse(cr, uid, group_id, context=context)
84 value['domain'] = "[('group_id','=',%d)]" % (group.id)
85 if group.method == 'page':
86 value['res_id'] = group.home.id
87 elif group.method == 'list':
88 value['view_type'] = 'form'
89 value['view_mode'] = 'tree,form'
90 elif group.method == 'tree':
91 view_id = self.pool.get('ir.ui.view').search(cr, uid, [('name', '=', 'wiki.wiki.tree.childs')])
92 value['view_id'] = view_id
93 value['domain'] = [('group_id', '=', group.id), ('parent_id', '=', False)]
94 value['view_type'] = 'tree'
100 class Wiki2(osv.osv):
103 _inherit = "wiki.wiki"
104 _description = "Wiki Page"
105 _order = 'section,create_date desc'
108 'name': fields.char('Title', size=256, select=True, required=True),
109 'write_uid': fields.many2one('res.users', "Last Contributor", select=True),
110 'text_area': fields.text("Content"),
111 'create_uid': fields.many2one('res.users', 'Author', select=True),
112 'create_date': fields.datetime("Created on", select=True),
113 'write_date': fields.datetime("Modification Date", select=True),
114 'tags': fields.char('Tags', size=1024, select=True),
115 'history_id': fields.one2many('wiki.wiki.history', 'wiki_id', 'History Lines'),
116 'minor_edit': fields.boolean('Minor edit', select=True),
117 'summary': fields.char('Summary', size=256),
118 'section': fields.char('Section', size=32, help="Use page section code like 1.2.1", select=True),
119 'group_id': fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null',
120 help="Topic, also called Wiki Group"),
121 'toc': fields.boolean('Table of Contents',
122 help="Indicates that this pages is a table of contents (linking to other pages)"),
123 'review': fields.boolean('Needs Review', select=True,
124 help="Indicates that this page should be reviewed, raising the attention of other contributors"),
125 'parent_id': fields.many2one('wiki.wiki', 'Parent Page'),
126 'child_ids': fields.one2many('wiki.wiki', 'parent_id', 'Child Pages'),
129 def onchange_group_id(self, cr, uid, ids, group_id, content, context={}):
131 """ @param cr: the current row, from the database cursor,
132 @param uid: the current user’s ID for security checks,
133 @param ids: List of wiki page’s IDs
134 @return: dictionay of open wiki page on give page section """
136 if (not group_id) or content:
138 grp = self.pool.get('wiki.groups').browse(cr, uid, group_id)
140 for page in grp.page_ids:
141 if page.section: section = page.section
142 s = section.split('.')
143 template = grp.template
145 s[-1] = str(int(s[-1])+1)
148 section = '.'.join(s)
151 'text_area': template,
156 def copy_data(self, cr, uid, id, default=None, context=None):
158 """ @param cr: the current row, from the database cursor,
159 @param uid: the current user’s ID for security checks,
160 @param id: Give wiki page's ID """
162 return super(Wiki, self).copy_data(cr, uid, id, {'wiki_id': False}, context)
164 def create(self, cr, uid, vals, context=None):
166 """ @param cr: the current row, from the database cursor,
167 @param uid: the current user’s ID for security checks, """
169 id = super(Wiki, self).create(cr, uid, vals, context)
170 history = self.pool.get('wiki.wiki.history')
171 if vals.get('text_area'):
173 'minor_edit': vals.get('minor_edit', True),
174 'text_area': vals.get('text_area', ''),
177 'summary':vals.get('summary', '')
179 history.create(cr, uid, res)
182 def write(self, cr, uid, ids, vals, context=None):
184 """ @param cr: the current row, from the database cursor,
185 @param uid: the current user’s ID for security checks, """
187 result = super(Wiki, self).write(cr, uid, ids, vals, context)
188 history = self.pool.get('wiki.wiki.history')
189 if vals.get('text_area'):
192 'minor_edit': vals.get('minor_edit', True),
193 'text_area': vals.get('text_area', ''),
196 'summary': vals.get('summary', '')
198 history.create(cr, uid, res)
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: