예제 #1
0
파일: __init__.py 프로젝트: Mic92/mygpo
def welcome(request):
    current_site = RequestSite(request)

    podcasts = get_cache_or_calc('podcast-count', timeout=60*60,
                    calc=lambda: Podcast.count())
    users    = get_cache_or_calc('user-count', timeout=60*60,
                    calc=lambda: User.count())
    episodes = get_cache_or_calc('episode-count', timeout=60*60,
                    calc=lambda: Episode.count())

    lang = utils.process_lang_params(request)

    toplist = PodcastToplist(lang)

    return render(request, 'home.html', {
          'podcast_count': podcasts,
          'user_count': users,
          'episode_count': episodes,
          'url': current_site,
          'toplist': toplist,
    })
예제 #2
0
def create_subscriptionlist(request):

    user = request.user
    user.sync_all()

    subscriptions = user.get_subscriptions()

    if not subscriptions:
        return []

    # Load all Podcasts and Devices first to ensure that they are
    # only loaded once, not for each occurance in a subscription
    public, podcast_ids, device_ids = unzip(subscriptions)
    podcast_ids= list(set(podcast_ids))
    device_ids = list(set(device_ids))

    podcasts = get_to_dict(Podcast, podcast_ids, get_id=Podcast.get_id)
    devices = dict([ (id, user.get_device(id)) for id in device_ids])

    subscription_list = {}
    for public, podcast_id, device_id in subscriptions:
        device = devices[device_id]
        if not podcast_id in subscription_list:
            podcast = podcasts.get(podcast_id, None)
            if podcast is None:
                continue

            episode = get_cache_or_calc('%s-latest-episode' % podcast.get_id(),
                    timeout=60*60, calc=lambda: podcast.get_latest_episode())

            subscription_list[podcast_id] = {
                'podcast': podcasts[podcast_id],
                'devices': [device] if device else [],
                'episode': episode
            }
        else:
            if device:
                subscription_list[podcast_id]['devices'].append(device)

    return subscription_list.values()
예제 #3
0
파일: views.py 프로젝트: Mic92/mygpo
    try:
        lang = utils.process_lang_params(request)
    except utils.UpdatedException, updated:
        return HttpResponseRedirect("/toplist/?lang=%s" % ",".join(updated.data))

    type_str = request.GET.get("types", "")
    set_types = [t for t in type_str.split(",") if t]
    media_types = set_types or CONTENT_TYPES

    toplist = PodcastToplist(lang, media_types)
    entries = toplist[:num]

    max_subscribers = max([p.subscriber_count() for (oldp, p) in entries]) if entries else 0
    current_site = RequestSite(request)

    languages = get_cache_or_calc("podcast-languages", timeout=60 * 60, calc=lambda: utils.get_podcast_languages())
    all_langs = utils.get_language_names(languages)

    return render(
        request,
        "toplist.html",
        {
            "entries": entries,
            "max_subscribers": max_subscribers,
            "url": current_site,
            "languages": lang,
            "all_languages": all_langs,
            "types": media_types,
        },
    )