Example #1
0
def tambah_buku(request):
    if request.POST:
        form = FormBuku(request.POST)
        if form.is_valid():
            form.save()
            form = FormBuku()
            pesan = "Data berhasil disimpan"
            konteks = {'form': form, 'pesan': pesan}
            return render(request, 'tambah-buku.html', konteks, pesan)

    else:
        form = FormBuku()
        konteks = {'form': form}
    return render(request, 'tambah-buku.html', konteks)
Example #2
0
def tambah_buku(request):
    if request.POST:
        form = FormBuku(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, "Successfully Added")
            form = FormBuku()
            konteks = {
                'form': form,
            }
            return redirect('tambah_buku')
    else:
        form = FormBuku()
        konteks = {
            'form': form,
        }
    return render(request, 'tambah-buku.html', konteks)
def tambah_buku(request):
    if request.POST:
        form = FormBuku(request.POST)
        if form.is_valid():
            form.save()
            form = FormBuku()
            message = "Data berhasil disimpan"
            context = {
                'form': form,
                'message': message,
            }
            return render(request, 'tambah-buku.html', context)
    else:
        form = FormBuku()
        context = {
            'form': form,
        }
        return render(request, 'tambah-buku.html', context)
Example #4
0
def tambah_buku(request):
    if request.POST:
        form = FormBuku(request.POST)
        if form.is_valid():
            form.save()
            form = FormBuku()

            konteks = {
                'form': form,
            }
            return render(request, 'tambah-buku.html', konteks)
    else:
        form = FormBuku()

        konteks = {
            'form': form,
        }

    return render(request, 'tambah-buku.html', konteks)
def ubah_buku(request, id_buku):
    book = Buku.objects.get(id=id_buku)
    template = 'ubah-buku.html'
    if request.POST:
        form = FormBuku(request.POST, instance=book)
        if form.is_valid():
            form.save()
            messages.success(request, "Data berhasil diperbaharui")
            return redirect('ubah_buku', id_buku=id_buku)
    else:
        form = FormBuku(instance=book)
        context = {'form': form, 'book': book}
    return render(request, template, context)
Example #6
0
def tambahBuku(request):
    if request.POST:  # jika ada data yg dikirim menggunakan method POST maka
        form = FormBuku(request.POST)  # form dengan data inputan
        if form.is_valid():  # cek validasi inputan user/client
            form.save()  # menyimpan data inputan ke database
            form = FormBuku()

            pesan = 'Data berhasil disimpan'

            konteks = {
                'form': form,
                'pesan': pesan,
            }
            return render(request, 'tambah-buku.html', konteks)
    else:  # jika tidak
        form = FormBuku(
        )  # buat form kosong langsung render ke template tambah-buku.html

        konteks = {
            'form': form,
        }
    return render(request, 'tambah-buku.html', konteks)
Example #7
0
def ubah_buku(request, id_buku):
    buku = Buku.objects.get(id=id_buku)
    if request.POST:
        form = FormBuku(request.POST, instance=buku)
        if form.is_valid():
            form.save()
            messages.success(request, 'Data berhasil di update')
            return redirect('ubah_buku', id_buku=id_buku)
    else:
        form = FormBuku(instance=buku)
        konteks = {
            'form': form,
            'buku': buku,
        }
    return render(request, 'ubah-buku.html', konteks)
Example #8
0
def ubah_buku(request, id_buku):
    buku = Buku.objects.get(id=id_buku)
    template = "ubah-buku.html"
    if request.POST:
        form = FormBuku(request.POST, instance=buku)
        if form.is_valid():
            messages.success(request, "Data berhasil diperbaharui!")
            form.save()
            return redirect('ubah_buku', id_buku=id_buku)
    else:
        form = FormBuku(instance=buku)
        konteks = {
            'form': form,
            'buku': buku,
        }
    return render(request, template, konteks)
Example #9
0
def ubah_buku(request, id_buku):
    buku = Buku.objects.get(id=id_buku)
    template = 'ubah-buku.html'
    if request.POST:
        form = FormBuku(request.POST, instance=buku)
        if form.is_valid():
            form.save()
            messages.success(request, "Data Successfully Changed")
            return redirect('ubah_buku', id_buku=id_buku) # diarahkan kembali ke halaman ubah data itu sendiri
    else:
        form = FormBuku(instance=buku)
        konteks = {
            'form':form,
            'buku':buku,
        }
    return render(request, template, konteks)
Example #10
0
def tambah_buku(request):
    if request.POST:
        # jika ada data yg diterima dr form, maka simpan
        # req.files saat submit data file maka akan ditempatkan di sini juga
        form = FormBuku(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            form = FormBuku()
            pesan = "Data berhasil disimpan"

            isi = {
                'form': form,
                'pesan': pesan,
            }
            return render(request, 'tambah-buku.html', isi)

    else:
        form = FormBuku()

        isi = {
            'form': form,
        }

    return render(request, 'tambah-buku.html', isi)
Example #11
0
def ubah_buku(request, id_buku):
    buku = Buku.objects.get(id=id_buku)
    template = 'ubah-buku.html'

    if request.POST:
        form = FormBuku(request.POST, request.FILES, instance=buku)
        if form.is_valid():
            form.save()
            messages.success(request, "Data berhasil di Ubah!")
            return redirect('ubah_buku', id_buku=id_buku)
    else:
        form = FormBuku(instance=buku)
        isi = {
            'form': form,
            'buku': buku,
        }

        return render(request, 'ubah-buku.html', isi)
Example #12
0
def ubahBuku(request, id_buku):
    buku = Buku.objects.get(id=id_buku)
    template = 'ubah-buku.html'

    if request.POST:
        form = FormBuku(request.POST,
                        instance=buku)  # form berisi data buku tertentu
        if form.is_valid():
            form.save()
            messages.success(request, 'Data berhasil diperbaharui.')
            # setelah berhasil, akan di redirect ke url ubah_buku lagi
            return redirect('ubah_buku', id_buku=id_buku)
    else:
        form = FormBuku(instance=buku)
        konteks = {
            'form': form,
            'buku': buku,
        }
    return render(request, template, konteks)