Changeset 218

Show
Ignore:
Timestamp:
10/11/07 09:49:28 (6 years ago)
Author:
ged
Message:
  • Applied patch from Stou Sandalski to add an "ignore" option to the
    versioning ext.
  • Minor improvements to the versioning ext.
  • updated TODO
Location:
elixir/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/TODO

    r210 r218  
    9797    Entity) defines a property will probably fail because of line 16. 
    9898 
    99 - Make the session context extension/assign_mapper optional 
    100  
    10199- I'm not sure it would be worth it but we might want to put a section 
    102100  "contributing" on the website. In that case it might be a good idea to point 
    103101  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 on 
    106   the entity base class. 
    107  
    108 - integrate the association proxy plugin 
    109   see ML thread about this 
    110102 
    111103- add __revision__ (+ svn property) to all elixir files? 
     
    151143    cfr http://www.sqlalchemy.org/trac/ticket/502 
    152144 
     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 
    153149- somehow support things like described at: 
    154150  http://spyced.blogspot.com/2007/01/why-sqlalchemy-impresses-me.html 
  • elixir/trunk/elixir/ext/versioned.py

    r217 r218  
    22A versioning plugin for Elixir. 
    33 
    4 Entities that are marked as versioned will automatically have a history table 
    5 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 with  
    8 compound primary keys are supported. 
     4Entities that are marked as versioned with the `acts_as_versioned` statement  
     5will automatically have a history table created and a timestamp and version 
     6column added to their tables. In addition, versioned entities are provided  
     7with four new methods: revert, revert_to, compare_with and get_as_of, and one  
     8new attribute: versions.  Entities with compound primary keys are supported. 
    99 
    1010The `versions` attribute will contain a list of previous versions of the 
     
    3434decorate methods on the versioned entity that will be called following that  
    3535instance being reverted. 
     36 
     37The acts_as_versioned statement also accepts an optional `ignore` argument  
     38that consists of a list of strings, specifying names of fields.  Changes in  
     39those fields will not result in a version increment. 
    3640 
    3741Note that relationships that are stored in mapping tables will not be included 
     
    107111        # to ensure we really should save this version and update the version 
    108112        # data. 
     113        ignored = instance.__class__.__ignored_fields__ 
    109114        for key in instance.c.keys(): 
    110             if key in ['version', 'timestamp']: 
     115            if key in ignored: 
    111116                continue 
    112117            if getattr(instance, key) != values[key]: 
     
    135140class ActsAsVersioned(object): 
    136141         
    137     def __init__(self, entity): 
     142    def __init__(self, entity, ignore=[]): 
    138143        entity._descriptor.add_mapper_extension(versioned_mapper_extension) 
    139144         
     
    144149        entity._descriptor.add_field(timestampField) 
    145150        self.entity = entity 
     151         
     152        # Changes in these fields  
     153        entity.__ignored_fields__ = ignore 
     154        entity.__ignored_fields__.extend(['version', 'timestamp']) 
    146155     
    147156    def after_table(self): 
  • elixir/trunk/tests/test_versioning.py

    r208 r218  
    2020        has_field('description', Unicode(512)) 
    2121        has_field('releasedate', DateTime) 
     22        has_field('ignoreme', Integer, default=0) 
    2223        belongs_to('director', of_kind='Director', inverse='movies') 
    2324        has_and_belongs_to_many('actors', of_kind='Actor', inverse='movies', tablename='movie_casting') 
    2425        using_options(tablename='movies') 
    25         acts_as_versioned() 
     26        acts_as_versioned(ignore=['ignoreme']) 
    2627 
    2728 
     
    7172        objectstore.flush(); objectstore.clear() 
    7273     
     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     
    7379        time.sleep(1) 
    7480        after_update_two = datetime.now() 
     
    8490        assert oldest_version.version == 1 
    8591        assert oldest_version.description == 'draft description' 
     92        assert oldest_version.ignoreme == 0 
    8693     
    8794        assert middle_version.version == 2 
     
    9097        assert latest_version.version == 3 
    9198        assert latest_version.description == 'description three' 
     99        assert latest_version.ignoreme == 1 
    92100     
    93101        differences = latest_version.compare_with(oldest_version)