From 61aab6502ad604291dcf3c749059251dae50a719 Mon Sep 17 00:00:00 2001 From: philipp Date: Fri, 8 Oct 2010 20:01:07 +0000 Subject: [PATCH] The debug version of atom feeds work. git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/feed@585 7aebc617-e5e2-0310-91dc-80fb5f6d2477 --- feed.egg-info/PKG-INFO | 2 +- feed.egg-info/SOURCES.txt | 7 +++- feed/config/environment.py | 8 ++--- feed/config/routing.py | 7 ++++ feed/controllers/berichte.py | 66 ++++++++++++++++++++++++++---------- setup.py | 6 ++-- 6 files changed, 69 insertions(+), 27 deletions(-) diff --git a/feed.egg-info/PKG-INFO b/feed.egg-info/PKG-INFO index ad4d008..f07b587 100644 --- a/feed.egg-info/PKG-INFO +++ b/feed.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: feed -Version: 0.1dev +Version: 0.1dev-r584 Summary: UNKNOWN Home-page: UNKNOWN Author: UNKNOWN diff --git a/feed.egg-info/SOURCES.txt b/feed.egg-info/SOURCES.txt index 1abb458..611d75b 100644 --- a/feed.egg-info/SOURCES.txt +++ b/feed.egg-info/SOURCES.txt @@ -1,7 +1,10 @@ MANIFEST.in README.txt +ez_setup.py setup.cfg setup.py +test.ini +docs/index.txt feed/__init__.py feed/websetup.py feed.egg-info/PKG-INFO @@ -18,6 +21,7 @@ feed/config/environment.py feed/config/middleware.py feed/config/routing.py feed/controllers/__init__.py +feed/controllers/berichte.py feed/controllers/error.py feed/lib/__init__.py feed/lib/app_globals.py @@ -32,4 +36,5 @@ feed/public/pylons-logo.gif feed/templates/__init__.py feed/tests/__init__.py feed/tests/test_models.py -feed/tests/functional/__init__.py \ No newline at end of file +feed/tests/functional/__init__.py +feed/tests/functional/test_berichte.py \ No newline at end of file diff --git a/feed/config/environment.py b/feed/config/environment.py index d8ab077..811e404 100644 --- a/feed/config/environment.py +++ b/feed/config/environment.py @@ -36,12 +36,12 @@ def load_environment(global_conf, app_conf): # Create the Genshi TemplateLoader - config['pylons.app_globals'].genshi_loader = TemplateLoader( - paths['templates'], auto_reload=True) + #config['pylons.app_globals'].genshi_loader = TemplateLoader( + # paths['templates'], auto_reload=True) # Setup the SQLAlchemy database engine - engine = engine_from_config(config, 'sqlalchemy.') - init_model(engine) + #engine = engine_from_config(config, 'sqlalchemy.') + #init_model(engine) # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) diff --git a/feed/config/routing.py b/feed/config/routing.py index ccd1d20..cb07750 100644 --- a/feed/config/routing.py +++ b/feed/config/routing.py @@ -3,6 +3,13 @@ The more specific and detailed routes should be defined first so they may take precedent over the more generic routes. For more information refer to the routes manual at http://routes.groovie.org/docs/ + +Format: + http://www.winterrodeln.org/feeds/berichte/alle + http://www.winterrodeln.org/feeds/berichte/bahn/kemater_alm + http://www.winterrodeln.org/feeds/berichte/bahnen/22+42+132 +See: + http://www.winterrodeln.org/trac/wiki/UrlSchema """ from routes import Mapper diff --git a/feed/controllers/berichte.py b/feed/controllers/berichte.py index 4f97f3e..3b45147 100644 --- a/feed/controllers/berichte.py +++ b/feed/controllers/berichte.py @@ -13,7 +13,6 @@ See: """ import sys import datetime -# from elementtree.ElementTree import Element, SubElement, tostring from xml.etree.ElementTree import Element, SubElement, tostring from sqlalchemy.engine import create_engine @@ -28,28 +27,47 @@ from feed.lib.base import BaseController, render log = logging.getLogger(__name__) -def create_feed(engine): - param_page_title = None +def create_feed(page_title=None, page_ids=None): + """If a page_title is given, only the reports for the given sled are shown. + If a list of page_ids is given, only the reports for the selected pages are shown. + Otherwise, all reports are shown.""" + engine = create_engine(config['sqlalchemy.url']) conn = engine.connect() - if param_page_title is None: - sql = "select id, page_title, date_report, date_entry, `condition`, description, author_name, author_username from wrreport where date_invalid > now() and delete_date is null order by id desc limit 50" + + select = "select id, page_title, date_report, date_entry, `condition`, description, author_name, author_username from wrreport " + if not page_title is None: + # page_title is given + sql = select + "where lcase(page_title) = lcase(%s) and date_invalid > now() and delete_date is null order by id desc limit 50" + result = conn.execute(sql, page_title) + elif not page_ids is None: + # a list of page_ids is given + sql = [select + "where "] + if len(page_ids) > 0: + sql += '(' + sql += " or ".join(['page_id=%s' for page_id in page_ids]) + sql += ') ' + sql += 'and date_invalid > now() and delete_date is null order by id desc limit 50' + page_ids_str = [str(page_id) for page_id in page_ids] + result = conn.execute("".join(sql), *page_ids_str) + else: + # user wants to have all reports + sql = select + "where date_invalid > now() and delete_date is null order by id desc limit 50" # Debug: - sql = "select id, page_title, date_report, date_entry, `condition`, description, author_name, author_username from wrreport where delete_date is null order by id limit 5" + sql = select + "where delete_date is null order by id limit 5" result = conn.execute(sql) - else: - sql = "select id, page_title, date_report, date_entry, `condition`, description, author_name, author_username from wrreport where page_title ilike ? and date_invalid > now() and delete_date is null order by id desc limit 50" - result = conn.execute(sql, param_page_title) feed = Element("feed", xmlns="http://www.w3.org/2005/Atom") feed_title = SubElement(feed, "title") feed_title.text = "Winterrodeln Rodelbahnberichte" feed_id = SubElement(feed, "id") - if param_page_title is None: - feed_id.text = "http://www.winterrodeln.org/feeds/schneelage" + if not page_title is None: + feed_id.text = url(controller='berichte', action='bahn', id=page_title) + elif not page_ids is None: + feed_id.text = url(controller='berichte', action='bahnen', id="+".join(page_ids_str)) else: - feed_id.text = "http://www.winterrodeln.org/feeds/schneelage/{0}".format(param_page_title.replace(u' ', u'_')) + feed_id.text = url(controller='berichte', action='alle') feed_updated = SubElement(feed, "updated") feed.append(Element("link", rel="self", href=feed_id.text)) @@ -97,9 +115,21 @@ def create_feed(engine): class BerichteController(BaseController): - def index(self): - # Return a rendered template - #return render('/berichte.mako') - # or, return a response - engine = create_engine(config['sqlalchemy.url']) - return create_feed(engine) + def alle(self): + """http://www.winterrodeln.org/feeds/berichte/alle""" + response.content_type = 'application/atom+xml' + return create_feed() + + + def bahn(self, id): + """http://www.winterrodeln.org/feeds/berichte/bahn/kemater_alm""" + response.content_type = 'application/atom+xml' + return create_feed(page_title=id) + + + def bahnen(self, id): + """http://www.winterrodeln.org/feeds/berichte/bahnen/22+42+132""" + page_ids = id.split('+') + page_ids = [int(page_id) for page_id in page_ids] + response.content_type = 'application/atom+xml' + return create_feed(page_ids=page_ids) diff --git a/setup.py b/setup.py index 838b742..9dd0ea9 100644 --- a/setup.py +++ b/setup.py @@ -8,9 +8,9 @@ except ImportError: setup( name='feed', version='0.1', - description='', - author='', - author_email='', + description='Provides Atom Feed for Winterrodeln snow reports', + author='Philipp Spitzer', + author_email='philipp.spitzer@winterrodeln.org', url='', install_requires=[ "Pylons>=0.10", -- 2.39.5