From 7521cc236fefef9fa7b2d7738c407c91fc212458 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 20 Apr 2023 14:39:45 +0200 Subject: [PATCH] Remove get_create_url, redirect createform to same page using hidden form field --- nummi/main/models.py | 15 --------------- nummi/main/templates/main/form/base.html | 1 + nummi/main/templates/main/table/invoice.html | 2 +- nummi/main/views.py | 7 ++++--- 4 files changed, 6 insertions(+), 19 deletions(-) diff --git a/nummi/main/models.py b/nummi/main/models.py index 50190cf..d967eda 100644 --- a/nummi/main/models.py +++ b/nummi/main/models.py @@ -53,9 +53,6 @@ class Account(NummiModel): def __str__(self): return str(self.name) - def get_create_url(self): - return reverse("new_account") - def get_absolute_url(self): return reverse("account", kwargs={"pk": self.pk}) @@ -102,9 +99,6 @@ class Category(NummiModel): def __str__(self): return str(self.name) - def get_create_url(self): - return reverse("new_category") - def get_absolute_url(self): return reverse("category", kwargs={"pk": self.pk}) @@ -189,9 +183,6 @@ class Snapshot(AccountModel): self.file.delete() super().delete(*args, **kwargs) - def get_create_url(self): - return reverse("new_snapshot") - def get_absolute_url(self): return reverse("snapshot", kwargs={"pk": self.pk}) @@ -254,9 +245,6 @@ class Transaction(NummiModel): def __str__(self): return f"{self.name}" - def get_create_url(self): - return reverse("new_transaction") - def get_absolute_url(self): return reverse("transaction", kwargs={"pk": self.pk}) @@ -306,9 +294,6 @@ class Invoice(NummiModel): self.file.delete() super().delete(*args, **kwargs) - def get_create_url(self): - return reverse("new_invoice", kwargs={"transaction_pk": self.transaction.pk}) - def get_absolute_url(self): return reverse( "invoice", kwargs={"transaction_pk": self.transaction.pk, "pk": self.pk} diff --git a/nummi/main/templates/main/form/base.html b/nummi/main/templates/main/form/base.html index 462f429..2904904 100644 --- a/nummi/main/templates/main/form/base.html +++ b/nummi/main/templates/main/form/base.html @@ -35,6 +35,7 @@ {% endif %}
{% csrf_token %} + {% if instance.adding %}{% endif %} {{ form }}
{% block tables %}{% endblock %} diff --git a/nummi/main/templates/main/table/invoice.html b/nummi/main/templates/main/table/invoice.html index bc3024b..a1c9727 100644 --- a/nummi/main/templates/main/table/invoice.html +++ b/nummi/main/templates/main/table/invoice.html @@ -34,7 +34,7 @@ - {% translate "New invoice" %} + {% translate "New invoice" %} diff --git a/nummi/main/views.py b/nummi/main/views.py index 2a0fb0a..c72d7bf 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -71,13 +71,14 @@ class UserFormMixin: class NummiCreateView(UserMixin, UserFormMixin, CreateView): - def get_success_url(self): - return self.object.get_create_url() - def form_valid(self, form): form.instance.user = self.request.user + self.next = form.data.get("next") return super().form_valid(form) + def get_success_url(self): + return self.next or super().get_success_url() + class NummiUpdateView(UserMixin, UserFormMixin, UpdateView): pass