Changeset 261:095fc2d3d2ba

Show
Ignore:
Timestamp:
02/08/10 17:55:56 (6 months ago)
Author:
rgrp <http://rufuspollock.org>
Branch:
default
Message:

[model][s]: add a base DomainObject? with a str method and used it on main objects.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • shakespeare/model/dm.py

    r201 r261  
    44from sqlalchemy import Column, Table, ForeignKey 
    55from sqlalchemy.types import * 
    6 from sqlalchemy.orm import relation, backref 
     6from sqlalchemy.orm import relation, backref, class_mapper 
    77 
    88from meta import * 
     
    4545    ) 
    4646 
     47class DomainObject(object): 
     48    def __unicode__(self): 
     49        repr = u'<%s' % self.__class__.__name__ 
     50        table = class_mapper(self.__class__).mapped_table 
     51        for col in table.c: 
     52            repr += u' %s=%s' % (col.name, getattr(self, col.name)) 
     53        repr += '>' 
     54        return repr 
    4755 
    48 class Work(object): 
     56    def __repr__(self): 
     57        return self.__str__() 
     58 
     59 
     60class Work(DomainObject): 
    4961 
    5062    @classmethod 
     
    5264        return self.query.filter_by(name=name).first() 
    5365 
    54 class Material(object): 
     66 
     67class Material(DomainObject): 
    5568    """Material related to Shakespeare (usually text of works and ancillary 
    5669    matter such as introductions). 
     
    8699 
    87100 
    88 class Resource(object): 
     101class Resource(DomainObject): 
    89102    def get_stream(self): 
    90103        '''Get text (if any) associated with this material. 
     
    109122 
    110123 
    111 class Statistic(object): 
     124class Statistic(DomainObject): 
    112125    pass 
    113126