Changeset 494 for elixir

Show
Ignore:
Timestamp:
10/02/09 14:30:48 (3 years ago)
Author:
ged
Message:

almost functional conversion

Location:
elixir/branches/field_inherits_from_column/elixir
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • elixir/branches/field_inherits_from_column/elixir/fields.py

    r484 r494  
    116116 
    117117 
    118 class Field(Property): 
     118class Field(Column, Property): 
    119119    ''' 
    120120    Represents the definition of a 'field' on an entity. 
     
    122122    This class represents a column on the table where the entity is stored. 
    123123    ''' 
    124  
     124    #FIXME: collision between prop.name & col.name 
    125125    def __init__(self, type, *args, **kwargs): 
    126         super(Field, self).__init__() 
     126        Property.__init__(self) 
    127127 
    128128        self.colname = kwargs.pop('colname', None) 
     
    134134        self.primary_key = kwargs.get('primary_key', False) 
    135135 
    136         self.column = None 
     136        Column.__init__(self, type, *args, **kwargs) 
    137137        self.property = None 
    138138 
     
    141141 
    142142    def attach(self, entity, name): 
     143        if self.key is None: 
     144            self.key = name 
     145        if self.name is None: 
     146            self.name = name 
     147 
    143148        # If no colname was defined (through the 'colname' kwarg), set 
    144149        # it to the name of the attr. 
     
    155160            self.create_col() 
    156161 
     162    @property 
     163    def column(self): 
     164        return self 
     165 
    157166    def create_col(self): 
    158         self.column = Column(self.colname, self.type, 
    159                              *self.args, **self.kwargs) 
    160         self.add_table_column(self.column) 
     167        self.add_table_column(self) 
    161168 
    162169    def create_properties(self): 
     
    165172            if isinstance(self.deferred, basestring): 
    166173                group = self.deferred 
    167             self.property = deferred(self.column, group=group) 
     174            self.property = deferred(self, group=group) 
    168175        elif self.name != self.colname: 
    169176            # if the property name is different from the column name, we need 
    170177            # to add an explicit property (otherwise nothing is needed as it's 
    171178            # done automatically by SA) 
    172             self.property = self.column 
     179            self.property = self 
    173180 
    174181        if self.property is not None: 
  • elixir/branches/field_inherits_from_column/elixir/properties.py

    r484 r494  
    105105        return instance 
    106106 
     107_global_counter = 0 
    107108 
    108109class Property(EntityBuilder): 
     
    110111    Abstract base class for all properties of an Entity. 
    111112    ''' 
    112     __metaclass__ = CounterMeta 
     113#    __metaclass__ = CounterMeta 
    113114 
    114115    def __init__(self, *args, **kwargs): 
     116        global _global_counter 
    115117        self.entity = None 
    116118        self.name = None 
     119        self._counter = _global_counter 
     120        _global_counter += 1 
    117121 
    118122    def attach(self, entity, name):