Changeset 96
- Timestamp:
- 03/27/07 11:15:20 (6 years ago)
- Location:
- elixir/trunk
- Files:
-
- 4 modified
-
CHANGES (modified) (2 diffs)
-
elixir/entity.py (modified) (2 diffs)
-
elixir/options.py (modified) (2 diffs)
-
tests/test_options.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/CHANGES
r95 r96 31 31 This shouldn't change anything to how it's used but allowed me to factor 32 32 some code with has_and_belongs_to_many relationships. 33 - The tablename option can now be given a callable so that people can provide 34 their own function to get the table name for an entity. The tablename option 35 can now also be set globally (using the options_defaults dictionary). Of 36 course, this only makes sense for the callable usecase. 37 33 38 - Fixed bug preventing having entities without any statement. 34 39 - Fixed documentation for belongs_to relationships (the arguemnt is "required", … … 40 45 - Actually make the code python 2.3 compatible (Robin's patch was based on 41 46 0.1.0 while I had introduced more decorators in the trunk in the mean time). 47 42 48 - Made some PEP8 tweaks in many places. Used the pep8 script provided with 43 49 Cheesecake. -
elixir/trunk/elixir/entity.py
r94 r96 65 65 # set default value for options 66 66 self.order_by = None 67 self.tablename = None68 67 self.table_args = list() 69 68 self.metadata = getattr(self.module, 'metadata', elixir.metadata) 70 69 71 70 for option in ('inheritance', 72 'autoload', 'shortnames', 'auto_primarykey', 71 'autoload', 'tablename', 'shortnames', 72 'auto_primarykey', 73 73 'version_id_col'): 74 74 setattr(self, option, options_defaults[option]) … … 93 93 tablename = "%s_%s" % (modulename, entity.__name__) 94 94 self.tablename = tablename.lower() 95 elif callable(self.tablename): 96 self.tablename = self.tablename(entity) 95 97 96 98 def setup(self): -
elixir/trunk/elixir/options.py
r83 r96 45 45 | | entities. | 46 46 +---------------------+-------------------------------------------------------+ 47 | ``tablename`` | Specify a custom tablename | 47 | ``tablename`` | Specify a custom tablename. You can either provide a | 48 | | plain string or a callable. The callable will be | 49 | | given the entity (ie class) as argument and must | 50 | | return a string representing the name of the table | 51 | | for that entity. | 48 52 +---------------------+-------------------------------------------------------+ 49 53 | ``shortnames`` | Usually tablenames include the full module-path | … … 117 121 autoload=None, 118 122 shortnames=False, 123 tablename=None, 119 124 auto_primarykey=True, 120 125 version_id_col=False, -
elixir/trunk/tests/test_options.py
r83 r96 54 54 pass 55 55 56 def test_tablename_func(self): 57 import re 58 59 def camel_to_underscore(entity): 60 return re.sub(r'(.+?)([A-Z])+?', r'\1_\2', entity.__name__).lower() 61 62 options_defaults['tablename'] = camel_to_underscore 63 64 class MyEntity(Entity): 65 has_field('name', Unicode(30)) 66 67 class MySuperTestEntity(Entity): 68 has_field('name', Unicode(30)) 69 70 assert MyEntity.table.name == 'my_entity' 71 assert MySuperTestEntity.table.name == 'my_super_test_entity' 72 73 options_defaults['tablename'] = None 74 56 75 def teardown(self): 57 76 cleanup_all()
