Ejemplo n.º 1
0
def dashboard(request, episode_count=10):

    site = RequestSite(request)

    user = request.user
    subscribed_podcasts = user.get_subscribed_podcasts()
    devices = user.active_devices

    tomorrow = datetime.today() + timedelta(days=1)
    newest_episodes = user.get_newest_episodes(tomorrow)
    newest_episodes = islice(newest_episodes, 0, episode_count)

    lang = utils.get_accepted_lang(request)
    lang = utils.sanitize_language_codes(lang)

    # for performance reasons, we only consider the first three languages
    lang = lang[:3]
    random_podcasts = islice(backend.get_random_picks(lang), 0, 5)

    return render(request, 'dashboard.html', {
            'site': site,
            'devices': devices,
            'subscribed_podcasts': subscribed_podcasts,
            'newest_episodes': newest_episodes,
            'random_podcasts': random_podcasts,
        })
Ejemplo n.º 2
0
    def all_languages(self):
        """ Returns all 2-letter language codes that are used by podcasts.

        It filters obviously invalid strings, but does not check if any
        of these codes is contained in ISO 639. """

        query = Podcast.objects.exclude(language__isnull=True)
        query = query.distinct('language').values('language')

        langs = [o['language'] for o in query]
        langs = sorted(sanitize_language_codes(langs))

        return get_language_names(langs)
Ejemplo n.º 3
0
    def all_languages(self):
        """ Returns all 2-letter language codes that are used by podcasts.

        It filters obviously invalid strings, but does not check if any
        of these codes is contained in ISO 639. """

        query = Podcast.objects.exclude(language__isnull=True)
        query = query.distinct('language').values('language')

        langs = [o['language'] for o in query]
        langs = sorted(sanitize_language_codes(langs))

        return get_language_names(langs)
Ejemplo n.º 4
0
def get_podcast_languages():
    """ Returns all 2-letter language codes that are used by podcasts.

    It filters obviously invalid strings, but does not check if any
    of these codes is contained in ISO 639. """

    from mygpo.web.utils import sanitize_language_codes

    res = Podcast.view('podcasts/by_language',
            group_level = 1,
            stale       = 'ok',
        )

    langs = [r['key'][0] for r in res]
    sane_lang = sanitize_language_codes(langs)
    sane_lang.sort()
    return sane_lang