コード例 #1
0
ファイル: views.py プロジェクト: Qbitus/pinecast
def podcast_top_episodes(req, podcast_slug):
    pod = get_podcast(req, podcast_slug)
    owner_uset = UserSettings.get_from_user(pod.owner)
    if not payment_plans.minimum(owner_uset.plan, payment_plans.FEATURE_MIN_COMMENT_BOX):
        return _pmrender(req, 'dashboard/podcast/page_top_episodes_upgrade.html', {'podcast': pod})

    with analytics_query.AsyncContext() as async_ctx:
        top_ep_data_query = analytics_query.get_top_episodes(unicode(pod.id), async_ctx)
    top_ep_data = top_ep_data_query()

    ep_ids = [x['episode'] for x in top_ep_data]
    episodes = PodcastEpisode.objects.filter(id__in=ep_ids)
    mapped = {unicode(ep.id): ep for ep in episodes}

    # This step is necessary to filter out deleted episodes
    top_ep_data = [x for x in top_ep_data if x['episode'] in mapped]

    # Sort the top episode data descending
    top_ep_data = reversed(sorted(top_ep_data, key=lambda x: x['podcast']))

    data = {
        'podcast': pod,
        'episodes': mapped,
        'top_ep_data': top_ep_data,
    }
    return _pmrender(req, 'dashboard/podcast/page_top_episodes.html', data)
コード例 #2
0
ファイル: views_network.py プロジェクト: Pinecast/pinecast
def network_dashboard(req, network_id):
    net = get_object_or_404(Network, deactivated=False, id=network_id, members__in=[req.user])

    net_podcasts = net.podcast_set.all()
    pod_map = {str(p.id): p for p in net_podcasts}

    top_episodes_data = analytics_query.get_top_episodes([str(p.id) for p in net_podcasts])

    top_episodes = []
    for ep_id, count in sorted(top_episodes_data.items(), key=lambda x: -1 * x[1])[:75]:
        try:
            episode = PodcastEpisode.objects.get(id=ep_id)
        except PodcastEpisode.DoesNotExist:
            continue
        top_episodes.append({
            'count': count,
            'episode': episode,
            'podcast': pod_map[str(episode.podcast_id)],
        })

    upcoming_episodes = PodcastEpisode.objects.filter(
        podcast__in=net_podcasts,
        publish__gt=round_now())

    return _pmrender(req,
                     'dashboard/network/page_dash.html',
                     {'error': req.GET.get('error'),
                      'network': net,
                      'net_podcasts': net_podcasts,
                      'net_podcasts_map': pod_map,
                      'top_episodes': top_episodes,
                      'upcoming_episodes': list(upcoming_episodes)})
コード例 #3
0
ファイル: views_network.py プロジェクト: vctrshn/pinecast
def network_dashboard(req, network_id):
    net = get_object_or_404(Network,
                            deactivated=False,
                            id=network_id,
                            members__in=[req.user])

    net_podcasts = net.podcast_set.all()
    pod_map = {str(p.id): p for p in net_podcasts}

    top_episodes_data = analytics_query.get_top_episodes(
        [str(p.id) for p in net_podcasts])

    top_episodes = []
    for ep_id, count in sorted(top_episodes_data.items(),
                               key=lambda x: -1 * x[1])[:75]:
        try:
            episode = PodcastEpisode.objects.get(id=ep_id)
        except PodcastEpisode.DoesNotExist:
            continue
        top_episodes.append({
            'count': count,
            'episode': episode,
            'podcast': pod_map[str(episode.podcast_id)],
        })

    upcoming_episodes = PodcastEpisode.objects.filter(podcast__in=net_podcasts,
                                                      publish__gt=round_now())

    return _pmrender(
        req, 'dashboard/network/page_dash.html', {
            'error': req.GET.get('error'),
            'network': net,
            'net_podcasts': net_podcasts,
            'net_podcasts_map': pod_map,
            'top_episodes': top_episodes,
            'upcoming_episodes': list(upcoming_episodes)
        })