示例#1
0
def create_booklet(request):
    if request.method == 'POST':
        song_list = request.POST.getlist("songs[]")
        front_page_text = request.POST.get("front_page_text")
        front_page_image = request.POST.get("front_page_image_url")
        songs = Song.objects.filter(id__in=song_list)
        user = request.user
        title = request.POST["title"]
        book = bookletpy.update_or_create_booklet(songs, user, title, song_list, front_page_text, front_page_image)
        bookletpy.convert_booklet_to_pdf(book)
        return HttpResponse(reverse('booklet', kwargs={"id":book.id}))
    return render(request, "booklets/create_booklet.html")
示例#2
0
def update_booklet(request, id):
    if request.method == 'POST':
        original = get_object_or_404(Booklet, pk=id)
        try:
            song_list = request.POST.getlist("songs[]")
            songs = Song.objects.filter(id__in=song_list)
            front_page_text = request.POST.get("front_page_text")
            front_page_image = request.POST.get("front_page_image_url")
            title = request.POST["title"]
            user = request.user
        except Exception, e:
            return HttpResponseBadRequest("Recieved JSON didn't contain all required information")
        try:
            new_booklet = bookletpy.update_or_create_booklet(songs, user, title, song_list, front_page_text, front_page_image, original)
            return HttpResponse(reverse('booklet', kwargs={"id": new_booklet.id}))
        except Exception, e:
            return HttpResponseBadRequest("Updating booklet failed")