diff --git a/accounting/urls.py b/accounting/urls.py index 9c0c150..fb77042 100644 --- a/accounting/urls.py +++ b/accounting/urls.py @@ -81,7 +81,7 @@ urlpatterns = [ path("transactions//store", views.txn_store, name="transactions.store"), path("transactions//", - views.txn_detail, name="transactions.detail"), + views.TransactionView.as_view(), name="transactions.detail"), path("transactions///edit", views.txn_edit, name="transactions.edit"), path("transactions///update", diff --git a/accounting/views.py b/accounting/views.py index 187d872..6626d21 100644 --- a/accounting/views.py +++ b/accounting/views.py @@ -799,22 +799,18 @@ def search(request): }) -@require_GET -@login_required -def txn_detail(request, txn_type, txn): - """The view of the details of an accounting transaction. +@method_decorator(require_GET, name="dispatch") +@method_decorator(login_required, name="dispatch") +class TransactionView(DetailView): + """The view of the details of an accounting transaction.""" + context_object_name = "txn" - Args: - request (HttpRequest): The request. - txn_type (str): The transaction type. - txn (Transaction): The transaction. + def get_object(self, queryset=None): + return self.request.resolver_match.kwargs["txn"] - Returns: - HttpResponse: The response. - """ - return render(request, F"accounting/transactions/{txn_type}/detail.html", { - "txn": txn, - }) + def get_template_names(self): + return ["accounting/transactions/%s/detail.html" + % (self.request.resolver_match.kwargs["txn_type"],)] @require_GET