changeset 1002:d4c6cb532f72

merged
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 28 Oct 2011 20:27:29 -0200
parents 4115bfe5e657 (current diff) 99d81080b98e (diff)
children 9fd0a6a988bb b65a998fab8e
files
diffstat 2 files changed, 39 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/apps/feed/_tests/test_feed.py	Fri Oct 28 20:24:40 2011 -0200
+++ b/MoinMoin/apps/feed/_tests/test_feed.py	Fri Oct 28 20:27:29 2011 -0200
@@ -7,6 +7,9 @@
 
 from MoinMoin._tests import wikiconfig
 
+from MoinMoin.items import Item
+from MoinMoin.config import CONTENTTYPE, COMMENT
+from MoinMoin._tests import update_item
 
 class TestFeeds(object):
     class Config(wikiconfig.Config):
@@ -23,3 +26,22 @@
             assert '<feed xmlns="http://www.w3.org/2005/Atom">' in rv.data
             assert '</feed>' in rv.data
 
+    def test_global_atom_with_an_item(self):
+        basename = u'Foo'
+        item = update_item(basename, {COMMENT: u"foo data for feed item"}, '')
+        with self.app.test_client() as c:
+            rv = c.get('/+feed/atom')
+            assert rv.status == '200 OK'
+            assert rv.headers['Content-Type'] == 'application/atom+xml'
+            assert rv.data.startswith('<?xml')
+            assert "foo data for feed item" in rv.data
+
+        # tests the cache invalidation
+        update_item(basename, {COMMENT: u"checking if the cache invalidation works"}, '')
+        with self.app.test_client() as c:
+            rv = c.get('/+feed/atom')
+            assert rv.status == '200 OK'
+            assert rv.headers['Content-Type'] == 'application/atom+xml'
+            assert rv.data.startswith('<?xml')
+            assert "checking if the cache invalidation works" in rv.data
+
--- a/MoinMoin/apps/feed/views.py	Fri Oct 28 20:24:40 2011 -0200
+++ b/MoinMoin/apps/feed/views.py	Fri Oct 28 20:27:29 2011 -0200
@@ -25,13 +25,14 @@
 from MoinMoin import wikiutil
 from MoinMoin.i18n import _, L_, N_
 from MoinMoin.apps.feed import feed
-from MoinMoin.config import NAME, NAME_EXACT, WIKINAME, ACL, ACTION, ADDRESS, HOSTNAME, USERID, COMMENT, MTIME, REVID, ALL_REVS
+from MoinMoin.config import (NAME, NAME_EXACT, WIKINAME, ACL, ACTION, ADDRESS,
+                            HOSTNAME, USERID, COMMENT, MTIME, REVID, ALL_REVS,
+                            PARENTID, LATEST_REVS)
 from MoinMoin.themes import get_editor_info
 from MoinMoin.items import Item
 from MoinMoin.util.crypto import cache_key
 from MoinMoin.util.interwiki import url_for_item
 
-
 @feed.route('/atom/<itemname:item_name>')
 @feed.route('/atom', defaults=dict(item_name=''))
 def atom(item_name):
@@ -40,8 +41,17 @@
     # - full item in html is nice
     # - diffs in textmode are OK, but look very simple
     # - full-item content in textmode is OK, but looks very simple
-    cid = cache_key(usage="atom", item_name=item_name)
-    content = app.cache.get(cid)
+    query = Term(WIKINAME, app.cfg.interwikiname)
+    if item_name:
+        query = And([query, Term(NAME_EXACT, item_name), ])
+    revs = list(flaskg.storage.search(query, idx_name=LATEST_REVS, sortedby=[MTIME], reverse=True, limit=1))
+    if revs:
+        rev = revs[0]
+        cid = cache_key(usage="atom", revid=rev.revid, item_name=item_name)
+        content = app.cache.get(cid)
+    else:
+        content = None
+        cid = None
     if content is None:
         title = app.cfg.sitename
         feed = AtomFeed(title=title, feed_url=request.url, url=request.host_url)
@@ -75,9 +85,10 @@
                      content=content, content_type=content_type,
                      author=get_editor_info(rev.meta, external=True),
                      url=url_for_item(name, rev=this_revid, _external=True),
-                     updated=rev.meta[MTIME],
+                     updated=datetime.fromtimestamp(rev.meta[MTIME]),
                     )
         content = feed.to_string()
-        app.cache.set(cid, content)
+        if cid is not None:
+            app.cache.set(cid, content)
     return Response(content, content_type='application/atom+xml')