Example #1
0
def list_favorites(request):
    site = RequestSite(request)

    episodes = backend.get_favorites(request.user)
    podcast_ids = [episode.podcast for episode in episodes]
    podcasts = get_to_dict(Podcast, podcast_ids, Podcast.get_id)

    def set_podcast(episode):
        episode = proxy_object(episode)
        episode.podcast = podcasts.get(episode.podcast, None)
        return episode

    episodes = map(set_podcast, episodes)

    feed_url = 'http://%s/%s' % (site.domain, reverse('favorites-feed', args=[request.user.username]))

    podcast = Podcast.for_url(feed_url)

    if 'public_feed' in request.GET:
        request.user.favorite_feeds_token = ''
        request.user.save()

    elif 'private_feed' in request.GET:
        request.user.create_new_token('favorite_feeds_token', 8)
        request.user.save()

    token = request.user.favorite_feeds_token

    return render(request, 'favorites.html', {
        'episodes': episodes,
        'feed_token': token,
        'site': site,
        'podcast': podcast,
        })
Example #2
0
File: sync.py Project: Mic92/mygpo
    def apply_sync_actions(self, device, sync_actions):
        """ Applies the sync-actions to the device """

        add, rem = sync_actions

        podcasts = get_to_dict(Podcast, add + rem, get_id=Podcast.get_id)

        for podcast_id in add:
            podcast = podcasts.get(podcast_id, None)
            if podcast is None:
                continue
            try:
                podcast.subscribe(self, device)
            except SubscriptionException as e:
                log('Web: %(username)s: cannot sync device: %(error)s' %
                    dict(username=self.username, error=repr(e)))

        for podcast_id in rem:
            podcast = podcasts.get(podcast_id, None)
            if not podcast:
                continue

            try:
                podcast.unsubscribe(self, device)
            except SubscriptionException as e:
                log('Web: %(username)s: cannot sync device: %(error)s' %
                    dict(username=self.username, error=repr(e)))
Example #3
0
    def fetch_data(cls, user, entries,
            podcasts=None, episodes=None):
        """ Efficiently loads additional data for a number of entries """

        if podcasts is None:
            # load podcast data
            podcast_ids = [getattr(x, 'podcast_id', None) for x in entries]
            podcast_ids = filter(None, podcast_ids)
            podcasts = get_to_dict(Podcast, podcast_ids, get_id=Podcast.get_id)

        if episodes is None:
            # load episode data
            episode_ids = [getattr(x, 'episode_id', None) for x in entries]
            episode_ids = filter(None, episode_ids)
            episodes = get_to_dict(Episode, episode_ids)

        # load device data
        # does not need pre-populated data because no db-access is required
        device_ids = [getattr(x, 'device_id', None) for x in entries]
        device_ids = filter(None, device_ids)
        devices = dict([ (id, user.get_device(id)) for id in device_ids])


        for entry in entries:
            podcast_id = getattr(entry, 'podcast_id', None)
            entry.podcast = podcasts.get(podcast_id, None)

            episode_id = getattr(entry, 'episode_id', None)
            entry.episode = episodes.get(episode_id, None)
            entry.user = user

            device = devices.get(getattr(entry, 'device_id', None), None)
            entry.device = device


        return entries
Example #4
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()
Example #5
0
def privacy(request):

    site = RequestSite(request)

    @repeat_on_conflict(['state'])
    def set_privacy_settings(state, is_public):
        state.settings['public_subscription'] = is_public
        state.save()

    if 'private_subscriptions' in request.GET:
        set_privacy_settings(state=request.user, is_public=False)

    elif 'public_subscriptions' in request.GET:
        set_privacy_settings(state=request.user, is_public=True)

    if 'exclude' in request.GET:
        id = request.GET['exclude']
        podcast = Podcast.get(id)
        state = podcast.get_user_state(request.user)
        set_privacy_settings(state=state, is_public=False)

    if 'include' in request.GET:
        id = request.GET['include']
        podcast = Podcast.get(id)
        state = podcast.get_user_state(request.user)
        set_privacy_settings(state=state, is_public=True)

    subscriptions = request.user.get_subscriptions()
    podcasts = get_to_dict(Podcast, [x[1] for x in subscriptions], get_id=Podcast.get_id)

    included_subscriptions = set(filter(None, [podcasts.get(x[1], None) for x in subscriptions if x[0] == True]))
    excluded_subscriptions = set(filter(None, [podcasts.get(x[1], None) for x in subscriptions if x[0] == False]))

    return render(request, 'privacy.html', {
        'public_subscriptions': request.user.settings.get('public_subscriptions', True),
        'included_subscriptions': included_subscriptions,
        'excluded_subscriptions': excluded_subscriptions,
        'domain': site.domain,
        })
Example #6
0
File: views.py Project: Mic92/mygpo
    try:
        lang = utils.process_lang_params(request)
    except utils.UpdatedException, updated:
        return HttpResponseRedirect("/toplist/episodes?lang=%s" % ",".join(updated.data))

    type_str = request.GET.get("types", "")
    set_types = filter(None, type_str.split(","))

    media_types = set_types or CONTENT_TYPES

    toplist = EpisodeToplist(languages=lang, types=media_types)
    entries = list(map(proxy_object, toplist[:num]))

    # load podcast objects
    podcast_ids = [e.podcast for e in entries]
    podcasts = get_to_dict(Podcast, podcast_ids, Podcast.get_id, True)
    for entry in entries:
        entry.podcast = podcasts.get(entry.podcast, None)

    current_site = RequestSite(request)

    # Determine maximum listener amount (or 0 if no entries exist)
    max_listeners = max([0] + [e.listeners for e in entries])

    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,
        "episode_toplist.html",
        {