Changeset 261:095fc2d3d2ba
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r201
|
r261
|
|
| 4 | 4 | from sqlalchemy import Column, Table, ForeignKey |
| 5 | 5 | from sqlalchemy.types import * |
| 6 | | from sqlalchemy.orm import relation, backref |
| | 6 | from sqlalchemy.orm import relation, backref, class_mapper |
| 7 | 7 | |
| 8 | 8 | from meta import * |
| … |
… |
|
| 45 | 45 | ) |
| 46 | 46 | |
| | 47 | class 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 |
| 47 | 55 | |
| 48 | | class Work(object): |
| | 56 | def __repr__(self): |
| | 57 | return self.__str__() |
| | 58 | |
| | 59 | |
| | 60 | class Work(DomainObject): |
| 49 | 61 | |
| 50 | 62 | @classmethod |
| … |
… |
|
| 52 | 64 | return self.query.filter_by(name=name).first() |
| 53 | 65 | |
| 54 | | class Material(object): |
| | 66 | |
| | 67 | class Material(DomainObject): |
| 55 | 68 | """Material related to Shakespeare (usually text of works and ancillary |
| 56 | 69 | matter such as introductions). |
| … |
… |
|
| 86 | 99 | |
| 87 | 100 | |
| 88 | | class Resource(object): |
| | 101 | class Resource(DomainObject): |
| 89 | 102 | def get_stream(self): |
| 90 | 103 | '''Get text (if any) associated with this material. |
| … |
… |
|
| 109 | 122 | |
| 110 | 123 | |
| 111 | | class Statistic(object): |
| | 124 | class Statistic(DomainObject): |
| 112 | 125 | pass |
| 113 | 126 | |