~zaber/openupgrade-addons/missing-import

« back to all changes in this revision

Viewing changes to wiki/wiki.py

  • Committer: Fabien Pinckaers
  • Date: 2008-11-21 15:52:37 UTC
  • mfrom: (1829.4.3 openobject-addons)
  • Revision ID: fp@tinyerp.com-20081121155237-erha4970wqar1nr6
add

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2004-2006 TINY SPRL. (http://axelor.com) All Rights Reserved.
 
5
#
 
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
 
11
# Service Company
 
12
#
 
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.
 
17
#
 
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.
 
22
#
 
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.
 
26
#
 
27
##############################################################################
 
28
 
 
29
from osv import fields, osv
 
30
import time
 
31
from StringIO import StringIO
 
32
from HTMLParser import HTMLParser
 
33
 
 
34
class Wiki(osv.osv):
 
35
    _name="wiki.wiki"
 
36
    _description="Wiki"
 
37
    _order = 'name'
 
38
    _columns={
 
39
       'name':fields.char('Title', size=128, select=True, required=True),
 
40
       'write_uid':fields.many2one('res.users',"Last Modify By"),
 
41
       'text_area':fields.text("Content", select=True),
 
42
       'create_uid':fields.many2one('res.users','Authour', select=True),
 
43
       'create_date':fields.datetime("Created on", select=True),
 
44
       'write_date':fields.datetime("Last modified", select=True),
 
45
       'tags':fields.char('Tags', size=1024),
 
46
       'history_id':fields.one2many('wiki.wiki.history','history_wiki_id','History Lines'),
 
47
       'minor_edit':fields.boolean('Thisd is a minor edit', select=True),
 
48
       'summary':fields.char('Summary',size=256, select=True),
 
49
    }
 
50
 
 
51
    def __init__(self, cr, pool):
 
52
        super(Wiki, self).__init__(cr, pool)
 
53
        self.oldmodel = None
 
54
 
 
55
    def read(self, cr, uid, cids, fields=None, context=None, load='_classic_read'):
 
56
        ids = []
 
57
        for id in cids:
 
58
            if type(id) == type(1):
 
59
                ids.append(id)
 
60
            elif type(id) == type(u''):
 
61
                ids.append(10)
 
62
                
 
63
        result = super(Wiki, self).read(cr, uid, ids, fields, None, load='_classic_read')
 
64
        return result
 
65
 
 
66
    def create(self, cr, uid, vals, context=None):
 
67
        if not vals.has_key('minor_edit'):
 
68
            return super(Wiki,self).create(cr, uid, vals, context)
 
69
        vals['history_id']=[[0,0,{'minor_edit':vals['minor_edit'],'text_area':vals['text_area'],'summary':vals['summary']}]]
 
70
        return super(Wiki,self).create(cr, uid, vals, context)
 
71
 
 
72
    def write(self, cr, uid, ids, vals, context=None):
 
73
        if vals.get('text_area'):
 
74
            if vals.has_key('minor_edit') and vals.has_key('summary'):
 
75
                vals['history_id']=[[0,0,{'minor_edit':vals['minor_edit'],'text_area':vals['text_area'],'modify_by':uid,'summary':vals['summary']}]]
 
76
            elif vals.has_key('minor_edit'):
 
77
                vals['history_id']=[[0,0,{'minor_edit':vals['minor_edit'],'text_area':vals['text_area'],'modify_by':uid,'summary':wiki_data['summary']}]]
 
78
            elif vals.has_key('summary'):
 
79
                vals['history_id']=[[0,0,{'minor_edit':wiki_data['summary'],'text_area':vals['text_area'],'modify_by':uid,'summary':vals['summary']}]]
 
80
            else:
 
81
                vals['history_id']=[[0,0,{'minor_edit':wiki_data['minor_edit'],'text_area':vals['text_area'],'modify_by':uid,'summary':wiki_data['summary']}]]
 
82
        return super(Wiki,self).write(cr, uid, ids, vals, context)
 
83
Wiki()
 
84
 
 
85
class History(osv.osv):
 
86
    _name="wiki.wiki.history"
 
87
    _description="Wiki History"
 
88
    _rec_name="date_time"
 
89
    _order = 'id DESC'
 
90
    _columns={
 
91
      'date_time':fields.datetime("Date",select=True),
 
92
      'text_area':fields.text("Text area",select=True),
 
93
      'minor_edit':fields.boolean('This is a major edit ?',select=True),
 
94
      'summary':fields.char('Summary',size=256, select=True),
 
95
      'modify_by':fields.many2one('res.users',"Modify By", select=True),
 
96
      'hist_write_date':fields.datetime("Last modified", select=True),
 
97
      'history_wiki_id':fields.many2one('wiki.wiki','Wiki Id', select=True)
 
98
    }
 
99
    _defaults = {
 
100
        'hist_write_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
 
101
        'modify_by': lambda obj,cr,uid,context: uid,
 
102
    }
 
103
    
 
104
    def getDiff(self, cr, uid, v1, v2, context={}):
 
105
        import difflib
 
106
        
 
107
        history_pool = self.pool.get('wiki.wiki.history')
 
108
        
 
109
        text1 = history_pool.read(cr, uid, [v1], ['text_area'])[0]['text_area']
 
110
        text2 = history_pool.read(cr, uid, [v2], ['text_area'])[0]['text_area']
 
111
        
 
112
        line1 = text1.splitlines(1)
 
113
        line2 = text2.splitlines(1)
 
114
        
 
115
        diff = difflib.HtmlDiff()
 
116
        
 
117
        return diff.make_file(line1, line2, "Revision-%s" % (v1), "Revision-%s" % (v2), context=False)
 
118
History()
 
 
b'\\ No newline at end of file'