Skip to content

Commit

Permalink
find podcasts by ids
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe committed Jun 26, 2016
1 parent 7ee595b commit 5bc19a6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions peterbecom/podcasttime/views.py
Expand Up @@ -56,9 +56,11 @@ def find(request):
return http.HttpResponseBadRequest('no ids or q')

if request.GET.get('ids'):
ids = request.GET['ids'].split(',')
ids = [int(x) for x in request.GET['ids'].split(',')]
found = Podcast.objects.filter(id__in=ids)
cache_key = 'podcastfind:ids:' + hashlib.md5(''.join(ids)).hexdigest()
# rearrange them in the order they were
found = sorted(found, key=lambda x: ids.index(x.id))
cache_key = 'podcastfind:ids:' + hashlib.md5(str(ids)).hexdigest()
else:
q = request.GET['q']
cache_key = 'podcastfind:' + hashlib.md5(q.encode('utf8')).hexdigest()
Expand Down Expand Up @@ -356,11 +358,16 @@ def podcasts(request):
def podcasts_data(request):
context = {}
search = request.GET.get('search', '').strip()
ids = request.GET.get('ids')

podcasts = Podcast.objects.all()
if search:
podcasts = _search_podcasts(search, podcasts)

if ids:
ids = [int(x) for x in ids.split(',') if x.strip()]
podcasts = podcasts.filter(id__in=ids)

podcasts = podcasts.order_by('-times_picked', 'name')

paginator = Paginator(podcasts, 15)
Expand Down

0 comments on commit 5bc19a6

Please sign in to comment.