Add login
This commit is contained in:
parent
e38b781ff9
commit
1f48c41005
5 changed files with 34 additions and 0 deletions
|
@ -1,9 +1,12 @@
|
|||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.http import HttpResponse
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth import views as auth_views
|
||||
|
||||
from .models import Transaction, TransactionForm, Invoice, InvoiceForm, Category
|
||||
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
_transactions = Transaction.objects.order_by("-date")[:5]
|
||||
_categories = Category.objects.order_by("name")
|
||||
|
@ -15,6 +18,15 @@ def index(request):
|
|||
return render(request, "main/index.html", context)
|
||||
|
||||
|
||||
class LoginView(auth_views.LoginView):
|
||||
template_name = "main/login.html"
|
||||
next_page = "index"
|
||||
|
||||
class LogoutView(auth_views.LogoutView):
|
||||
next_page = "login"
|
||||
|
||||
|
||||
@login_required
|
||||
def transaction(request, uuid=None):
|
||||
if uuid is None:
|
||||
_transaction = Transaction()
|
||||
|
@ -34,6 +46,7 @@ def transaction(request, uuid=None):
|
|||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def update_transaction(request, uuid):
|
||||
try:
|
||||
_transaction = Transaction.objects.get(id=uuid)
|
||||
|
@ -44,12 +57,14 @@ def update_transaction(request, uuid):
|
|||
return redirect(transaction, uuid=uuid)
|
||||
|
||||
|
||||
@login_required
|
||||
def invoice(request, uuid):
|
||||
_invoice = get_object_or_404(Invoice, id=uuid)
|
||||
with _invoice.file.open() as _file:
|
||||
return HttpResponse(_file.read(), content_type="application/pdf")
|
||||
|
||||
|
||||
@login_required
|
||||
def add_invoice(request, uuid):
|
||||
_transaction = get_object_or_404(Transaction, id=uuid)
|
||||
_invoice = Invoice(transaction=_transaction)
|
||||
|
@ -58,6 +73,7 @@ def add_invoice(request, uuid):
|
|||
return redirect(transaction, uuid=uuid)
|
||||
|
||||
|
||||
@login_required
|
||||
def del_invoice(request, uuid, invoice_id):
|
||||
_invoice = get_object_or_404(Invoice, id=invoice_id)
|
||||
_invoice.delete()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue