Mercurial > hg > Feedworm
view Mapping.py @ 62:abc0516a1c0c
FeedEntry provides a static method for creating new entries: better modularization and support for working with the class in interactive mode. FeedUpdater's normalize method is a module function now, again for ease of use in interactive scenarios
author | dirk@xanthippe.ping.de |
---|---|
date | Wed, 28 Jul 2010 20:30:34 +0200 |
parents | b535bce50626 |
children | 525a52169f60 |
line wrap: on
line source
from Feed import Feed from FeedEntry import FeedEntry from Preference import Preference from sqlalchemy import Boolean from sqlalchemy import Column from sqlalchemy import DateTime from sqlalchemy import ForeignKey from sqlalchemy import Integer from sqlalchemy import MetaData from sqlalchemy import String from sqlalchemy import Table from sqlalchemy import Text from sqlalchemy.orm import mapper from sqlalchemy.orm import relation mappingDefined = False def createMapping(engine): """ Make sure the mapping is defined only once. This is not really needed for the feed updater or the GUI app but comes in handy when working interactively with the system. """ global mappingDefined if not mappingDefined: _createMapping(engine) mappingDefined = True def _createMapping(engine): metadata = MetaData(engine) feedTable = Table("feed", metadata, Column("pk", Integer, primary_key=True), Column("title", String(255), nullable=False), Column("rss_url", String(255), nullable=False), Column("update_interval", Integer, nullable=False), Column("next_update", DateTime, nullable=False), # when displaying an entry of this feed, do not display the summary but rather load # the link directly Column("auto_load_entry_link", Boolean, nullable=False) ) feedEntryTable = Table("feed_entry", metadata, Column("pk", Integer, primary_key=True), Column("create_timestamp", DateTime, nullable=False), Column("read", Integer, nullable=False), Column("id", String(255), nullable=False), Column("link", String(255), nullable=False), Column("title", Text, nullable=False), Column("summary", Text, nullable=False), Column("updated", DateTime), Column("feed_id", Integer, ForeignKey("feed.pk")) ) preferencesTable = Table("preference", metadata, Column("pk", Integer, primary_key=True), Column("key", String(255), nullable=False), Column("value", String(255), nullable=False) ) metadata.create_all() mapper(FeedEntry, feedEntryTable) mapper(Feed, feedTable, properties = { "entries" : relation(FeedEntry, backref="feed", lazy=True) } ) mapper(Preference, preferencesTable)