예제 #1
0
파일: views.py 프로젝트: piIorama/des
def addbook(request,id=1):
	if request.POST:
		form = BookForm(request.POST)
		if form.is_valid():
			book=form.save(commit=False)
			form.save()
	return redirect('/books/all',)
예제 #2
0
파일: views.py 프로젝트: shustrik113/myweb
def create_book(request):
    if request.POST:
        form = BookForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/books/')
    else:
        form = BookForm()

    args = {}
    args.update(csrf(request))
    args['form'] = form

    # right box
    args['menu'] = Menu.objects.all()
    args['pop_books'] = Book.objects.all().order_by('likes').reverse()[:10]
    args['new_books'] = Book.objects.all().order_by('date').reverse()[:10]
    args['cats'] = Category.objects.all()
    args['tags'] = Tag.objects.all()
    args['current_item'] = 'книги'

    # user
    args['username'] = auth.get_user(request).username

    # poll
    args['question_web'] = Question.objects.get(text=u"Как вам наш сайт?")
    args['choices'] = Choice.objects.filter(question_id=args['question_web'].id)
    return render_to_response('book/create_book.html', args)
예제 #3
0
def add(request):
    """View to add a book, we will check if the seller is active first"""
    try:
        seller = Seller.objects.get(user=request.user.id)
    except Seller.DoesNotExist:
        seller = None
    if seller and seller.account_status == 'AC':
        can_add_book = True
        seller_id = seller.id
    else:
        can_add_book = False
        seller_id = None

    if request.method == 'POST':  # If the form has been submitted...
        form = BookForm(request.POST,
                        request.FILES)  # 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 redirect('/accounts/books/')  # Redirect after POST
    else:
        form = BookForm(initial={'seller': seller_id})  # An unbound form

    return render_to_response('books/book_form.html', {
        'form': form,
        'can_add_book': can_add_book,
        'seller': seller
    },
                              context_instance=RequestContext(request))
예제 #4
0
파일: views.py 프로젝트: piIorama/des
def addbook(request, id=1):
    if request.POST:
        form = BookForm(request.POST)
        if form.is_valid():
            book = form.save(commit=False)
            form.save()
    return redirect('/books/all', )
예제 #5
0
파일: views.py 프로젝트: rasiel/mibooklist
def add(request):
    """View to add a book, we will check if the seller is active first"""
    try:
        seller = Seller.objects.get(user=request.user.id)
    except Seller.DoesNotExist:
        seller = None
    if seller and seller.account_status == 'AC':
        can_add_book = True
        seller_id = seller.id
    else:
        can_add_book = False
        seller_id = None
        
    if request.method == 'POST': # If the form has been submitted...
        form = BookForm(request.POST, request.FILES) # 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 redirect('/accounts/books/') # Redirect after POST
    else:
        form = BookForm(initial={'seller': seller_id}) # An unbound form

    return render_to_response('books/book_form.html', {
        'form': form,
        'can_add_book': can_add_book,
        'seller': seller
    },context_instance=RequestContext(request))
예제 #6
0
def add_book(request):
    if request.method == 'POST':
        form = BookForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/books/all/')
    else:
        form = BookForm()

    args = {}
    args.update(csrf(request))
    args['form'] = form
    return render(request, 'books/add_book.html', args)
예제 #7
0
def create(request):
	if request.method == 'POST':
		form = BookForm(request.POST, request.FILES)
		if form.is_valid:
			form.save()
			messages.add_message(request, messages.SUCCESS, 'Your book was added!')
			return HttpResponseRedirect('/')
	else:
		form = BookForm()
	args = {}
	#args.update(csrf(request))
	args['form'] = form
	return render(request, 'create_book.html', args)
예제 #8
0
def book_view(request):
    if request.method == 'GET':
        form = BookForm()
    else:
        form = BookForm(request.POST)
    
    """
    WARING: this line will technically work, but is horribly sub-optimal.
    djangoperformance.com will make you aware of that sub-optimality by telling
    you how many queries are being generated for each view, and what those queries are
    """
#    books = Book.objects.all()
    
    """
    this is a simple solution to reduce the number of queries issued to the database.
    this should not be considered a recipe for optimizing all applications, and is only
    used here to illustrate expected use case of djangoperformance.com
    (you may, for example, want to use a custom model manager if you're doing something complicated
    in your application)
    """
    books = Book.objects.select_related('publisher').all().prefetch_related('authors')
    
    if not form.is_valid() or request.method == 'GET':
        return render_to_response('books.html',
                                  {'form': form,
                                   'object_list': books},
                                  context_instance=RequestContext(request))
    else:
        newitem = form.save()
        messages.success(request, "Book %s was added" % newitem)
        return HttpResponseRedirect(request.build_absolute_uri())
예제 #9
0
파일: views.py 프로젝트: ailling/gatestapp
def book_view(request):
    if request.method == "GET":
        form = BookForm()
    else:
        form = BookForm(request.POST)

    """
    WARING: this line will technically work, but is horribly sub-optimal.
    djangoperformance.com will make you aware of that sub-optimality by telling
    you how many queries are being generated for each view, and what those queries are
    """
    #    books = Book.objects.all()

    """
    this is a simple solution to reduce the number of queries issued to the database.
    this should not be considered a recipe for optimizing all applications, and is only
    used here to illustrate expected use case of djangoperformance.com
    (you may, for example, want to use a custom model manager if you're doing something complicated
    in your application)
    """
    books = Book.objects.select_related("publisher").all().prefetch_related("authors")

    if not form.is_valid() or request.method == "GET":
        return render_to_response(
            "books.html", {"form": form, "object_list": books}, context_instance=RequestContext(request)
        )
    else:
        newitem = form.save()
        messages.success(request, "Book %s was added" % newitem)
        return HttpResponseRedirect(request.build_absolute_uri())
예제 #10
0
파일: views.py 프로젝트: rasiel/mibooklist
def edit(request, id):
    """Edit a book, using the passed id"""
    book = Book.objects.get(pk=id)
    if request.method == 'POST': # If the form has been submitted...
        form = BookForm(request.POST, request.FILES, instance=book) # 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 redirect('/accounts/books/') # Redirect after POST
    else:
        form = BookForm(instance=book) # Lets bound the form

    return render_to_response('books/book_form.html', {
        'form': form,
        'can_add_book': True
    },context_instance=RequestContext(request))
예제 #11
0
def edit(request, id):
    """Edit a book, using the passed id"""
    book = Book.objects.get(pk=id)
    if request.method == 'POST':  # If the form has been submitted...
        form = BookForm(request.POST, request.FILES,
                        instance=book)  # 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 redirect('/accounts/books/')  # Redirect after POST
    else:
        form = BookForm(instance=book)  # Lets bound the form

    return render_to_response('books/book_form.html', {
        'form': form,
        'can_add_book': True
    },
                              context_instance=RequestContext(request))
예제 #12
0
파일: views.py 프로젝트: crainbf/camucamu
def addbook(request):
    #form_args = {}
    if request.POST:
        book_form = BookForm(request.POST)
        if book_form.is_valid():
            book = book_form.save(commit=False)
            book.user = request.user
            book.save()
            book_form.save_m2m()
            return HttpResponseRedirect("/stats/")
    else:
        book_form = BookForm(initial={'user': request.user})
    return render_to_response('add_book.html', {'BookForm': book_form}, context_instance=RequestContext(request))
예제 #13
0
def edit(request, book_id):
	b = Book.objects.get(id=book_id)
	if request.method == 'POST':
		form = BookForm(request.POST, request.FILES)
		if form.is_valid:
			c = form.save(commit=False)
			c.book = b
			c.save()
			messages.add_message(request, messages.SUCCESS, 'Your book was edited!')
			return HttpResponseRedirect('/books/get/%s' % book_id)
	else:
		form = BookForm()
	args = {}
	args['form'] = form
	return render(request, 'create_book.html', args)
예제 #14
0
def addbook(request):
    args = {}
    args.update(csrf(request))
    args['form'] = BookForm()
    args['username'] = auth.get_user(request).username
    if request.POST:
        form = BookForm(request.POST, request.FILES)
        if form.is_valid():
            book = form.save(commit=False)
            book.book_from = request.user
            book.book_date = timezone.now()
            book.save()
            return redirect('/books/get/%s/' % book.id)
    else:
        form = BookForm()
    return render_to_response('AddBook.html', args)
예제 #15
0
def addbook(request):
	args={}
	args.update(csrf(request))
	args['form']=BookForm()
	args['username'] = auth.get_user(request).username
	if request.POST:
		form=BookForm(request.POST, request.FILES)
		if form.is_valid():
			book = form.save(commit=False)
			book.book_from = request.user
			book.book_date = timezone.now()
			book.save()
			return redirect('/books/get/%s/' %book.id)
	else:
		form=BookForm()
	return render_to_response('AddBook.html', args)