Changeset 3398

Show
Ignore:
Timestamp:
07/29/07 14:40:04 (1 year ago)
Author:
mscott
Message:

Merge #58 to trunk.

Allow nested transaction classes other than _Create, _Delete, and
_Update to subclass from T.Create, T.Delete, and T.Update and still
work properly.


Update documentation to show that you can customize custom-named
transaction subclasses.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Schevo/doc/SchevoTransactionHookMethods.txt

    r3189 r3398  
    1212======== 
    1313 
    14 When overriding the default implementations of Create, Delete, and Update 
    15 transactions for entity classes in a schema, there are hooks that make it 
    16 easy to change specific behavior. 
     14Transaction hooks make it easy to change specific behavior of default 
     15transaction classes.  You can customize the following behaviors: 
     16 
     17* Setup of a transaction instance. 
     18 
     19* What happens just before standard transaction execution. 
     20 
     21* What happens just after standard transaction execution. 
    1722 
    1823 
     
    4550                     
    4651        class _Update(T.Update): 
     52            ... 
     53 
     54You can also create custom transactions that have names that differ 
     55from the standard ones shown above.  Remember to set up a `t` method 
     56so you can create instances of your new transaction:: 
     57 
     58    class Foo(E.Entity): 
     59 
     60        bar = f.unicode() 
     61        count = f.integer() 
     62 
     63        def t_custom_update(self, **kw): 
     64            return E.Foo._CustomUpdate(self, **kw) 
     65 
     66        class _CustomUpdate(T.Update): 
    4767            ... 
    4868 
  • trunk/Schevo/schevo/entity.py

    r3306 r3398  
    202202        # Fields in a transaction class defined in the schema appear 
    203203        # below the fields that come from the entity field spec. 
    204         for name in ('_Create', '_Delete', '_Update'): 
    205             # Create a subclass. 
     204        for name in dir(cls): 
    206205            OldClass = getattr(cls, name) 
     206            if not isinstance(OldClass, type): 
     207                continue 
     208            if not issubclass(OldClass, (transaction.Create, 
     209                                         transaction.Delete, 
     210                                         transaction.Update)): 
     211                continue 
    207212            NewClass = type(name, (OldClass,), {}) 
    208213            NewClass._EntityClass = cls