Package Camelot :: Package camelot :: Package model :: Module memento
[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  from elixir.entity import Entity 
 28  from elixir.options import using_options 
 29  from elixir.fields import Field 
 30  from sqlalchemy.types import Unicode, INT, DateTime, PickleType 
 31  from elixir.relationships import ManyToOne 
 32   
 33  from camelot.model import metadata 
 34  from camelot.view import filters 
 35   
 36  """Set of classes to keep track of changes to objects and 
 37  be able to restore their state 
 38  """ 
 39   
 40  __metadata__ = metadata 
 41   
 42  from camelot.core.utils import ugettext_lazy as _ 
 43  from camelot.view.elixir_admin import EntityAdmin 
 44  import datetime 
45 46 47 -class Memento( Entity ):
48 """Keeps information on the previous state of objects, to keep track 49 of changes and enable restore to that previous state""" 50 using_options( tablename = 'memento' ) 51 model = Field( Unicode( 256 ), index = True, required = True ) 52 primary_key = Field( INT(), index = True, required = True ) 53 creation_date = Field( DateTime(), default = datetime.datetime.now ) 54 authentication = ManyToOne( 'AuthenticationMechanism', 55 required = True, 56 ondelete = 'restrict', 57 onupdate = 'cascade' ) 58 description = property( lambda self:'Change' ) 59
60 - class Admin( EntityAdmin ):
61 verbose_name = _( 'History' ) 62 verbose_name_plural = _( 'History' ) 63 list_display = ['creation_date', 64 'authentication', 65 'model', 66 'primary_key', 67 'description'] 68 list_filter = [filters.ComboBoxFilter('model')]
69
70 71 -class BeforeUpdate( Memento ):
72 """The state of the object before an update took place""" 73 using_options( inheritance = 'multi', tablename = 'memento_update', ) 74 previous_attributes = Field( PickleType() ) 75 76 @property
77 - def description( self ):
78 if self.previous_attributes: 79 return u'Update %s when previous value was %s' % ( 80 ','.join( self.previous_attributes.keys() ), 81 ','.join( unicode( v ) for v in self.previous_attributes.values() ) )
82
83 - class Admin( Memento.Admin ):
84 verbose_name = _('Update') 85 verbose_name_plural = _('Updates')
86
87 -class BeforeDelete( Memento ):
88 """The state of the object before it is deleted""" 89 using_options( inheritance = 'multi', tablename = 'memento_delete', ) 90 previous_attributes = Field( PickleType() ) 91 92 @property
93 - def description( self ):
94 return 'Delete'
95
96 - class Admin( Memento.Admin ):
97 verbose_name = _('Delete') 98 verbose_name_plural = _('Deletes')
99
100 -class Create( Memento ):
101 """Marks the creation of an object""" 102 using_options( inheritance = 'multi', tablename = 'memento_create', ) 103 104 @property
105 - def description( self ):
106 return 'Create'
107
108 - class Admin( Memento.Admin ):
109 verbose_name = _('Create') 110 verbose_name_plural = _('Creates')
111