Changeset 218
- Timestamp:
- 10/11/07 09:49:28 (6 years ago)
- Location:
- elixir/trunk
- Files:
-
- 3 modified
-
TODO (modified) (2 diffs)
-
elixir/ext/versioned.py (modified) (5 diffs)
-
tests/test_versioning.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/TODO
r210 r218 97 97 Entity) defines a property will probably fail because of line 16. 98 98 99 - Make the session context extension/assign_mapper optional100 101 99 - I'm not sure it would be worth it but we might want to put a section 102 100 "contributing" on the website. In that case it might be a good idea to point 103 101 to this file so that people know what can be done. 104 105 - get rid of the assign_mapper stuff. This means we have to add all methods on106 the entity base class.107 108 - integrate the association proxy plugin109 see ML thread about this110 102 111 103 - add __revision__ (+ svn property) to all elixir files? … … 151 143 cfr http://www.sqlalchemy.org/trac/ticket/502 152 144 145 - better support from strange relation, or even other properties (like 146 column_property, and so on) 147 see http://www.sqlalchemy.org/trac/ticket/198 148 153 149 - somehow support things like described at: 154 150 http://spyced.blogspot.com/2007/01/why-sqlalchemy-impresses-me.html -
elixir/trunk/elixir/ext/versioned.py
r217 r218 2 2 A versioning plugin for Elixir. 3 3 4 Entities that are marked as versioned wi ll automatically have a history table5 created and a timestamp and version column added to their tables. In addition, 6 versioned entities are provided with four new methods: revert, revert_to, and 7 compare_with, get_as_of, and one new attribute: versions. Entities with8 compound primary keys are supported.4 Entities that are marked as versioned with the `acts_as_versioned` statement 5 will automatically have a history table created and a timestamp and version 6 column added to their tables. In addition, versioned entities are provided 7 with four new methods: revert, revert_to, compare_with and get_as_of, and one 8 new attribute: versions. Entities with compound primary keys are supported. 9 9 10 10 The `versions` attribute will contain a list of previous versions of the … … 34 34 decorate methods on the versioned entity that will be called following that 35 35 instance being reverted. 36 37 The acts_as_versioned statement also accepts an optional `ignore` argument 38 that consists of a list of strings, specifying names of fields. Changes in 39 those fields will not result in a version increment. 36 40 37 41 Note that relationships that are stored in mapping tables will not be included … … 107 111 # to ensure we really should save this version and update the version 108 112 # data. 113 ignored = instance.__class__.__ignored_fields__ 109 114 for key in instance.c.keys(): 110 if key in ['version', 'timestamp']:115 if key in ignored: 111 116 continue 112 117 if getattr(instance, key) != values[key]: … … 135 140 class ActsAsVersioned(object): 136 141 137 def __init__(self, entity ):142 def __init__(self, entity, ignore=[]): 138 143 entity._descriptor.add_mapper_extension(versioned_mapper_extension) 139 144 … … 144 149 entity._descriptor.add_field(timestampField) 145 150 self.entity = entity 151 152 # Changes in these fields 153 entity.__ignored_fields__ = ignore 154 entity.__ignored_fields__.extend(['version', 'timestamp']) 146 155 147 156 def after_table(self): -
elixir/trunk/tests/test_versioning.py
r208 r218 20 20 has_field('description', Unicode(512)) 21 21 has_field('releasedate', DateTime) 22 has_field('ignoreme', Integer, default=0) 22 23 belongs_to('director', of_kind='Director', inverse='movies') 23 24 has_and_belongs_to_many('actors', of_kind='Actor', inverse='movies', tablename='movie_casting') 24 25 using_options(tablename='movies') 25 acts_as_versioned( )26 acts_as_versioned(ignore=['ignoreme']) 26 27 27 28 … … 71 72 objectstore.flush(); objectstore.clear() 72 73 74 # Edit the ignored field, this shouldn't change the version 75 monkeys = Movie.get_by(title='12 Monkeys') 76 monkeys.ignoreme = 1 77 objectstore.flush(); objectstore.clear() 78 73 79 time.sleep(1) 74 80 after_update_two = datetime.now() … … 84 90 assert oldest_version.version == 1 85 91 assert oldest_version.description == 'draft description' 92 assert oldest_version.ignoreme == 0 86 93 87 94 assert middle_version.version == 2 … … 90 97 assert latest_version.version == 3 91 98 assert latest_version.description == 'description three' 99 assert latest_version.ignoreme == 1 92 100 93 101 differences = latest_version.compare_with(oldest_version)
