Changeset 292

Show
Ignore:
Timestamp:
01/14/08 20:38:20 (5 years ago)
Author:
cleverdevil
Message:

Support compound primary keys in acts_as_list.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/elixir/ext/list.py

    r289 r292  
    8383__all__ = ['acts_as_list'] 
    8484__doc_all__ = [] 
     85 
     86 
     87def get_entity_where(instance): 
     88    clauses = [] 
     89    for column in instance.table.primary_key.columns: 
     90        instance_value = getattr(instance, column.name) 
     91        clauses.append(column==instance_value) 
     92    return and_(*clauses) 
    8593 
    8694 
     
    135143            # move this item to the max position 
    136144            self.table.update( 
    137                 self.table.c.id == self.id, 
     145                get_entity_where(self), 
    138146                values={ 
    139147                    self.table.c.position : select( 
     
    158166 
    159167            # move this item to the first position 
    160             self.table.update(self.table.c.id == self.id).execute(position=1) 
     168            self.table.update(get_entity_where(self)).execute(position=1) 
    161169             
    162170         
     
    184192             
    185193            # update this item's position to the desired position 
    186             self.table.update(self.table.c.id==self.id).execute(position=position) 
     194            self.table.update(get_entity_where(self)).execute(position=position) 
    187195         
    188196