1 from random
import random
3 from django
.core
.cache
import cache
5 from mygpo
.share
.models
import PodcastList
6 from mygpo
.cache
import cache_result
7 from mygpo
.db
import QueryParameterMissing
11 def podcastlist_for_user_slug(user_id
, slug
):
14 raise QueryParameterMissing('user_id')
17 raise QueryParameterMissing('slug')
19 key
= 'plist-%s-%s' % (user_id
, slug
)
25 r
= PodcastList
.view('podcastlists/by_user_slug',
26 key
= [user_id
, slug
],
39 def podcastlists_for_user(user_id
):
42 raise QueryParameterMissing('user_id')
44 r
= PodcastList
.view('podcastlists/by_user_slug',
45 startkey
= [user_id
, None],
46 endkey
= [user_id
, {}],
53 @cache_result(timeout
=60*69)
54 def podcastlists_by_rating(**kwargs
):
55 r
= PodcastList
.view('podcastlists/by_rating',
58 stale
= 'update_after',
65 @cache_result(timeout
=60*60)
66 def podcastlist_count(with_rating
=True):
67 view
= 'podcastlists/by_rating' if with_rating
else \
68 'podcastlists/by_user_slug'
70 return PodcastList
.view(view
,
72 stale
= 'update_after',
77 def random_podcastlists(chunk_size
=1):
81 res
= PodcastList
.view('podcastlists/random',