Example #1
0
    def get_subscriptions_by_device(self, public=None):
        from mygpo.db.couchdb.podcast_state import subscriptions_by_user
        get_dev = itemgetter(2)
        groups = collections.defaultdict(list)
        subscriptions = subscriptions_by_user(self, public=public)
        subscriptions = sorted(subscriptions, key=get_dev)

        for public, podcast_id, device_id in subscriptions:
            groups[device_id].append(podcast_id)

        return groups
Example #2
0
def privacy(request):
    site = RequestSite(request)

    subscriptions = subscriptions_by_user(request.user)
    podcasts = podcasts_to_dict([x[1] for x in subscriptions])

    subs = set((podcasts.get(x[1], None), not x[0]) for x in subscriptions)
    subs = sorted(subs, key=lambda (p, _): PODCAST_SORT(p))

    return render(request, 'privacy.html', {
        'private_subscriptions': not request.user.get_wksetting(PUBLIC_SUB_USER),
        'subscriptions': subs,
        'domain': site.domain,
        })
Example #3
0
def create_subscriptionlist(request):
    user = request.user
    subscriptions = subscriptions_by_user(user)

    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 = podcasts_to_dict(podcast_ids)
    devices = user.get_devices_by_id(device_ids)

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

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

    subscriptions = subscription_list.values()
    sort_key = lambda s: s['podcast'].latest_episode_timestamp or datetime.utcnow()
    subscriptions = sorted(subscriptions, key=sort_key, reverse=True)
    return subscriptions