Changeset 383

Show
Ignore:
Timestamp:
08/04/08 10:52:41 (4 years ago)
Author:
ged
Message:

removed support for the deprecated with_fields syntax

Location:
elixir/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/CHANGES

    r382 r383  
    99  underlying constructs 
    1010 
     11Changes: 
     12- removed support for the deprecated with_fields syntax 
    1113 
    12140.6.0 - 2008-07-18 
  • elixir/trunk/elixir/__init__.py

    r377 r383  
    3333from elixir.entity import Entity, EntityMeta, EntityDescriptor, \ 
    3434                          setup_entities, cleanup_entities 
    35 from elixir.fields import has_field, with_fields, Field 
     35from elixir.fields import has_field, Field 
    3636from elixir.relationships import belongs_to, has_one, has_many, \ 
    3737                                 has_and_belongs_to_many, \ 
     
    4545 
    4646__all__ = ['Entity', 'EntityMeta', 'EntityCollection', 'entities', 
    47            'Field', 'has_field', 'with_fields', 
     47           'Field', 'has_field', 
    4848           'has_property', 'GenericProperty', 'ColumnProperty', 'Synonym', 
    4949           'belongs_to', 'has_one', 'has_many', 'has_and_belongs_to_many', 
  • elixir/trunk/elixir/fields.py

    r370 r383  
    33entities. Elixir currently supports two syntaxes to do so: the default 
    44`Attribute-based syntax`_ as well as the has_field_ DSL statement. 
    5  
    6 Note that the old with_fields_ statement is currently deprecated in favor of 
    7 the `Attribute-based syntax`_. 
    85 
    96Attribute-based syntax 
     
    107104        has_field('id', Integer, primary_key=True) 
    108105        has_field('name', String(50)) 
    109  
    110  
    111 with_fields 
    112 ----------- 
    113 The `with_fields` statement is **deprecated** in favor of the `attribute-based 
    114 syntax`_. 
    115  
    116 It allows you to define all fields of an entity at once. 
    117 Each keyword argument to this statement represents one field, which should 
    118 be a `Field` object. The first argument to a Field object is its type. 
    119 Following it, any number of keyword arguments can be specified for 
    120 additional behavior. The `with_fields` statement supports the same keyword 
    121 arguments than the `has_field` statement. 
    122  
    123 Here is a quick example of how to use ``with_fields``. 
    124  
    125 .. sourcecode:: python 
    126  
    127     class Person(Entity): 
    128         with_fields( 
    129             id = Field(Integer, primary_key=True), 
    130             name = Field(String(50)) 
    131         ) 
    132106''' 
    133107import sys 
     
    148122 
    149123    This class represents a column on the table where the entity is stored. 
    150     This object is only used with the `with_fields` syntax for defining all 
    151     fields for an entity at the same time. The `has_field` syntax does not 
    152     require the manual creation of this object. 
    153124    ''' 
    154125 
     
    197168            self.property = deferred(self.column, group=group) 
    198169        elif self.name != self.colname: 
    199             # if the property name is different from the column name, we need  
     170            # if the property name is different from the column name, we need 
    200171            # to add an explicit property (otherwise nothing is needed as it's 
    201172            # done automatically by SA) 
     
    219190    field.attach(entity, name) 
    220191 
    221  
    222 def with_fields_handler(entity, *args, **fields): 
    223     for name, field in fields.iteritems(): 
    224         field.attach(entity, name) 
    225  
    226  
    227192has_field = ClassMutator(has_field_handler) 
    228 with_fields = ClassMutator(with_fields_handler) 
  • elixir/trunk/elixir/properties.py

    r382 r383  
    154154        super(GenericProperty, self).__init__(*args, **kwargs) 
    155155        self.prop = prop 
     156        #XXX: move this to Property? 
    156157        self.args = args 
    157158        self.kwargs = kwargs 
  • elixir/trunk/tests/test_fields.py

    r349 r383  
    4545 
    4646        assert p.surname == 'Simpson' 
    47  
    48     def test_with_fields(self): 
    49         class Person(Entity): 
    50             with_fields( 
    51                 firstname = Field(String(30)), 
    52                 surname = Field(String(30)) 
    53             ) 
    54  
    55         setup_all(True) 
    56  
    57         homer = Person(firstname="Homer", surname="Simpson") 
    58         bart = Person(firstname="Bart", surname="Simpson") 
    59  
    60         session.commit() 
    61         session.clear() 
    62  
    63         p = Person.get_by(firstname="Homer") 
    64  
    65         assert p.surname == 'Simpson' 
    66