fix missing podcasts in podcast lists
authorStefan Kögl <stefan@skoegl.net>
Mon, 20 May 2013 13:14:23 +0000 (20 15:14 +0200)
committerStefan Kögl <stefan@skoegl.net>
Mon, 20 May 2013 13:14:23 +0000 (20 15:14 +0200)
Thanks for user Alexander_Wilms for reporting the bug!

mygpo/db/couchdb/podcast.py
mygpo/share/views.py

index 59a6c03..6284dee 100644 (file)
@@ -208,6 +208,41 @@ def podcasts_by_id(ids):
     return podcasts
 
 
+def podcasts_groups_by_id(ids):
+    """ gets podcast groups and top-level podcasts for the given ids """
+
+    if ids is None:
+        raise QueryParameterMissing('ids')
+
+    if not ids:
+        return
+
+    db = get_main_database()
+    res = db.view('_all_docs',
+            keys         = ids,
+            include_docs = True,
+            classes      = [Podcast, PodcastGroup],
+        )
+
+    for r in res:
+        doc = r['doc']
+        if doc['doc_type'] == 'Podcast':
+            obj = Podcast.wrap(doc)
+
+        elif doc['doc_type'] == 'PodcastGroup':
+            obj = PodcastGroup.wrap(doc)
+
+        else:
+            logger.error('podcasts_groups_by_id retrieved unknown doc_type '
+                '"%s" for params %s', doc['doc_type'], res.params)
+            continue
+
+        if obj.needs_update:
+            incomplete_obj.send_robust(sender=obj)
+
+        yield obj
+
+
 
 @cache_result(timeout=60*60)
 def podcast_for_oldid(oldid):
index 264fdc5..38620d4 100644 (file)
@@ -23,7 +23,7 @@ from mygpo.directory.views import search as directory_search
 from mygpo.decorators import repeat_on_conflict
 from mygpo.flattr import Flattr
 from mygpo.userfeeds.feeds import FavoriteFeed
-from mygpo.db.couchdb.podcast import podcasts_by_id, podcast_for_url
+from mygpo.db.couchdb.podcast import podcasts_groups_by_id, podcast_for_url
 from mygpo.db.couchdb.podcastlist import podcastlist_for_user_slug, \
          podcastlists_for_user
 from mygpo.data.feeddownloader import PodcastUpdater
@@ -92,7 +92,7 @@ def list_show(request, plist, owner):
 
     plist = proxy_object(plist)
 
-    podcasts = podcasts_by_id(plist.podcasts)
+    podcasts = list(podcasts_groups_by_id(plist.podcasts))
     plist.podcasts = podcasts
 
     max_subscribers = max([p.subscriber_count() for p in podcasts] + [0])
@@ -113,7 +113,7 @@ def list_show(request, plist, owner):
 
 @list_decorator(must_own=False)
 def list_opml(request, plist, owner):
-    podcasts = podcasts_by_id(plist.podcasts)
+    podcasts = podcasts_groups_by_id(plist.podcasts)
     return format_podcast_list(podcasts, 'opml', plist.title)