Beispiel #1
0
def update_list(request, plist, owner, format):
    """ Replaces the podcasts in the list and returns 204 No Content """
    urls = parse_subscription(request.body.decode('utf-8'), format)
    podcasts = [Podcast.objects.get_or_create_for_url(url) for url in urls]
    plist.set_entries(podcasts)

    return HttpResponse(status=204)
Beispiel #2
0
def create(request, username, format):
    """ Creates a new podcast list and links to it in the Location header """

    title = request.GET.get('title', None)

    if not title:
        return HttpResponseBadRequest('Title missing')

    slug = slugify(title)

    if not slug:
        return HttpResponseBadRequest('Invalid title')

    plist = PodcastList.for_user_slug(request.user._id, slug)

    if plist:
        return HttpResponse('List already exists', status=409)

    urls = parse_subscription(request.raw_post_data, format)
    podcasts = [Podcast.for_url(url, create=True) for url in urls]
    podcast_ids = map(Podcast.get_id, podcasts)

    plist = PodcastList()
    plist.title = title
    plist.slug = slug
    plist.user = request.user._id
    plist.podcasts = podcast_ids
    plist.save()

    response = HttpResponse(status=201)
    list_url = reverse('api-get-list', args=[request.user.username, slug, format])
    response['Location'] = list_url

    return response
Beispiel #3
0
def update_list(request, plist, owner, format):
    """ Replaces the podcasts in the list and returns 204 No Content """
    urls = parse_subscription(request.body.decode('utf-8'), format)
    podcasts = [Podcast.objects.get_or_create_for_url(url).object for url in urls]
    plist.set_entries(podcasts)

    return HttpResponse(status=204)
Beispiel #4
0
def upload_opml(request, device):

    if not 'opml' in request.FILES:
        return HttpResponseRedirect(reverse('device-edit', args=[device.uid]))

    opml = request.FILES['opml'].read()
    subscriptions = simple.parse_subscription(opml, 'opml')
    simple.set_subscriptions(subscriptions, request.user, device.uid, None)
    return HttpResponseRedirect(reverse('device', args=[device.uid]))
Beispiel #5
0
def upload_opml(request, device):

    if not 'opml' in request.FILES:
        return HttpResponseRedirect(reverse('device-edit', args=[device.uid]))

    try:
        opml = request.FILES['opml'].read().decode('utf-8')
        subscriptions = simple.parse_subscription(opml, 'opml')
        simple.set_subscriptions(subscriptions, request.user, device.uid, None)

    except (ValueError, ExpatError, UnicodeDecodeError) as ex:
        msg = _('Could not upload subscriptions: {err}').format(err=str(ex))
        messages.error(request, msg)
        return HttpResponseRedirect(reverse('device-edit', args=[device.uid]))

    return HttpResponseRedirect(reverse('device', args=[device.uid]))
Beispiel #6
0
def create(request, username, format):
    """ Creates a new podcast list and links to it in the Location header """

    title = request.GET.get('title', None)

    if not title:
        return HttpResponseBadRequest('Title missing')

    slug = slugify(title)

    if not slug:
        return HttpResponseBadRequest('Invalid title')

    plist, created = PodcastList.objects.get_or_create(user=request.user,
                                                       slug=slug,
                                                       defaults={
                                                           'id':
                                                           uuid.uuid1(),
                                                           'title':
                                                           title,
                                                           'slug':
                                                           slug,
                                                           'created':
                                                           datetime.utcnow(),
                                                           'modified':
                                                           datetime.utcnow(),
                                                       })

    if not created:
        return HttpResponse('List already exists', status=409)

    urls = parse_subscription(request.body.decode('utf-8'), format)
    podcasts = [
        Podcast.objects.get_or_create_for_url(url).object for url in urls
    ]

    for podcast in podcasts:
        plist.add_entry(podcast)

    response = HttpResponse(status=201)
    list_url = reverse('api-get-list',
                       args=[request.user.username, slug, format])
    response['Location'] = list_url

    return response
Beispiel #7
0
def create(request, username, format):
    """ Creates a new podcast list and links to it in the Location header """

    title = request.GET.get("title", None)

    if not title:
        return HttpResponseBadRequest("Title missing")

    slug = slugify(title)

    if not slug:
        return HttpResponseBadRequest("Invalid title")

    plist, created = PodcastList.objects.get_or_create(
        user=request.user,
        slug=slug,
        defaults={
            "id": uuid.uuid1(),
            "title": title,
            "slug": slug,
            "created": datetime.utcnow(),
            "modified": datetime.utcnow(),
        },
    )

    if not created:
        return HttpResponse("List already exists", status=409)

    urls = parse_subscription(request.body.decode("utf-8"), format)
    podcasts = [
        Podcast.objects.get_or_create_for_url(url).object for url in urls
    ]

    for podcast in podcasts:
        plist.add_entry(podcast)

    response = HttpResponse(status=201)
    list_url = reverse("api-get-list",
                       args=[request.user.username, slug, format])
    response["Location"] = list_url

    return response
Beispiel #8
0
def update_list(request, plist, owner, format):
    """ Replaces the podcasts in the list and returns 204 No Content """

    is_own = owner == request.uuser

    if not is_own:
        return HttpResponseForbidden()

    urls = parse_subscription(request.raw_post_data, format)
    podcasts = [Podcast.for_url(url, create=True) for url in urls]
    podcast_ids = map(Podcast.get_id, podcasts)

    @repeat_on_conflict(['podcast_ids'])
    def _update(plist, podcast_ids):
        plist.podcasts = podcast_ids
        plist.save()

    _update(plist=plist, podcast_ids=podcast_ids)

    return HttpResponse(status=204)
Beispiel #9
0
def create(request, username, format):
    """ Creates a new podcast list and links to it in the Location header """

    title = request.GET.get('title', None)

    if not title:
        return HttpResponseBadRequest('Title missing')

    slug = slugify(title)

    if not slug:
        return HttpResponseBadRequest('Invalid title')

    plist, created = PodcastList.objects.get_or_create(
        user=request.user,
        slug=slug,
        defaults={
            'id': uuid.uuid1(),
            'title': title,
            'slug': slug,
            'created': datetime.utcnow(),
            'modified': datetime.utcnow(),
        },
    )

    if not created:
        return HttpResponse('List already exists', status=409)

    urls = parse_subscription(request.body.decode('utf-8'), format)
    podcasts = [Podcast.objects.get_or_create_for_url(url).object for url in urls]

    for podcast in podcasts:
        plist.add_entry(podcast)

    response = HttpResponse(status=201)
    list_url = reverse('api-get-list', args=[request.user.username, slug, format])
    response['Location'] = list_url

    return response