From 195a5151abd1ba7b5bab71653c560c056a44badf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stefan=20K=C3=B6gl?= Date: Tue, 10 Jun 2014 19:40:57 +0200 Subject: [PATCH] get Flattr / licensed podcasts from PostgreSQL --- .../general/_design/podcasts/views/flattr/map.js | 22 ---- .../_design/podcasts/views/flattr/reduce.js | 1 - .../general/_design/podcasts/views/license/map.js | 22 ---- .../_design/podcasts/views/license/reduce.js | 1 - doc/dev/couchdb-views.rst | 1 - mygpo/db/couchdb/podcast.py | 69 ------------- .../templates/directory/license-podcasts.html | 14 +-- mygpo/directory/templates/directory/licenses.html | 2 +- mygpo/directory/templates/flattr-podcasts.html | 4 +- mygpo/directory/views.py | 111 ++++++++++----------- .../podcasts/migrations/0003_auto_20140610_1752.py | 44 ++++++++ mygpo/podcasts/models.py | 19 +++- 12 files changed, 124 insertions(+), 186 deletions(-) delete mode 100644 couchdb/general/_design/podcasts/views/flattr/map.js delete mode 100644 couchdb/general/_design/podcasts/views/flattr/reduce.js delete mode 100644 couchdb/general/_design/podcasts/views/license/map.js delete mode 100644 couchdb/general/_design/podcasts/views/license/reduce.js create mode 100644 mygpo/podcasts/migrations/0003_auto_20140610_1752.py diff --git a/couchdb/general/_design/podcasts/views/flattr/map.js b/couchdb/general/_design/podcasts/views/flattr/map.js deleted file mode 100644 index f9a9b9a3..00000000 --- a/couchdb/general/_design/podcasts/views/flattr/map.js +++ /dev/null @@ -1,22 +0,0 @@ -function(doc) -{ - if (doc.doc_type == 'Podcast') - { - if(doc.flattr_url) - { - emit(null, null); - } - } - else if(doc.doc_type == 'PodcastGroup') - { - for(var n in doc.podcasts) - { - var podcast = doc.podcasts[n]; - if (podcast.flattr_url) - { - emit(null, null); - return; - } - } - } -} diff --git a/couchdb/general/_design/podcasts/views/flattr/reduce.js b/couchdb/general/_design/podcasts/views/flattr/reduce.js deleted file mode 100644 index c866cd72..00000000 --- a/couchdb/general/_design/podcasts/views/flattr/reduce.js +++ /dev/null @@ -1 +0,0 @@ -_count diff --git a/couchdb/general/_design/podcasts/views/license/map.js b/couchdb/general/_design/podcasts/views/license/map.js deleted file mode 100644 index 1157005e..00000000 --- a/couchdb/general/_design/podcasts/views/license/map.js +++ /dev/null @@ -1,22 +0,0 @@ -function(doc) -{ - if (doc.doc_type == 'Podcast') - { - if(doc.license) - { - emit(doc.license, null); - } - } - else if(doc.doc_type == 'PodcastGroup') - { - for(var n in doc.podcasts) - { - var podcast = doc.podcasts[n]; - if (podcast.license) - { - emit(podcast.license, null); - return; - } - } - } -} diff --git a/couchdb/general/_design/podcasts/views/license/reduce.js b/couchdb/general/_design/podcasts/views/license/reduce.js deleted file mode 100644 index c866cd72..00000000 --- a/couchdb/general/_design/podcasts/views/license/reduce.js +++ /dev/null @@ -1 +0,0 @@ -_count diff --git a/doc/dev/couchdb-views.rst b/doc/dev/couchdb-views.rst index 8c7c2ed1..1f6d65f9 100644 --- a/doc/dev/couchdb-views.rst +++ b/doc/dev/couchdb-views.rst @@ -76,7 +76,6 @@ Doc-Types: Podcast, PodcastGroup, PodcastSubscriberData * `podcasts/by_slug `_ * `podcasts/by_tag `_ * `podcasts/by_url `_ -* `podcasts/flattr `_ * `podcasts/groups_by_oldid `_ * `podcasts/podcasts_groups `_ * `podcasts/subscriber_data `_ diff --git a/mygpo/db/couchdb/podcast.py b/mygpo/db/couchdb/podcast.py index 92946603..aab11e18 100644 --- a/mygpo/db/couchdb/podcast.py +++ b/mygpo/db/couchdb/podcast.py @@ -408,75 +408,6 @@ def podcasts_need_update(limit=100): yield podcast -@cache_result(timeout=60*60) -def get_flattr_podcasts(offset=0, limit=20): - """ returns all podcasts that contain Flattr payment URLs """ - - r = Podcast.view('podcasts/flattr', - skip = offset, - limit = limit, - classes = [Podcast, PodcastGroup], - include_docs = True, - reduce = False, - ) - - podcasts = list(r) - - for podcast in podcasts: - if podcast.needs_update: - incomplete_obj.send_robust(sender=podcast) - - return podcasts - - -@cache_result(timeout=60*60) -def get_flattr_podcast_count(): - """ returns the number of podcasts that contain Flattr payment URLs """ - db = get_main_database() - r = get_single_result(db, 'podcasts/flattr') - return r['value'] - - -@cache_result(timeout=60*60) -def get_license_podcasts(offset=0, limit=20, license_url=None): - """ returns a page of podcasts w/ license information """ - - kwargs = {} - if license_url: - kwargs['key'] = license_url - - r = Podcast.view('podcasts/license', - skip = offset, - limit = limit, - classes = [Podcast, PodcastGroup], - include_docs = True, - reduce = False, - **kwargs - ) - - podcasts = list(r) - - for podcast in podcasts: - if podcast.needs_update: - incomplete_obj.send_robust(sender=podcast) - - return podcasts - - -@cache_result(timeout=60*60) -def get_license_podcast_count(license_url=None): - """ returns the number of podcasts that contain license information """ - - kwargs = {} - if license_url: - kwargs['key'] = license_url - - db = get_main_database() - r = get_single_result(db, 'podcasts/license', **kwargs) - - return r['value'] if r else 0 - - def subscriberdata_for_podcast(podcast_id): if not podcast_id: diff --git a/mygpo/directory/templates/directory/license-podcasts.html b/mygpo/directory/templates/directory/license-podcasts.html index 8b4ec9ab..af1adf1b 100644 --- a/mygpo/directory/templates/directory/license-podcasts.html +++ b/mygpo/directory/templates/directory/license-podcasts.html @@ -10,10 +10,10 @@ {% block mainmenu %}{{ "/directory/+license"|main_menu }}{% endblock %} {% block sectionmenu %}{{ "/directory/+license"|section_menu }}{% endblock %} -{% block title %}{% blocktrans with license_url|license_name as licensename %}Podcasts with License {{ licensename }}{% endblocktrans %}{% endblock %} +{% block title %}{% blocktrans with view.license_url|license_name as licensename %}Podcasts with License {{ licensename }}{% endblocktrans %}{% endblock %} {% block header %} -

{% blocktrans with license_url|license_name as licensename %}Podcasts with License {{ licensename }}{% endblocktrans %}

+

{% blocktrans with view.license_url|license_name as licensename %}Podcasts with License {{ licensename }}{% endblocktrans %}

{% endblock %} {% block content %} @@ -24,7 +24,7 @@ {% trans "License overview" %} - + {% trans "View License" %} @@ -42,7 +42,7 @@ {% podcast_group_link podcast %} - {% vertical_bar podcast.subscriber_count max_subscribers %} + {% vertical_bar podcast.subscriber_count view.max_subscribers %} {% empty %} @@ -54,16 +54,16 @@