Exemplo n.º 1
0
def book_update_view(request, pk):
    book = get_object_or_404(Book, id=pk)

    if request.method == 'GET':

        form = BookForm(
            initial={
                'name': book.name,
                'email': book.email,
                'description': book.description,
            })
        return render(request,
                      'book_update.html',
                      context={
                          'form': form,
                          'book': book
                      })
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            book.name = form.cleaned_data.get("name")
            book.email = form.cleaned_data.get("email")
            book.description = form.cleaned_data.get("description")
            book.save()
            return redirect('book_list')
        return render(request,
                      'book_update.html',
                      context={
                          'form': form,
                          'book': book
                      })
Exemplo n.º 2
0
def book_update_view(request, pk):
    book = get_object_or_404(Book, pk=pk)
    if request.method == 'GET':
        form = BookForm(data={
            'author': book.author,
            'email': book.email,
            'text': book.text
        })
        return render(request,
                      'update.html',
                      context={
                          'form': form,
                          'book': book
                      })
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            book.author = form.cleaned_data['author']
            book.email = form.cleaned_data['email']
            book.text = form.cleaned_data['text']
            book.save()
            return redirect('book_update', pk=book.pk)
        else:
            return render(request,
                          'update.html',
                          context={
                              'form': form,
                              'book': book
                          })
def guest_update_view(request, pk):
    guest = get_object_or_404(G_book, pk=pk)
    if request.method == 'GET':
        form = BookForm(data={
            'name': guest.name,
            'email': guest.email,
            'text': guest.text,
        })
        return render(request,
                      'update.html',
                      context={
                          'form': form,
                          'guest': guest
                      })
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            guest.name = form.cleaned_data['name']
            guest.email = form.cleaned_data['email']
            guest.text = form.cleaned_data['text']
            guest.save()
            return redirect('index')
        else:
            return render(request,
                          'update.html',
                          context={
                              'form': form,
                              'guest': guest
                          })
Exemplo n.º 4
0
def add_new_note(request, *args, **kwargs):

    if request.method == 'GET':

        form = BookForm()

        return render(request, 'create.html', context={'form': form})

    elif request.method == 'POST':

        form = BookForm(data=request.POST)

        if form.is_valid():

            Book.objects.create(
                name=form.cleaned_data['name'],
                email=form.cleaned_data['email'],
                text=form.cleaned_data['text'],
            )

            return redirect('index')

        else:

            return render(request, 'create.html', context={'form': form})
Exemplo n.º 5
0
def book_create_view(request, *args, **kwargs):
    if request.method == "GET":
        form = BookForm()
        return render(request, 'create.html', context={'form': form})
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            Book.objects.create(author=form.cleaned_data['author'],
                                email=form.cleaned_data['email'],
                                text=form.cleaned_data['text'])
            return redirect('index')
        else:
            return render(request, 'create.html', context={'form': form})
Exemplo n.º 6
0
def book_create(request):
    if request.method == 'GET':
        form = BookForm()
        return render(request, 'create.html', context={'form': form})
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            data = form.cleaned_data
            book = Book.objects.create(author=data['author'],
                                       email=data['email'],
                                       text=data['text'])
            return redirect('book_index')
        else:
            return render(request, 'create.html', context={'form': form})
def book_create_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = BookForm()
        return render(request, 'create.html', context={'form': form})
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            Books.objects.create(
                name_author=form.cleaned_data['name_author'],
                mail_author=form.cleaned_data['mail_author'],
                entry=form.cleaned_data['entry']
            )
            return redirect('index')
        else:
            return render(request, 'create.html', context={'form': form})
Exemplo n.º 8
0
def index_view(request):
    form = BookForm()
    books = Book.objects.all().filter(status="active").order_by("-created_at")
    return render(request,
                  'index.html',
                  context={
                      'books': books,
                      'form': form
                  })
Exemplo n.º 9
0
def book_create_view(request):
    if request.method == "GET":
        form = BookForm()
        return render(request, 'book_create.html', {
            'stat': STATUS_CHOICES,
            'form': form
        })
    elif request.method == "POST":
        form = BookForm(data=request.POST)
        if form.is_valid():
            book = Book.objects.create(
                name=form.cleaned_data.get("name"),
                email=form.cleaned_data.get("email"),
                description=form.cleaned_data.get("description"),
            )

            return redirect('book_list')
        return render(request, 'book_create.html', context={'form': form})
Exemplo n.º 10
0
def detailed_update_view(request, pk):
    task = get_object_or_404(Book, pk=pk)
    if request.method == 'GET':
        form = BookForm(data={
            'name': task.name,
            'email': task.email,
            'text': text,
        })
        return render(request, 'update.html', context={'form': form, 'task': task})
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            task.name = form.cleaned_data['name']
            task.email = form.cleaned_data['email']
            task.text = form.cleaned_data['text']
            task.save()
            return redirect('index')

        return render(request, 'update.html', context={'form': form, 'task': task})
Exemplo n.º 11
0
def form_storage_view(request, *args, **kwargs):
    if request.method == 'GET':
        form = BookForm()
        return render(request, 'form.html', context={
            'form': form,
            'status': STATUS
        })
    elif request.method == 'POST':
        form = BookForm(data=request.POST)

        if not form.is_valid():
            return render(request, 'form.html', context={'form': form, 'status': STATUS})

        Book.objects.create(
            name=form.cleaned_data['name'],
            email=form.cleaned_data['email'],
            text=form.cleaned_data['text'],

        )
        return redirect('index')
def book_edit_view(request, pk):
    book = get_object_or_404(Books, pk=pk)
    if request.method == 'GET':
        form = BookForm(data={
            'name_author' : book.name_author,
            'mail_author' : book.mail_author,
            'entry' : book.entry
        })
        return render(request, 'update.html', context={'form': form, 'book': book})
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            book.name_author = request.POST.get('name_author')
            book.mail_author = request.POST.get('mail_author')
            book.entry = request.POST.get('entry')
            book.save()
            return redirect('index')
        else:
            return render(request, 'update.html', context={'book': book, 'form': form})
    return redirect('index')
Exemplo n.º 13
0
def update_record_view(request, pk):
    record = get_object_or_404(Book, pk=pk)
    if request.method == 'GET':
        form = BookForm(data={
            'author': record.author,
            'email': record.email,
            'text': record.text
        })
        return render(request,
                      'update.html',
                      context={
                          'form': form,
                          'record': record
                      })
    elif request.method == 'POST':
        form = BookForm(data=request.POST)
        if form.is_valid():
            record.author = form.cleaned_data['author']
            record.email = form.cleaned_data['email']
            record.text = form.cleaned_data['text']
            record.save()
            return redirect('index')
        else:
            return render(request, 'update.html', context={'form': form})