def podcast_lists(request, page_size=20): lists = PodcastList.objects.all()\ .annotate(num_votes=Count('votes'))\ .order_by('-num_votes') paginator = Paginator(lists, page_size) page = request.GET.get('page') try: lists = paginator.page(page) except PageNotAnInteger: lists = paginator.page(1) page = 1 except EmptyPage: lists = paginator.page(paginator.num_pages) page = paginator.num_pages num_pages = int(ceil(PodcastList.objects.count() / float(page_size))) page_list = get_page_list(1, num_pages, int(page), 15) return render(request, 'podcast_lists.html', { 'lists': lists, 'page_list': page_list, })
def category(request, category, page_size=20): try: category = Category.objects.get(tags__tag=category) except Category.DoesNotExist: return HttpResponseNotFound() podcasts = category.entries.all()\ .prefetch_related('podcast', 'podcast__slugs') paginator = Paginator(podcasts, page_size) page = request.GET.get('page') try: podcasts = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. podcasts = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. podcasts = paginator.page(paginator.num_pages) page_list = get_page_list(1, paginator.num_pages, podcasts.number, 15) return render(request, 'category.html', { 'entries': podcasts, 'category': category.title, 'page_list': page_list, })
def search(request, template='search.html', args={}): if 'q' in request.GET: q = request.GET.get('q', '').encode('utf-8') try: page = int(request.GET.get('page', 1)) except ValueError: page = 1 results, total = search_podcasts(q=q, skip=RESULTS_PER_PAGE*(page-1)) num_pages = int(ceil(total / RESULTS_PER_PAGE)) page_list = get_page_list(1, num_pages, page, 15) else: results = [] q = None page_list = [] max_subscribers = max([p.subscriber_count() for p in results] + [0]) current_site = RequestSite(request) return render(request, template, dict( q= q, results= results, page_list= page_list, max_subscribers= max_subscribers, domain= current_site.domain, **args ))
def podcast_lists(request, page_size=20): # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 lists = podcastlists_by_rating(skip=(page-1) * page_size, limit=page_size) def _prepare_list(l): user = get_user_by_id(l.user) l = proxy_object(l) l.username = user.username if user else '' return l lists = map(_prepare_list, lists) num_pages = int(ceil(podcastlist_count() / float(page_size))) page_list = get_page_list(1, num_pages, page, 15) return render(request, 'podcast_lists.html', { 'lists': lists, 'page_list': page_list, })
def search(request, template="search.html", args={}): if "q" in request.GET: q = request.GET.get("q", "").encode("utf-8") try: page = int(request.GET.get("page", 1)) except ValueError: page = 1 results, total = search_podcasts(q=q, skip=RESULTS_PER_PAGE * (page - 1)) num_pages = total / RESULTS_PER_PAGE page_list = utils.get_page_list(1, num_pages, page, 15) else: results = [] q = None page_list = [] max_subscribers = max([p.subscriber_count() for p in results] + [0]) return render( request, template, dict(q=q, results=results, page_list=page_list, max_subscribers=max_subscribers, **args) )
def all_episodes(request, podcast, page_size=20): # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 user = request.user episodes = episode_list(podcast, user, (page-1) * page_size, page_size) episodes_total = podcast.episode_count or 0 num_pages = episodes_total / page_size page_list = get_page_list(1, num_pages, page, 15) listeners = [e.listeners for e in episodes if e.listeners is not None] max_listeners = max(listeners, default=0) is_publisher = check_publisher_permission(user, podcast) return render(request, 'episodes.html', { 'podcast': podcast, 'episodes': episodes, 'max_listeners': max_listeners, 'page_list': page_list, 'current_page': page, 'is_publisher': is_publisher, })
def all_episodes(request, podcast, page_size=20): # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 user = request.user episodes = episode_list(podcast, user, (page - 1) * page_size, page_size) episodes_total = podcast.episode_count or 0 num_pages = episodes_total / page_size page_list = get_page_list(1, num_pages, page, 15) listeners = [e.listeners for e in episodes if e.listeners is not None] max_listeners = max(listeners, default=0) is_publisher = check_publisher_permission(user, podcast) return render( request, 'episodes.html', { 'podcast': podcast, 'episodes': episodes, 'max_listeners': max_listeners, 'page_list': page_list, 'current_page': page, 'is_publisher': is_publisher, }, )
def podcast_lists(request, page_size=20): lists = PodcastList.objects.all()\ .annotate(num_votes=Count('votes'))\ .order_by('-num_votes') paginator = Paginator(lists, page_size) page = request.GET.get('page') try: lists = paginator.page(page) except PageNotAnInteger: lists = paginator.page(1) page = 1 except EmptyPage: lists = paginator.page(paginator.num_pages) page = paginator.num_pages num_pages = int(ceil(PodcastList.objects.count() / float(page_size))) page_list = get_page_list(1, num_pages, int(page), 15) return render(request, 'podcast_lists.html', { 'lists': lists, 'page_list': page_list, })
def search(request, template='search.html', args={}): if 'q' in request.GET: q = request.GET.get('q', '') try: page = int(request.GET.get('page', 1)) except ValueError: page = 1 start = RESULTS_PER_PAGE * (page - 1) results = search_podcasts(q) total = len(results) num_pages = int(ceil(total / RESULTS_PER_PAGE)) results = results[start:start + RESULTS_PER_PAGE] page_list = get_page_list(1, num_pages, page, 15) else: results = [] q = None page_list = [] max_subscribers = max([p.subscribers for p in results] + [0]) current_site = RequestSite(request) return render( request, template, dict(q=q, results=results, page_list=page_list, max_subscribers=max_subscribers, domain=current_site.domain, **args))
def category(request, category, page_size=20): try: category = Category.objects.get(tags__tag=category) except Category.DoesNotExist: return HttpResponseNotFound() podcasts = category.entries.all()\ .prefetch_related('podcast', 'podcast__slugs') paginator = Paginator(podcasts, page_size) page = request.GET.get('page') try: podcasts = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. podcasts = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. podcasts = paginator.page(paginator.num_pages) page_list = get_page_list(1, paginator.num_pages, podcasts.number, 15) return render(request, 'category.html', { 'entries': podcasts, 'category': category.title, 'page_list': page_list, })
def page_list(self, page_size=15): """ Return a list of pages, eg [1, 2, 3, '...', 6, 7, 8] """ page = self._page return get_page_list(1, page.paginator.num_pages, page.number, page.paginator.per_page, )
def category(request, category, page_size=20): category = Category.for_tag(category) if not category: return HttpResponseNotFound() # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get("page", "1")) except ValueError: page = 1 entries = category.get_podcasts((page - 1) * page_size, page * page_size) podcasts = filter(None, entries) num_pages = len(category.podcasts) / page_size page_list = utils.get_page_list(1, num_pages, page, 15) return render(request, "category.html", {"entries": podcasts, "category": category.label, "page_list": page_list})
def category(request, category, page_size=20): category = category_for_tag(category) if not category: return HttpResponseNotFound() # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get('page', '1')) except ValueError: page = 1 entries = category.get_podcasts( (page-1) * page_size, page*page_size ) podcasts = filter(None, entries) num_pages = int(ceil(len(category.podcasts) / page_size)) page_list = get_page_list(1, num_pages, page, 15) return render(request, 'category.html', { 'entries': podcasts, 'category': category.label, 'page_list': page_list, })
def podcast_lists(request, page_size=20): # Make sure page request is an int. If not, deliver first page. try: page = int(request.GET.get("page", "1")) except ValueError: page = 1 lists = PodcastList.by_rating(skip=(page - 1) * page_size, limit=page_size) def _prepare_list(l): user = User.get(l.user) l = proxy_object(l) l.username = user.username return l lists = map(_prepare_list, lists) num_pages = int(ceil(PodcastList.count() / float(page_size))) page_list = utils.get_page_list(1, num_pages, page, 15) return render(request, "podcast_lists.html", {"lists": lists, "page_list": page_list})
def podcast_lists(request, page_size=20): lists = (PodcastList.objects.all().annotate( num_votes=Count("votes")).order_by("-num_votes")) paginator = Paginator(lists, page_size) page = request.GET.get("page") try: lists = paginator.page(page) except PageNotAnInteger: lists = paginator.page(1) page = 1 except EmptyPage: lists = paginator.page(paginator.num_pages) page = paginator.num_pages num_pages = int(ceil(PodcastList.objects.count() / float(page_size))) page_list = get_page_list(1, num_pages, int(page), 15) return render(request, "podcast_lists.html", { "lists": lists, "page_list": page_list })
def show(request, podcast): """ Shows a podcast detail page """ podcast = check_restrictions(podcast) current_site = RequestSite(request) num_episodes = 20 episodes = episode_list(podcast, request.user, limit=num_episodes) user = request.user # TODO: move into EpisodeList (?) class listeners = [e.listeners for e in episodes if e.listeners is not None] max_listeners = max(listeners, default=0) episode = None if episodes: episode = episodes[0] episodes = episodes[1:] if podcast.group: group = podcast.group rel_podcasts = group.podcast_set.exclude(pk=podcast.pk) else: rel_podcasts = [] tags = get_tags(podcast, user) has_tagged = any(t['is_own'] for t in tags) if user.is_authenticated(): subscribed_devices = Client.objects.filter( subscription__user=user, subscription__podcast=podcast, ) subscribe_targets = get_subscribe_targets(podcast, user) has_history = HistoryEntry.objects.filter(user=user, podcast=podcast)\ .exists() can_flattr = (user.profile.settings.get_wksetting(FLATTR_TOKEN) and podcast.flattr_url) else: has_history = False subscribed_devices = [] subscribe_targets = [] can_flattr = False is_publisher = check_publisher_permission(user, podcast) episodes_total = podcast.episode_count or 0 num_pages = episodes_total / num_episodes page_list = get_page_list(1, num_pages, 1, 15) return render(request, 'podcast.html', { 'tags': tags, 'has_tagged': has_tagged, 'url': current_site, 'has_history': has_history, 'podcast': podcast, 'devices': subscribed_devices, 'related_podcasts': rel_podcasts, 'can_subscribe': len(subscribe_targets) > 0, 'subscribe_targets': subscribe_targets, 'episode': episode, 'episodes': episodes, 'max_listeners': max_listeners, 'can_flattr': can_flattr, 'is_publisher': is_publisher, 'page_list': page_list, 'current_page': 1, })
def show(request, podcast): """ Shows a podcast detail page """ podcast = check_restrictions(podcast) current_site = RequestSite(request) num_episodes = 20 episodes = episode_list(podcast, request.user, limit=num_episodes) user = request.user # TODO: move into EpisodeList (?) class listeners = [e.listeners for e in episodes if e.listeners is not None] max_listeners = max(listeners, default=0) episode = None if episodes: episode = episodes[0] episodes = episodes[1:] if podcast.group: group = podcast.group rel_podcasts = group.podcast_set.all() else: rel_podcasts = [] tags = get_tags(podcast, user) has_tagged = any(t['is_own'] for t in tags) if user.is_authenticated: subscribed_devices = Client.objects.filter( subscription__user=user, subscription__podcast=podcast) subscribe_targets = get_subscribe_targets(podcast, user) has_history = HistoryEntry.objects.filter(user=user, podcast=podcast).exists() else: has_history = False subscribed_devices = [] subscribe_targets = [] is_publisher = check_publisher_permission(user, podcast) episodes_total = podcast.episode_count or 0 num_pages = episodes_total / num_episodes page_list = get_page_list(1, num_pages, 1, 15) return render( request, 'podcast.html', { 'tags': tags, 'has_tagged': has_tagged, 'url': current_site, 'has_history': has_history, 'podcast': podcast, 'devices': subscribed_devices, 'related_podcasts': rel_podcasts, 'can_subscribe': len(subscribe_targets) > 0, 'subscribe_targets': subscribe_targets, 'episode': episode, 'episodes': episodes, 'max_listeners': max_listeners, 'is_publisher': is_publisher, 'page_list': page_list, 'current_page': 1, }, )
def page_list(cur, start, total, show_max): return get_page_list(start, total, cur, show_max)
def get_page_list(self, page, page_size, podcast_count): num_pages = int(ceil(podcast_count / page_size)) return get_page_list(1, num_pages, page, 15)
def page_list(cur, start, total, show_max): return get_page_list(start, total, cur, show_max)
def show(request, podcast): """ Shows a podcast detail page """ podcast = check_restrictions(podcast) current_site = RequestSite(request) num_episodes = 20 episodes = episode_list(podcast, request.user, limit=num_episodes) user = request.user max_listeners = max([e.listeners for e in episodes] + [0]) episode = None if episodes: episode = episodes[0] episodes = episodes[1:] if podcast.group: group = PodcastGroup.get(podcast.group) rel_podcasts = filter(lambda x: x != podcast, group.podcasts) else: rel_podcasts = [] tags, has_tagged = get_tags(podcast, user) if user.is_authenticated(): state = podcast_state_for_user_podcast(user, podcast) subscribed_devices = state.get_subscribed_device_ids() subscribed_devices = user.get_devices(subscribed_devices) subscribe_targets = podcast.subscribe_targets(user) has_history = bool(state.actions) is_public = state.settings.get('public_subscription', True) can_flattr = request.user.get_wksetting(FLATTR_TOKEN) and podcast.flattr_url else: has_history = False is_public = False subscribed_devices = [] subscribe_targets = [] can_flattr = False is_publisher = check_publisher_permission(user, podcast) episodes_total = podcast.episode_count or 0 num_pages = episodes_total / num_episodes page_list = get_page_list(1, num_pages, 1, 15) return render(request, 'podcast.html', { 'tags': tags, 'has_tagged': has_tagged, 'url': current_site, 'has_history': has_history, 'podcast': podcast, 'is_public': is_public, 'devices': subscribed_devices, 'related_podcasts': rel_podcasts, 'can_subscribe': len(subscribe_targets) > 0, 'subscribe_targets': subscribe_targets, 'episode': episode, 'episodes': episodes, 'max_listeners': max_listeners, 'can_flattr': can_flattr, 'is_publisher': is_publisher, 'page_list': page_list, 'current_page': 1, })