diff --git a/nummi/statement/models.py b/nummi/statement/models.py index 8e91bcb..865abdd 100644 --- a/nummi/statement/models.py +++ b/nummi/statement/models.py @@ -79,10 +79,10 @@ class Statement(AccountModel): super().delete(*args, **kwargs) def get_absolute_url(self): - return reverse("statement", kwargs={"pk": self.pk}) + return reverse("statement", args=(self.pk,)) def get_delete_url(self): - return reverse("del_statement", kwargs={"pk": self.pk}) + return reverse("del_statement", args=(self.pk,)) class Meta: ordering = ["-date", "account"] diff --git a/nummi/main/templates/main/form/statement.html b/nummi/statement/templates/statement/statement_form.html similarity index 100% rename from nummi/main/templates/main/form/statement.html rename to nummi/statement/templates/statement/statement_form.html diff --git a/nummi/main/templates/main/list/statement.html b/nummi/statement/templates/statement/statement_list.html similarity index 100% rename from nummi/main/templates/main/list/statement.html rename to nummi/statement/templates/statement/statement_list.html diff --git a/nummi/statement/urls.py b/nummi/statement/urls.py index c5d7442..d9e1e3b 100644 --- a/nummi/statement/urls.py +++ b/nummi/statement/urls.py @@ -4,21 +4,21 @@ from transaction.views import TransactionCreateView from . import views urlpatterns = [ - path("statements", views.StatementListView.as_view(), name="statements"), - path("statement", views.StatementCreateView.as_view(), name="new_statement"), - path("statement/", views.StatementUpdateView.as_view(), name="statement"), + path("list", views.StatementListView.as_view(), name="statements"), + path("new", views.StatementCreateView.as_view(), name="new_statement"), + path("", views.StatementUpdateView.as_view(), name="statement"), path( - "statement//transactions", + "/transaction/list", views.StatementTListView.as_view(), name="statement_transactions", ), path( - "statement//transaction", + "/transaction/new", TransactionCreateView.as_view(), name="new_transaction", ), path( - "statement//delete", + "/delete", views.StatementDeleteView.as_view(), name="del_statement", ), diff --git a/nummi/statement/views.py b/nummi/statement/views.py index 68cdc43..cbbbc6a 100644 --- a/nummi/statement/views.py +++ b/nummi/statement/views.py @@ -12,7 +12,6 @@ from .models import Statement class StatementCreateView(NummiCreateView): model = Statement form_class = StatementForm - template_name = "main/form/statement.html" def get_initial(self): _queryset = Account.objects.filter(user=self.request.user) @@ -36,7 +35,7 @@ class StatementCreateView(NummiCreateView): class StatementUpdateView(NummiUpdateView): model = Statement form_class = StatementForm - template_name = "main/form/statement.html" + pk_url_kwarg = "statement" def get_context_data(self, **kwargs): data = super().get_context_data(**kwargs) @@ -74,23 +73,24 @@ class StatementUpdateView(NummiUpdateView): class StatementDeleteView(NummiDeleteView): model = Statement + pk_url_kwarg = "statement" class StatementListView(NummiListView): model = Statement - template_name = "main/list/statement.html" context_object_name = "statements" class StatementMixin: def get_queryset(self): - return super().get_queryset().filter(statement=self.kwargs.get("pk")) + self.statement = get_object_or_404( + Statement.objects.filter(user=self.request.user), + pk=self.kwargs.get("statement"), + ) + return super().get_queryset().filter(statement=self.statement) def get_context_data(self, **kwargs): - return super().get_context_data(**kwargs) | { - "object": Statement.objects.get(pk=self.kwargs.get("pk")), - "statement": True, - } + return super().get_context_data(**kwargs) | {"statement": self.statement} class StatementTListView(StatementMixin, TransactionListView):