Changeset 336

Show
Ignore:
Timestamp:
06/13/08 17:12:38 (5 years ago)
Author:
ged
Message:

update Elixir to work with SA0.5

Location:
elixir/trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/CHANGES

    r327 r336  
    1212  identity for an entity. It also accepts a callable so that you can generate 
    1313  the identity name automatically from the class itself. 
     14 
     15Changes: 
     16- require SQLAlchemy 0.4 
    1417 
    1518Bug fixes: 
  • elixir/trunk/elixir/entity.py

    r335 r336  
    1414                                          ForeignKeyConstraint 
    1515from sqlalchemy.orm                import Query, MapperExtension, \ 
    16                                           mapper, object_session, EXT_PASS, \ 
     16                                          mapper, object_session, \ 
     17                                          EXT_CONTINUE, \ 
    1718                                          polymorphic_union 
    18 from sqlalchemy.ext.sessioncontext import SessionContext 
     19try: 
     20    from sqlalchemy.ext.sessioncontext import SessionContext 
     21except ImportError: 
     22    # Probably on sqlalchemy version 0.5 
     23    pass 
    1924 
    2025import elixir 
     
    331336                    ret = func(instance) 
    332337                    # I couldn't commit myself to force people to  
    333                     # systematicaly return EXT_PASS in all their event methods. 
     338                    # systematicaly return EXT_CONTINUE in all their event  
     339                    # methods. 
    334340                    # But not doing that diverge to how SQLAlchemy works. 
    335                     # I should try to convince Mike to do EXT_PASS by default, 
    336                     # and stop processing as the special case. 
    337 #                    if ret != EXT_PASS: 
    338                     if ret is not None and ret != EXT_PASS: 
     341                    # I should try to convince Mike to do EXT_CONTINUE by  
     342                    # default, and stop processing as the special case. 
     343#                    if ret != EXT_CONTINUE: 
     344                    if ret is not None and ret != EXT_CONTINUE: 
    339345                        return ret 
    340                 return EXT_PASS 
     346                return EXT_CONTINUE 
    341347            return proxy_method 
    342348 
  • elixir/trunk/elixir/ext/encrypted.py

    r267 r336  
    2929from Crypto.Cipher          import Blowfish  
    3030from elixir.statements      import Statement 
    31 from sqlalchemy.orm         import MapperExtension, EXT_PASS 
     31from sqlalchemy.orm         import MapperExtension, EXT_CONTINUE 
    3232 
    3333__all__ = ['acts_as_encrypted'] 
     
    7373            def before_insert(self, mapper, connection, instance): 
    7474                perform_encryption(instance) 
    75                 return EXT_PASS 
     75                return EXT_CONTINUE 
    7676             
    7777            def before_update(self, mapper, connection, instance):        
    7878                perform_encryption(instance) 
    79                 return EXT_PASS 
     79                return EXT_CONTINUE 
    8080             
    8181            def populate_instance(self, mapper, selectcontext, row, instance,  
    8282                                  *args, **kwargs): 
     83                #FIXME: this is not available anymore in 0.5 
     84                #<jek> Gedd: on_load will do what you want here.   
     85                #the example in test/orm/instrumentation is the most succinct 
    8386                mapper.populate_instance(selectcontext, instance, row,  
    8487                                         *args, **kwargs) 
  • elixir/trunk/elixir/ext/versioned.py

    r312 r336  
    5050 
    5151from sqlalchemy            import Table, Column, and_, desc 
    52 from sqlalchemy.orm        import mapper, MapperExtension, EXT_PASS, \ 
     52from sqlalchemy.orm        import mapper, MapperExtension, EXT_CONTINUE, \ 
    5353                                  object_session 
    5454 
     
    8989        instance.version = 1 
    9090        instance.timestamp = datetime.now() 
    91         return EXT_PASS 
     91        return EXT_CONTINUE 
    9292             
    9393    def before_update(self, mapper, connection, instance): 
     
    100100        # data. 
    101101        ignored = instance.__class__.__ignored_fields__ 
    102         for key in instance.c.keys(): 
     102        for key in instance.table.c.keys(): 
    103103            if key in ignored: 
    104104                continue 
     
    111111                break 
    112112 
    113         return EXT_PASS 
     113        return EXT_CONTINUE 
    114114         
    115115    def before_delete(self, mapper, connection, instance): 
     
    117117            get_history_where(instance) 
    118118        )) 
    119         return EXT_PASS 
     119        return EXT_CONTINUE 
    120120 
    121121 
     
    184184            v = object_session(self).query(Version) \ 
    185185                                    .filter(get_history_where(self)) \ 
    186                                     .order_by(Version.c.version) \ 
     186                                    .order_by(Version.version) \ 
    187187                                    .all() 
    188188            # history contains all the previous records. 
     
    201201            query = object_session(self).query(Version) 
    202202            query = query.filter(and_(get_history_where(self),  
    203                                       Version.c.timestamp <= dt)) 
    204             query = query.order_by(desc(Version.c.timestamp)).limit(1) 
     203                                      Version.timestamp <= dt)) 
     204            query = query.order_by(desc(Version.timestamp)).limit(1) 
    205205            return query.first() 
    206206         
     
    231231        def compare_with(self, version): 
    232232            differences = {} 
    233             for column in self.c: 
     233            for column in self.table.c: 
    234234                if column.name in ('version', 'concurrent_version'): 
    235235                    continue 
  • elixir/trunk/elixir/options.py

    r323 r336  
    3131|                     | ``multi``. Defaults to ``single``.                    | 
    3232|                     | Note that polymorphic concrete inheritance is         | 
    33 |                     | currently not implemented.                            | 
     33|                     | currently not implemented. See:                       | 
     34|                     | http://www.sqlalchemy.org/docs/04/mappers.html        | 
     35|                     | #advdatamapping_mapper_inheritance for an explanation | 
     36|                     | of the different kinds of inheritances.               | 
    3437+---------------------+-------------------------------------------------------+ 
    3538| ``polymorphic``     | Whether the inheritance should be polymorphic or not. | 
  • elixir/trunk/setup.py

    r323 r336  
    2525      license = "MIT License", 
    2626      install_requires = [ 
    27           "SQLAlchemy >= 0.3.9" 
     27          "SQLAlchemy >= 0.4.0" 
    2828      ], 
    2929      packages=find_packages(exclude=['ez_setup', 'tests', 'examples']), 
  • elixir/trunk/tests/test_associable.py

    r310 r336  
    8484        assert '123 Elm St.' in streets 
    8585         
    86         people = Person.select_addresses(and_(Address.c.street=='132 Elm St', 
    87                                               Address.c.city=='Smallville')) 
     86        people = Person.select_addresses(and_(Address.street=='132 Elm St', 
     87                                              Address.city=='Smallville')) 
    8888        assert len(people) == 0 
    8989 
  • elixir/trunk/tests/test_options.py

    r310 r336  
    114114 
    115115    def test_session_context(self): 
    116         from sqlalchemy.ext.sessioncontext import SessionContext 
     116        try: 
     117            from sqlalchemy.ext.sessioncontext import SessionContext 
     118        except ImportError: 
     119            # we are probably on SQLAlchemy 0.5, no need to test this. 
     120            return 
    117121 
    118122        engine = create_engine('sqlite:///') 
  • elixir/trunk/tests/test_sa_integration.py

    r329 r336  
    2525            Column('id', Integer, primary_key=True), 
    2626            Column('name', String(60)), 
    27             Column('a_id', Integer, ForeignKey(A.c.id)) 
     27            Column('a_id', Integer, ForeignKey(A.id)) 
    2828        ) 
    2929        b_table.create()