Compare commits
No commits in common. "c3c328fdd623df594460f883114244ce10814684" and "c5ac2d83c7e9e6571f295424221e724a9279b592" have entirely different histories.
c3c328fdd6
...
c5ac2d83c7
9 changed files with 102 additions and 101 deletions
|
@ -18,8 +18,6 @@ class Category(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class CategoryForm(ModelForm):
|
class CategoryForm(ModelForm):
|
||||||
template_name = "main/form.html"
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Category
|
model = Category
|
||||||
fields = ["name", "icon"]
|
fields = ["name", "icon"]
|
||||||
|
@ -49,8 +47,6 @@ class Transaction(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class TransactionForm(ModelForm):
|
class TransactionForm(ModelForm):
|
||||||
template_name = "main/form.html"
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Transaction
|
model = Transaction
|
||||||
fields = [
|
fields = [
|
||||||
|
@ -82,8 +78,6 @@ class Invoice(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class InvoiceForm(ModelForm):
|
class InvoiceForm(ModelForm):
|
||||||
template_name = "main/form.html"
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Invoice
|
model = Invoice
|
||||||
fields = ["name", "file"]
|
fields = ["name", "file"]
|
||||||
|
@ -184,8 +178,6 @@ class Snapshot(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class SnapshotForm(ModelForm):
|
class SnapshotForm(ModelForm):
|
||||||
template_name = "main/form.html"
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Snapshot
|
model = Snapshot
|
||||||
fields = ["date", "value"]
|
fields = ["date", "value"]
|
||||||
|
|
|
@ -6,14 +6,6 @@ form {
|
||||||
line-height: 2rem;
|
line-height: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
form ul.errorlist {
|
|
||||||
grid-column: 1 / -1;
|
|
||||||
color: var(--red);
|
|
||||||
font-weight: 550;
|
|
||||||
list-style-type: "! ";
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
form input,
|
form input,
|
||||||
form select,
|
form select,
|
||||||
form textarea {
|
form textarea {
|
||||||
|
|
|
@ -11,9 +11,13 @@
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<h1><i class="fa fa-{{ category.icon }}"></i> {{ category }}</h1>
|
<h1><i class="fa fa-{{ category.icon }}"></i> {{ category }}</h1>
|
||||||
|
|
||||||
<form action="{% url 'category' category.id %}" method="post">
|
<form action="{% url 'update_category' category.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form }}
|
{% for field in form %}
|
||||||
|
{{ field.errors }}
|
||||||
|
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||||
|
{{ field }}
|
||||||
|
{% endfor %}
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="{% url 'del_category' category.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
<a href="{% url 'del_category' category.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
||||||
<input type="reset" />
|
<input type="reset" />
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
{% for field in form %}
|
|
||||||
{{ field.errors }}
|
|
||||||
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
|
||||||
{{ field }}
|
|
||||||
{% endfor %}
|
|
|
@ -29,7 +29,7 @@
|
||||||
{% for snap in snapshots %}
|
{% for snap in snapshots %}
|
||||||
<div class="snapshot {% cycle 'w' 'g' %}">
|
<div class="snapshot {% cycle 'w' 'g' %}">
|
||||||
<span class="date num center">
|
<span class="date num center">
|
||||||
<a href="{% url 'snapshot' snap.id %}">{{ snap.date|date:"Y-m-d" }}</a>
|
<a href="{% url 'snapshot' snap.date %}">{{ snap.date|date:"Y-m-d" }}</a>
|
||||||
</span>
|
</span>
|
||||||
<span class="value num right">{% value snap.value %}</span>
|
<span class="value num right">{% value snap.value %}</span>
|
||||||
<span class="diff num right">
|
<span class="diff num right">
|
||||||
|
|
|
@ -21,9 +21,13 @@
|
||||||
{{ snapshot }}
|
{{ snapshot }}
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<form action="{% url 'snapshot' snapshot.id %}" method="post">
|
<form action="{% url 'update_snapshot' snapshot.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form }}
|
{% for field in form %}
|
||||||
|
{{ field.errors }}
|
||||||
|
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||||
|
{{ field }}
|
||||||
|
{% endfor %}
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="{% url 'del_snapshot' snapshot.date %}"><input type="button" value="Delete" class="del" /></a>
|
<a href="{% url 'del_snapshot' snapshot.date %}"><input type="button" value="Delete" class="del" /></a>
|
||||||
<input type="reset" />
|
<input type="reset" />
|
||||||
|
|
|
@ -10,10 +10,13 @@
|
||||||
<h1>{{ transaction }}</h1>
|
<h1>{{ transaction }}</h1>
|
||||||
|
|
||||||
{% spaceless %}
|
{% spaceless %}
|
||||||
<form id="transaction" action="{% url 'transaction' transaction.id %}" method="post">
|
<form id="transaction" action="{% url 'update_transaction' transaction.id %}" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="form" value="transaction" />
|
{% for field in form %}
|
||||||
{{ form }}
|
{{ field.errors }}
|
||||||
|
<label for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||||
|
{{ field }}
|
||||||
|
{% endfor %}
|
||||||
<div class="buttons">
|
<div class="buttons">
|
||||||
<a href="{% url 'del_transaction' transaction.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
<a href="{% url 'del_transaction' transaction.id %}"><input type="button" value="Delete" class="btn del" /></a>
|
||||||
<input class="btn" type="reset" />
|
<input class="btn" type="reset" />
|
||||||
|
@ -36,10 +39,13 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3>Add Invoice</h3>
|
<h3>Add Invoice</h3>
|
||||||
<form action="{% url 'transaction' transaction.id %}" method="post" enctype="multipart/form-data">
|
<form action="{% url 'add_invoice' transaction.id %}" method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="form" value="invoice" />
|
{% for field in invoice_form %}
|
||||||
{{ invoice_form }}
|
{{ field.errors }}
|
||||||
|
<label for="{{ field.id_for_label }}">{{field.label }}</label>
|
||||||
|
{{ field }}
|
||||||
|
{% endfor %}
|
||||||
<div class="buttons"><input class="btn" type="submit" value="Add Invoice" /></div>
|
<div class="buttons"><input class="btn" type="submit" value="Add Invoice" /></div>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -9,13 +9,23 @@ urlpatterns = [
|
||||||
path("transactions", views.TransactionListView.as_view(), name="transactions"),
|
path("transactions", views.TransactionListView.as_view(), name="transactions"),
|
||||||
path("transaction", views.transaction, name="transaction"),
|
path("transaction", views.transaction, name="transaction"),
|
||||||
path("transaction/<uuid>", views.transaction, name="transaction"),
|
path("transaction/<uuid>", views.transaction, name="transaction"),
|
||||||
|
path(
|
||||||
|
"transaction/<uuid>/update", views.update_transaction, name="update_transaction"
|
||||||
|
),
|
||||||
path("transaction/<uuid>/del", views.del_transaction, name="del_transaction"),
|
path("transaction/<uuid>/del", views.del_transaction, name="del_transaction"),
|
||||||
path("del_invoice/<uuid>/<invoice_id>", views.del_invoice, name="del_invoice"),
|
path("transaction/<uuid>/add_invoice", views.add_invoice, name="add_invoice"),
|
||||||
|
path(
|
||||||
|
"transaction/<uuid>/del_invoice/<invoice_id>",
|
||||||
|
views.del_invoice,
|
||||||
|
name="del_invoice",
|
||||||
|
),
|
||||||
path("invoice/<uuid>", views.invoice, name="invoice"),
|
path("invoice/<uuid>", views.invoice, name="invoice"),
|
||||||
path("category", views.category, name="category"),
|
path("category", views.category, name="category"),
|
||||||
path("category/<uuid>", views.category, name="category"),
|
path("category/<uuid>", views.category, name="category"),
|
||||||
|
path("category/<uuid>/update", views.update_category, name="update_category"),
|
||||||
path("category/<uuid>/del", views.del_category, name="del_category"),
|
path("category/<uuid>/del", views.del_category, name="del_category"),
|
||||||
path("snapshot", views.snapshot, name="snapshot"),
|
path("snapshot", views.snapshot, name="snapshot"),
|
||||||
path("snapshot/<uuid>", views.snapshot, name="snapshot"),
|
path("snapshot/<date>", views.snapshot, name="snapshot"),
|
||||||
path("snapshot/<uuid>/del", views.del_snapshot, name="del_snapshot"),
|
path("snapshot/update/<uuid>", views.update_snapshot, name="update_snapshot"),
|
||||||
|
path("snapshot/<date>/del", views.del_snapshot, name="del_snapshot"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -50,41 +50,32 @@ class TransactionListView(LoginRequiredMixin, ListView):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def transaction(request, uuid=None):
|
def transaction(request, uuid=None):
|
||||||
_form = None
|
if uuid is None:
|
||||||
_inv_form = None
|
_transaction = Transaction()
|
||||||
_invoices = []
|
_invoices = []
|
||||||
if request.method == "GET":
|
else:
|
||||||
if uuid is None:
|
_transaction = get_object_or_404(Transaction, id=uuid)
|
||||||
_transaction = Transaction()
|
_invoices = Invoice.objects.filter(transaction=_transaction)
|
||||||
else:
|
|
||||||
_transaction = get_object_or_404(Transaction, id=uuid)
|
|
||||||
elif request.method == "POST":
|
|
||||||
if request.POST["form"] == "transaction":
|
|
||||||
_transaction, _ = Transaction.objects.get_or_create(id=uuid)
|
|
||||||
_form = TransactionForm(request.POST, instance=_transaction)
|
|
||||||
if _form.is_valid():
|
|
||||||
_form.save()
|
|
||||||
_inv_form = InvoiceForm(instance=Invoice(transaction=_transaction))
|
|
||||||
elif request.POST["form"] == "invoice":
|
|
||||||
_transaction = get_object_or_404(Transaction, id=uuid)
|
|
||||||
_invoice = Invoice(transaction=_transaction)
|
|
||||||
_inv_form = InvoiceForm(request.POST, request.FILES, instance=_invoice)
|
|
||||||
if _inv_form.is_valid():
|
|
||||||
_inv_form.save()
|
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"main/transaction.html",
|
"main/transaction.html",
|
||||||
{
|
{
|
||||||
"transaction": _transaction,
|
"transaction": _transaction,
|
||||||
"form": _form or TransactionForm(instance=_transaction),
|
"form": TransactionForm(instance=_transaction),
|
||||||
"invoices": _invoices or Invoice.objects.filter(transaction=_transaction),
|
"invoices": _invoices,
|
||||||
"invoice_form": _inv_form
|
"invoice_form": InvoiceForm(instance=Invoice(transaction=_transaction)),
|
||||||
or InvoiceForm(instance=Invoice(transaction=_transaction)),
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def update_transaction(request, uuid):
|
||||||
|
_transaction, _ = Transaction.objects.get_or_create(id=uuid)
|
||||||
|
_form = TransactionForm(request.POST, instance=_transaction)
|
||||||
|
_form.save()
|
||||||
|
return redirect(transaction, uuid=uuid)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def del_transaction(request, uuid):
|
def del_transaction(request, uuid):
|
||||||
_transaction = get_object_or_404(Transaction, id=uuid)
|
_transaction = get_object_or_404(Transaction, id=uuid)
|
||||||
|
@ -99,6 +90,15 @@ def invoice(request, uuid):
|
||||||
return HttpResponse(_file.read(), content_type="application/pdf")
|
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)
|
||||||
|
_form = InvoiceForm(request.POST, request.FILES, instance=_invoice)
|
||||||
|
_form.save()
|
||||||
|
return redirect(transaction, uuid=uuid)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def del_invoice(request, uuid, invoice_id):
|
def del_invoice(request, uuid, invoice_id):
|
||||||
_invoice = get_object_or_404(Invoice, id=invoice_id)
|
_invoice = get_object_or_404(Invoice, id=invoice_id)
|
||||||
|
@ -108,29 +108,31 @@ def del_invoice(request, uuid, invoice_id):
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def category(request, uuid=None):
|
def category(request, uuid=None):
|
||||||
if request.method == "GET":
|
if uuid is None:
|
||||||
if uuid is None:
|
_category = Category()
|
||||||
_category = Category()
|
_transactions = None
|
||||||
else:
|
else:
|
||||||
_category = get_object_or_404(Category, id=uuid)
|
_category = get_object_or_404(Category, id=uuid)
|
||||||
_form = CategoryForm(instance=_category)
|
_transactions = Transaction.objects.filter(category=_category)
|
||||||
elif request.method == "POST":
|
|
||||||
_category, _ = Category.objects.get_or_create(id=uuid)
|
|
||||||
_form = CategoryForm(request.POST, instance=_category)
|
|
||||||
if _form.is_valid():
|
|
||||||
_form.save()
|
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"main/category.html",
|
"main/category.html",
|
||||||
{
|
{
|
||||||
"category": _category,
|
"category": _category,
|
||||||
"form": _form,
|
"form": CategoryForm(instance=_category),
|
||||||
"transactions": Transaction.objects.filter(category=_category),
|
"transactions": _transactions,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def update_category(request, uuid):
|
||||||
|
_category, _ = Category.objects.get_or_create(id=uuid)
|
||||||
|
_form = CategoryForm(request.POST, instance=_category)
|
||||||
|
_form.save()
|
||||||
|
return redirect(category, uuid=uuid)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def del_category(request, uuid):
|
def del_category(request, uuid):
|
||||||
_category = get_object_or_404(Category, id=uuid)
|
_category = get_object_or_404(Category, id=uuid)
|
||||||
|
@ -139,38 +141,34 @@ def del_category(request, uuid):
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def snapshot(request, uuid=None):
|
def snapshot(request, date=None):
|
||||||
if request.method == "GET":
|
if date is None:
|
||||||
if uuid is None:
|
_snapshot = Snapshot()
|
||||||
_snapshot = Snapshot()
|
else:
|
||||||
else:
|
_snapshot = get_object_or_404(Snapshot, date=date)
|
||||||
_snapshot = get_object_or_404(Snapshot, id=uuid)
|
|
||||||
context = {
|
|
||||||
"snapshot": _snapshot,
|
|
||||||
"form": SnapshotForm(instance=_snapshot),
|
|
||||||
}
|
|
||||||
elif request.method == "POST":
|
|
||||||
try:
|
|
||||||
_snapshot = Snapshot.objects.get(id=uuid)
|
|
||||||
except Snapshot.DoesNotExist:
|
|
||||||
_snapshot = Snapshot(id=uuid)
|
|
||||||
_form = SnapshotForm(request.POST, instance=_snapshot)
|
|
||||||
if _form.is_valid():
|
|
||||||
_form.save()
|
|
||||||
context = {
|
|
||||||
"snapshot": _snapshot,
|
|
||||||
"form": _form,
|
|
||||||
}
|
|
||||||
|
|
||||||
return render(
|
return render(
|
||||||
request,
|
request,
|
||||||
"main/snapshot.html",
|
"main/snapshot.html",
|
||||||
context,
|
{
|
||||||
|
"snapshot": _snapshot,
|
||||||
|
"form": SnapshotForm(instance=_snapshot),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def del_snapshot(request, uuid):
|
def update_snapshot(request, uuid):
|
||||||
_snapshot = get_object_or_404(Snapshot, id=uuid)
|
try:
|
||||||
|
_snapshot = Snapshot.objects.get(id=uuid)
|
||||||
|
except Snapshot.DoesNotExist:
|
||||||
|
_snapshot = Snapshot(id=uuid)
|
||||||
|
_form = SnapshotForm(request.POST, instance=_snapshot)
|
||||||
|
_form.save()
|
||||||
|
return redirect(snapshot, date=_snapshot.date)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def del_snapshot(request, date):
|
||||||
|
_snapshot = get_object_or_404(Snapshot, date=date)
|
||||||
_snapshot.delete()
|
_snapshot.delete()
|
||||||
return redirect(index)
|
return redirect(index)
|
||||||
|
|
Loading…
Reference in a new issue