def search(request, format): NUM_RESULTS = 20 query = request.GET.get('q', '') try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') if scale not in range(1, 257): return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256') if not query: return HttpResponseBadRequest('/search.opml|txt|json?q={query}') results = search_podcasts(query)[:NUM_RESULTS] title = _('gpodder.net - Search') domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) return format_podcast_list( results, format, title, json_map=p_data, jsonp_padding=request.GET.get('jsonp', ''), xml_template='podcasts.xml', request=request, )
def example_podcasts(request, format): podcasts = cache.get('example-podcasts', None) try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') if scale not in range(1, 257): return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256') if not podcasts: podcasts = ExamplePodcast.objects.get_podcasts() cache.set('example-podcasts', podcasts) title = 'gPodder Podcast Directory' domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) return format_podcast_list( podcasts, format, title, json_map=p_data, xml_template='podcasts.xml', request=request, )
def example_podcasts(request, format): podcasts = cache.get("example-podcasts", None) try: scale = int(request.GET.get("scale_logo", 64)) except (TypeError, ValueError): return HttpResponseBadRequest("scale_logo has to be a numeric value") if scale not in range(1, 257): return HttpResponseBadRequest("scale_logo has to be a number from 1 to 256") if not podcasts: podcasts = list(ExamplePodcast.objects.get_podcasts()) cache.set("example-podcasts", podcasts) podcast_ad = Podcast.objects.get_advertised_podcast() if podcast_ad: podcasts = [podcast_ad] + podcasts title = "gPodder Podcast Directory" domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) return format_podcast_list( podcasts, format, title, json_map=p_data, xml_template="podcasts.xml", request=request, )
def example_podcasts(request, format): podcasts = cache.get('example-podcasts', None) try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') if scale not in range(1, 257): return HttpResponseBadRequest( 'scale_logo has to be a number from 1 to 256') if not podcasts: podcasts = ExamplePodcast.objects.get_podcasts() cache.set('example-podcasts', podcasts) title = 'gPodder Podcast Directory' domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) return format_podcast_list( podcasts, format, title, json_map=p_data, xml_template='podcasts.xml', request=request, )
def search(request, format): NUM_RESULTS = 20 query = request.GET.get("q", "") try: scale = int(request.GET.get("scale_logo", 64)) except (TypeError, ValueError): return HttpResponseBadRequest("scale_logo has to be a numeric value") if scale not in range(1, 257): return HttpResponseBadRequest("scale_logo has to be a number from 1 to 256") if not query: return HttpResponseBadRequest("/search.opml|txt|json?q={query}") results = search_podcasts(query)[:NUM_RESULTS] title = _("gpodder.net - Search") domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) return format_podcast_list( results, format, title, json_map=p_data, jsonp_padding=request.GET.get("jsonp", ""), xml_template="podcasts.xml", request=request, )
def suggestions(request, count, format): count = parse_range(count, 1, 100, 100) suggestion_obj = suggestions_for_user(request.user) suggestions = suggestion_obj.get_podcasts(count) title = _('gpodder.net - %(count)d Suggestions') % {'count': len(suggestions)} domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain) return format_podcast_list(suggestions, format, title, json_map=p_data, jsonp_padding=request.GET.get('jsonp'))
def suggestions(request, count, format): count = parse_range(count, 1, 100, 100) user = request.user suggestions = Podcast.objects.filter(podcastsuggestion__suggested_to=user, podcastsuggestion__deleted=False) title = _('gpodder.net - %(count)d Suggestions') % {'count': len(suggestions)} domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain) return format_podcast_list(suggestions, format, title, json_map=p_data, jsonp_padding=request.GET.get('jsonp'))
def json_map(t): old_pos, podcast = t podcast.old_pos = old_pos p = podcast_data(podcast, domain, scale) p.update(dict( subscribers = podcast.subscriber_count(), subscribers_last_week = podcast.prev_subscriber_count(), position_last_week = podcast.old_pos, )) return p
def get_subscription_changes(self, user, device, since, now, domain): """gets new, removed and current subscriptions""" history = get_subscription_history(user, device, since, now) add, rem = subscription_diff(history) subscriptions = device.get_subscribed_podcasts() add = [podcast_data(p, domain) for p in add] rem = [p.url for p in rem] return add, rem, subscriptions
def get_subscription_changes(self, user, device, since, now, domain): """ gets new, removed and current subscriptions """ history = get_subscription_history(user, device, since, now) add, rem = subscription_diff(history) subscriptions = device.get_subscribed_podcasts() add = [podcast_data(p, domain) for p in add] rem = [p.url for p in rem] return add, rem, subscriptions
def get_subscription_changes(self, device, since, now, domain): """ gets new, removed and current subscriptions """ # DB: get all podcast states for the device podcast_states = podcast_states_for_device(device.id) add, rem = subscription_changes(device.id, podcast_states, since, now) subscriptions = filter(lambda s: s.is_subscribed_on(device), podcast_states) # DB get podcast objects for the subscribed podcasts subscriptions = podcasts_for_states(subscriptions) podcasts = dict( (p.url, p) for p in subscriptions ) add = [podcast_data(podcasts.get(url), domain) for url in add ] return add, rem, subscriptions
def all_subscriptions(request, username, format): try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') if scale not in range(1, 257): return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256') subscriptions = get_subscribed_podcasts(request.user) title = _('%(username)s\'s Subscription List') % {'username': username} domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) return format_podcast_list(subscriptions, format, title, json_map=p_data, xml_template='podcasts.xml', request=request)
def get_list(request, plist, owner, format): """ Returns the contents of the podcast list """ try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) title = '{title} by {username}'.format(title=plist.title, username=owner.username) objs = [entry.content_object for entry in plist.entries.all()] return format_podcast_list(objs, format, title, json_map=p_data, jsonp_padding=request.GET.get('jsonp', ''), xml_template='podcasts.xml', request=request)
def get_list(request, plist, owner, format): """ Returns the contents of the podcast list """ try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') podcasts = Podcast.get_multi(plist.podcasts) domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) title = '{title} by {username}'.format(title=plist.title, username=owner.username) return format_podcast_list(podcasts, format, title, json_map=p_data, jsonp_padding=request.GET.get('jsonp', ''), xml_template='podcasts.xml', request=request)
def json_map(t): podcast = t p = podcast_data(podcast, domain, scale) return p
def get_podcast_data(podcasts, domain, url): """ Gets podcast data for a URL from a dict of podcasts """ podcast = podcasts.get(url) return podcast_data(podcast, domain)