Example #1
0
def download_all(request):
    podcasts = get_subscribed_podcasts(request.user)
    response = simple.format_podcast_list(podcasts, "opml",
                                          request.user.username)
    response[
        "Content-Disposition"] = "attachment; filename=all-subscriptions.opml"
    return response
Example #2
0
def update_suggestions(user, max_suggestions=15):
    """ updates the suggestions of a user """
    logger.info('Updating suggestions of user {user.username}'.format(
        user=user))

    # calculate possible suggestions
    subscribed_podcasts = [sp.podcast for sp in get_subscribed_podcasts(user)]
    logger.debug('Found {num_podcasts} subscribed podcasts'.format(
        num_podcasts=len(subscribed_podcasts)))

    # TODO: update related_podcasts of the subscribed_podcasts?

    related = list(chain.from_iterable([p.related_podcasts.all() for p
                                        in subscribed_podcasts]))

    # get most relevant
    counter = Counter(related)
    logger.debug('Found {num_related} related podcasts'.format(
        num_related=len(counter)))

    suggested = [p for p, count in counter.most_common(max_suggestions)]

    for suggested_podcast in suggested:
        ps, created = PodcastSuggestion.objects.get_or_create(
            suggested_to=user,
            podcast=suggested_podcast,
        )
        if created:
            logger.info('Created suggestion for {podcast}'.format(
                podcast=suggested_podcast))

    user.profile.suggestions_up_to_date = True
    user.profile.save()
Example #3
0
def for_user(request, username):
    User = get_user_model()
    user = get_object_or_404(User, username=username)
    subscriptions = get_subscribed_podcasts(user, only_public=True)
    token = user.profile.get_token('subscriptions_token')

    return render(request, 'user_subscriptions.html', {
        'subscriptions': subscriptions,
        'other_user': user,
        'token': token,
        })
Example #4
0
def for_user(request, username):
    User = get_user_model()
    user = get_object_or_404(User, username=username)
    subscriptions = get_subscribed_podcasts(user, only_public=True)
    token = user.profile.get_token("subscriptions_token")

    return render(
        request,
        "user_subscriptions.html",
        {"subscriptions": subscriptions, "other_user": user, "token": token},
    )
Example #5
0
def for_user(request, username):
    User = get_user_model()
    user = get_object_or_404(User, username=username)
    subscriptions = get_subscribed_podcasts(user, only_public=True)
    token = user.profile.get_token('subscriptions_token')

    return render(request, 'user_subscriptions.html', {
        'subscriptions': subscriptions,
        'other_user': user,
        'token': token,
    })
Example #6
0
def for_user_opml(request, username):
    User = get_user_model()
    user = get_object_or_404(User, username=username)
    subscriptions = get_subscribed_podcasts(user, only_public=True)

    if parse_bool(request.GET.get('symbian', False)):
        subscriptions = map(symbian_opml_changes,
                            [p.podcast for p in subscriptions])

    response = render(request, 'user_subscriptions.opml', {
        'subscriptions': subscriptions,
        'other_user': user
        })
    response['Content-Disposition'] = 'attachment; filename=%s-subscriptions.opml' % username
    return response
Example #7
0
def for_user_opml(request, username):
    User = get_user_model()
    user = get_object_or_404(User, username=username)
    subscriptions = get_subscribed_podcasts(user, only_public=True)

    if parse_bool(request.GET.get('symbian', False)):
        subscriptions = map(symbian_opml_changes,
                            [p.podcast for p in subscriptions])

    response = render(request, 'user_subscriptions.opml', {
        'subscriptions': subscriptions,
        'other_user': user
    })
    response[
        'Content-Disposition'] = 'attachment; filename=%s-subscriptions.opml' % username
    return response
Example #8
0
def all_subscriptions(request, username, format):

    try:
        scale = int(request.GET.get('scale_logo', 64))
    except (TypeError, ValueError):
        return HttpResponseBadRequest('scale_logo has to be a numeric value')

    if scale not in range(1, 257):
        return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256')


    subscriptions = get_subscribed_podcasts(request.user)
    title = _('%(username)s\'s Subscription List') % {'username': username}
    domain = RequestSite(request).domain
    p_data = lambda p: podcast_data(p, domain, scale)
    return format_podcast_list(subscriptions, format, title,
            json_map=p_data, xml_template='podcasts.xml', request=request)
Example #9
0
def for_user_opml(request, username):
    User = get_user_model()
    user = get_object_or_404(User, username=username)
    subscriptions = get_subscribed_podcasts(user, only_public=True)

    if parse_bool(request.GET.get("symbian", False)):
        subscriptions = map(symbian_opml_changes, [p.podcast for p in subscriptions])

    response = render(
        request,
        "user_subscriptions.opml",
        {"subscriptions": subscriptions, "other_user": user},
    )
    response["Content-Disposition"] = (
        "attachment; filename=%s-subscriptions.opml" % username
    )
    return response
Example #10
0
def all_subscriptions(request, username, format):

    try:
        scale = int(request.GET.get('scale_logo', 64))
    except (TypeError, ValueError):
        return HttpResponseBadRequest('scale_logo has to be a numeric value')

    if scale not in range(1, 257):
        return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256')


    subscriptions = get_subscribed_podcasts(request.user)
    title = _('%(username)s\'s Subscription List') % {'username': username}
    domain = RequestSite(request).domain
    p_data = lambda p: podcast_data(p, domain, scale)
    return format_podcast_list(subscriptions, format, title,
            json_map=p_data, xml_template='podcasts.xml', request=request)
Example #11
0
def dashboard(request, episode_count=10):

    subscribed_podcasts = get_subscribed_podcasts(request.user)
    subscribed_podcasts = [sp.podcast for sp in subscribed_podcasts]

    site = RequestSite(request)

    checklist = []

    if request.user.client_set.count():
        checklist.append('devices')

    if subscribed_podcasts:
        checklist.append('subscriptions')

    if FavoriteEpisode.objects.filter(user=request.user).exists():
        checklist.append('favorites')

    if not request.user.profile.get_token('subscriptions_token'):
        checklist.append('share')

    if not request.user.profile.get_token('favorite_feeds_token'):
        checklist.append('share-favorites')

    if not request.user.profile.get_token('userpage_token'):
        checklist.append('userpage')

    if Tag.objects.filter(user=request.user).exists():
        checklist.append('tags')

    if PodcastList.objects.filter(user=request.user).exists():
        checklist.append('lists')

    if PublishedPodcast.objects.filter(publisher=request.user).exists():
        checklist.append('publish')

    if request.user.profile.settings.get_wksetting(FLATTR_TOKEN):
        checklist.append('flattr')

    if request.user.profile.settings.get_wksetting(FLATTR_AUTO):
        checklist.append('auto-flattr')

    tomorrow = datetime.today() + timedelta(days=1)

    newest_episodes = Episode.objects.filter(podcast__in=subscribed_podcasts,
                                             released__lt=tomorrow).\
                                      select_related('podcast').\
                                      prefetch_related('slugs',
                                                       'podcast__slugs').\
                                      order_by('-released')[:episode_count]


    # we only show the "install reader" link in firefox, because we don't know
    # yet how/if this works in other browsers.
    # hints appreciated at https://bugs.gpodder.org/show_bug.cgi?id=58
    show_install_reader = \
                'firefox' in request.META.get('HTTP_USER_AGENT', '').lower()

    random_podcast = Podcast.objects.all().random().prefetch_related('slugs').first()

    return render(request, 'dashboard.html', {
            'user': request.user,
            'subscribed_podcasts': subscribed_podcasts,
            'newest_episodes': list(newest_episodes),
            'random_podcast': random_podcast,
            'checklist': checklist,
            'site': site,
            'show_install_reader': show_install_reader,
        })
Example #12
0
 def get_subscriptions(self, user):
     subscriptions = [sp.podcast for sp in get_subscribed_podcasts(user)]
     return PodcastPercentageListenedSorter(subscriptions, user)
Example #13
0
def download_all(request):
    podcasts = get_subscribed_podcasts(request.user)
    response = simple.format_podcast_list(podcasts, 'opml', request.user.username)
    response['Content-Disposition'] = 'attachment; filename=all-subscriptions.opml'
    return response
Example #14
0
def dashboard(request, episode_count=10):

    subscribed_podcasts = get_subscribed_podcasts(request.user)
    subscribed_podcasts = [sp.podcast for sp in subscribed_podcasts]

    podcast_ad = Podcast.objects.get_advertised_podcast()

    site = RequestSite(request)

    checklist = []

    if request.user.client_set.count():
        checklist.append("devices")

    if subscribed_podcasts:
        checklist.append("subscriptions")

    if FavoriteEpisode.objects.filter(user=request.user).exists():
        checklist.append("favorites")

    if not request.user.profile.get_token("subscriptions_token"):
        checklist.append("share")

    if not request.user.profile.get_token("favorite_feeds_token"):
        checklist.append("share-favorites")

    if not request.user.profile.get_token("userpage_token"):
        checklist.append("userpage")

    if Tag.objects.filter(user=request.user).exists():
        checklist.append("tags")

    if PodcastList.objects.filter(user=request.user).exists():
        checklist.append("lists")

    if PublishedPodcast.objects.filter(publisher=request.user).exists():
        checklist.append("publish")

    tomorrow = datetime.today() + timedelta(days=1)

    #    newest_episodes = Episode.objects.filter(podcast__in=subscribed_podcasts,
    #                                             released__lt=tomorrow).\
    #                                      select_related('podcast').\
    #                                      prefetch_related('slugs',
    #                                                       'podcast__slugs').\
    #                                      order_by('-released')[:episode_count]
    #

    newest_episodes = []

    # we only show the "install reader" link in firefox, because we don't know
    # yet how/if this works in other browsers.
    # hints appreciated at https://bugs.gpodder.org/show_bug.cgi?id=58
    show_install_reader = "firefox" in request.META.get("HTTP_USER_AGENT",
                                                        "").lower()

    random_podcast = Podcast.objects.all().random().prefetch_related(
        "slugs").first()

    return render(
        request,
        "dashboard.html",
        {
            "user": request.user,
            "subscribed_podcasts": subscribed_podcasts,
            "newest_episodes": list(newest_episodes),
            "random_podcast": random_podcast,
            "checklist": checklist,
            "site": site,
            "show_install_reader": show_install_reader,
            "podcast_ad": podcast_ad,
        },
    )