예제 #1
0
파일: views.py 프로젝트: weshayutin/mysite
def manage_authors_form(request):
    if request.method == 'POST': # If the form has been submitted...
        form = AuthorForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            form.save()
            return HttpResponseRedirect('/thanks/') # Redirect after POST
    else:
        form = AuthorForm() # An unbound form

    return render(request, 'book/manage_books_form.html', {
        'form': form,
    })
예제 #2
0
def add_publisher(request):
    if request.method == 'POST':
        form = AuthorForm(request.POST)
        if form.is_valid():
            form.save()
            sender = form.cleaned_data['first_name']
            #print(sen)
            return redirect('ul_name', tst=sender)
            #return HttpResponseRedirect(reverse('thanks_author', kwargs={'tst': location}))
    else:
        form = AuthorForm()
    return render_to_response('books/add_publisher.html', {'form': form},
                              context_instance=RequestContext(request))
예제 #3
0
def author_edit(request,author_id):
    if author_id is None:
        selected_author = None
        create_message = 'Author success create!'
    else:
        selected_author = get_object_or_404(Author, pk=author_id)
        create_message = 'Author success edit!'

    if request.method == 'POST':
        form = AuthorForm(request.POST, instance=selected_author)
        if form.is_valid():
            instance_form = form.save()
            messages.success(request,create_message)
            if author_id is None:
                return redirect(reverse('author_view', args=[instance_form.id]))
    else:
        form = AuthorForm(instance=selected_author)
    return render_to_response('books/author_edit.html',{'form':form,'author_id':author_id}, context_instance=RequestContext(request))