Ejemplo n.º 1
0
def create_reserve(request, slug=None):
    post = get_object_or_404(EventModel, slug=slug)
    comm_parent = Comment.objects.filter(is_parent=True).filter(post=post)
    errors = []
    user = request.user
    form = ReserveForm(request.POST or None)
    if request.method == "POST":
        if form.is_valid():
            p_tickets = int(post.nrlocuri)
            r_tickets = int(form.cleaned_data['nrlocuri'])
            if r_tickets <= p_tickets:
                reserve = form.instance
                reserve.user = user
                reserve.post = post
                form.save()
                EventModel.objects.filter(slug=slug).update(
                    nrlocuri=str(p_tickets - r_tickets))
                return redirect('/')
            else:
                errors.append("1")
        else:
            errors.append("2")
    return render(
        request, "posts/Offer-page.html", {
            'form': form,
            'events': post,
            'comm_parent': comm_parent,
            'user': request.user
        })
Ejemplo n.º 2
0
def reserve_book(request, id_book):
    authenticated = False
    reserved = False
    if request.user.is_authenticated():
        authenticated = True
    book = Book.objects.get(id_book=id_book)
    form = ReserveForm(request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            reserved_book = form.save(commit=False)
            reserved_book.book = book
            reserved_book.user = request.user
            reserved_book.save()
            reserved = True
            email_user(user=request.user,
                       subject='reserve book',
                       message='You have successfully reserved' +
                       reserved_book.book.title + '!')

    return render_to_response("book_reserve.html",
                              context_instance=RequestContext(
                                  request, {
                                      'authenticated': authenticated,
                                      'book': book,
                                      'form': form,
                                      'reserved': reserved
                                  }))
Ejemplo n.º 3
0
def reserve_book(request, id_book):
    authenticated = False
    reserved = False
    if request.user.is_authenticated():
        authenticated = True
    book = Book.objects.get(id_book=id_book)
    form = ReserveForm(request.POST or None)

    if request.method == 'POST':
        if form.is_valid():
            reserved_book = form.save(commit=False)
            reserved_book.book = book
            reserved_book.user = request.user
            reserved_book.save()
            reserved = True
            email_user(user=request.user,
                       subject='reserve book',
                       message='You have successfully reserved' + reserved_book.book.title + '!')

    return render_to_response("book_reserve.html", context_instance=RequestContext(request,
                                                                                   {'authenticated': authenticated,
                                                                                    'book': book, 'form': form,
                                                                                    'reserved': reserved}))