Exemple #1
0
def create_list(request):
    title = request.POST.get('title', None)

    if not title:
        messages.error(request, _('You have to specify a title.'))
        return HttpResponseRedirect(reverse('lists-overview'))

    slug = slugify(title)

    if not slug:
        messages.error(request, _('"{title}" is not a valid title').format(
                    title=title))
        return HttpResponseRedirect(reverse('lists-overview'))

    plist = podcastlist_for_user_slug(request.user._id, slug)

    if plist is None:
        plist = PodcastList()
        plist.created_timestamp = get_timestamp(datetime.utcnow())
        plist.title = title
        plist.slug = slug
        plist.user = request.user._id
        plist.save()

    list_url = reverse('list-show', args=[request.user.username, slug])
    return HttpResponseRedirect(list_url)
Exemple #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
Exemple #3
0
def create_list(request):
    title = request.POST.get("title", None)

    if not title:
        messages.error(request, _("You have to specify a title."))
        return HttpResponseRedirect(reverse("lists-overview"))

    slug = slugify(title)

    if not slug:
        messages.error(request, _('"{title}" is not a valid title').format(title=title))
        return HttpResponseRedirect(reverse("lists-overview"))

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

    if plist is None:
        plist = PodcastList()
        plist.title = title
        plist.slug = slug
        plist.user = request.user._id
        plist.save()

    list_url = reverse("list-show", args=[request.user.username, slug])
    return HttpResponseRedirect(list_url)