Changeset 263
- Timestamp:
- 11/03/07 17:17:44 (6 years ago)
- Location:
- elixir/trunk
- Files:
-
- 6 modified
-
TODO (modified) (1 diff)
-
elixir/__init__.py (modified) (3 diffs)
-
elixir/ext/associable.py (modified) (1 diff)
-
elixir/ext/encrypted.py (modified) (5 diffs)
-
elixir/ext/versioned.py (modified) (4 diffs)
-
elixir/relationships.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/TODO
r253 r263 12 12 - multiple files (modules) models 13 13 - demonstrate common raltionships options (order_by, ...) 14 - inverse relationships matching (with a link to BehindTheScene) 14 15 15 16 ? autoload -
elixir/trunk/elixir/__init__.py
r254 r263 16 16 ''' 17 17 18 try: 19 set 20 except NameError: 21 from sets import Set as set 22 18 23 import sqlalchemy 19 20 24 from sqlalchemy.types import * 21 25 … … 26 30 from elixir.fields import has_field, with_fields, Field 27 31 from elixir.relationships import belongs_to, has_one, has_many, \ 28 has_and_belongs_to_many 29 from elixir.relationships importManyToOne, OneToOne, OneToMany, ManyToMany32 has_and_belongs_to_many, \ 33 ManyToOne, OneToOne, OneToMany, ManyToMany 30 34 from elixir.properties import has_property, GenericProperty, ColumnProperty 31 35 from elixir.statements import Statement 32 36 33 try:34 set35 except NameError:36 from sets import Set as set37 37 38 __version__ = '0.4. 0'38 __version__ = '0.4.1' 39 39 40 40 __all__ = ['Entity', 'EntityMeta', … … 51 51 52 52 __doc_all__ = ['create_all', 'drop_all', 53 'setup_all', 'cleanup_all',54 'metadata', 'session']53 'setup_all', 'cleanup_all', 54 'metadata', 'session'] 55 55 56 56 -
elixir/trunk/elixir/ext/associable.py
r236 r263 113 113 import elixir as el 114 114 import sqlalchemy as sa 115 116 __doc_all__ = ['associable'] 115 117 116 118 def associable(assoc_entity, plural_name=None, lazy=True): -
elixir/trunk/elixir/ext/encrypted.py
r236 r263 17 17 password = Field(Unicode) 18 18 ssn = Field(Unicode) 19 acts_as_encrypted(for_columns=['password', 'ssn'], with_secret='secret') 19 acts_as_encrypted(for_columns=['password', 'ssn'], 20 with_secret='secret') 20 21 21 22 The above Person entity will automatically encrypt and decrypt the password and … … 28 29 from sqlalchemy.orm import MapperExtension, EXT_PASS 29 30 31 __all__ = ['acts_as_encrypted'] 32 __doc_all__ = [] 30 33 31 34 # … … 34 37 35 38 def encrypt_value(value, secret): 36 return Blowfish.new(secret, Blowfish.MODE_CFB).encrypt(value).encode('string_escape') 39 return Blowfish.new(secret, Blowfish.MODE_CFB) \ 40 .encrypt(value).encode('string_escape') 37 41 38 42 def decrypt_value(value, secret): 39 return Blowfish.new(secret, Blowfish.MODE_CFB).decrypt(value.decode('string_escape')) 43 return Blowfish.new(secret, Blowfish.MODE_CFB) \ 44 .decrypt(value.decode('string_escape')) 40 45 41 46 … … 70 75 return EXT_PASS 71 76 72 def populate_instance(self, mapper, selectcontext, row, instance, *args, **kwargs): 73 mapper.populate_instance(selectcontext, instance, row, *args, **kwargs) 77 def populate_instance(self, mapper, selectcontext, row, instance, 78 *args, **kwargs): 79 mapper.populate_instance(selectcontext, instance, row, 80 *args, **kwargs) 74 81 perform_decryption(instance) 75 82 return True … … 81 88 acts_as_encrypted = Statement(ActsAsEncrypted) 82 89 83 84 __all__ = [85 'acts_as_encrypted'86 ] -
elixir/trunk/elixir/ext/versioned.py
r221 r263 44 44 ''' 45 45 46 from elixir import Integer, DateTime 47 from elixir.statements import Statement 46 from datetime import datetime 47 import inspect 48 48 49 from sqlalchemy import Table, Column, and_, desc 49 50 from sqlalchemy.orm import mapper, MapperExtension, EXT_PASS, \ 50 51 object_session 51 from datetime import datetime 52 53 import inspect 54 52 53 from elixir import Integer, DateTime 54 from elixir.statements import Statement 55 56 __all__ = ['acts_as_versioned', 'after_revert'] 57 __doc_all__ = [] 55 58 56 59 # … … 68 71 def get_history_where(instance): 69 72 clauses = [] 73 history_columns = instance.__history_table__.primary_key.columns 70 74 for column in instance.table.primary_key.columns: 71 75 instance_value = getattr(instance, column.name) 72 history_column = getattr( instance.__history_table__.primary_key.columns, column.name)76 history_column = getattr(history_columns, column.name) 73 77 clauses.append(history_column==instance_value) 74 78 return and_(*clauses) … … 184 188 # attach utility methods and properties to the entity 185 189 def get_versions(self): 186 return object_session(self).query(Version).filter(get_history_where(self)).all() 190 return object_session(self).query(Version) \ 191 .filter(get_history_where(self)) \ 192 .all() 187 193 188 194 def get_as_of(self, dt): … … 238 244 Version.compare_with = compare_with 239 245 240 #def acts_as_versioned_handler(entity, ignore=[]):241 # builder = VersionedEntityBuilder(entity, ignore)242 # entity._descriptor.builders.append(builder)243 244 #acts_as_versioned = ClassMutator(acts_as_versioned_handler)245 246 acts_as_versioned = Statement(VersionedEntityBuilder) 246 247 247 248 248 #249 # decorator for watching for revert events250 #251 252 249 def after_revert(func): 250 """ 251 Decorator for watching for revert events. 252 """ 253 253 func._elixir_after_revert = True 254 254 return func 255 255 256 256 257 __all__ = ['acts_as_versioned', 'after_revert'] -
elixir/trunk/elixir/relationships.py
r244 r263 725 725 # target's table 726 726 727 # In some databases (at leas eMySQL) the constraint names need727 # In some databases (at least MySQL) the constraint names need 728 728 # to be unique for the whole database, instead of per table. 729 729 source_fk_name = "%s_fk" % source_part
