Package camelot :: Package camelot :: Package model :: Module memento
[hide private]
[frames] | no frames]

Source Code for Module camelot.camelot.model.memento

 1  #  ============================================================================= 
 2  # 
 3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved. 
 4  #  www.conceptive.be / project-camelot@conceptive.be 
 5  # 
 6  #  This file is part of the Camelot Library. 
 7  # 
 8  #  This file may be used under the terms of the GNU General Public 
 9  #  License version 2.0 as published by the Free Software Foundation 
10  #  and appearing in the file LICENSE.GPL included in the packaging of 
11  #  this file.  Please review the following information to ensure GNU 
12  #  General Public Licensing requirements will be met: 
13  #  http://www.trolltech.com/products/qt/opensource.html 
14  # 
15  #  If you are unsure which license is appropriate for your use, please 
16  #  review the following information: 
17  #  http://www.trolltech.com/products/qt/licensing.html or contact 
18  #  project-camelot@conceptive.be. 
19  # 
20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 
21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
22  # 
23  #  For use of this library in commercial applications, please contact 
24  #  project-camelot@conceptive.be 
25  # 
26  #  ============================================================================= 
27   
28  """Set of classes to keep track of changes to objects and 
29  be able to restore their state 
30  """ 
31   
32  from camelot.model import * 
33  from authentication import getCurrentPerson, Person 
34  __metadata__ = metadata 
35   
36  from camelot.view.elixir_admin import EntityAdmin 
37  import datetime 
38 39 -class Memento(Entity):
40 """Keeps information on the previous state of objects, to keep track 41 of changes and enable restore to that previous state""" 42 using_options(tablename='memento') 43 model = Field(Unicode(256), index=True, required=True) 44 primary_key = Field(INT(), index=True, required=True) 45 creation_date = Field(DateTime(), default=datetime.datetime.now) 46 person = ManyToOne('Person', required=True, ondelete='restrict', onupdate='cascade') 47 48 description = property(lambda self:'Change') 49
50 - class Admin(EntityAdmin):
51 name = 'History' 52 section = 'configuration' 53 list_display = ['creation_date', 'person', 'model', 'primary_key', 'description'] 54 list_filter = ['model']
55
56 -class BeforeUpdate(Memento):
57 """The state of the object before an update took place""" 58 using_options(inheritance='multi', tablename='memento_update',) 59 previous_attributes = Field(PickleType()) 60 61 @property
62 - def description(self):
63 return 'Update %s when previous value was %s'%(','.join(self.previous_attributes.keys()), ','.join(str(v) for v in self.previous_attributes.values()))
64
65 - class Admin(EntityAdmin):
66 name = 'Updates' 67 list_display = Memento.Admin.list_display 68 list_filter = ['model']
69
70 -class BeforeDelete(Memento):
71 """The state of the object before it is deleted""" 72 using_options(inheritance='multi', tablename='memento_delete',) 73 previous_attributes = Field(PickleType()) 74 75 @property
76 - def description(self):
77 return 'Delete'
78
79 - class Admin(EntityAdmin):
80 name = 'Deletes' 81 list_display = Memento.Admin.list_display 82 list_filter = ['model']
83
84 -class Create(Memento):
85 """Marks the creation of an object""" 86 using_options(inheritance='multi', tablename='memento_create',) 87 88 @property
89 - def description(self):
90 return 'Create'
91
92 - class Admin(EntityAdmin):
93 name = 'Creates' 94 list_display = Memento.Admin.list_display 95 list_filter = ['model']
96