Replaced the function-based txn_detail() view with the class-based TransactionView view in the accounting application.

This commit is contained in:
依瑪貓 2020-08-08 16:08:15 +08:00
parent 908fbedf0d
commit f29e939de3
2 changed files with 11 additions and 15 deletions

View File

@ -81,7 +81,7 @@ urlpatterns = [
path("transactions/<txn-type:txn_type>/store", path("transactions/<txn-type:txn_type>/store",
views.txn_store, name="transactions.store"), views.txn_store, name="transactions.store"),
path("transactions/<txn-type:txn_type>/<txn:txn>", path("transactions/<txn-type:txn_type>/<txn:txn>",
views.txn_detail, name="transactions.detail"), views.TransactionView.as_view(), name="transactions.detail"),
path("transactions/<txn-type:txn_type>/<txn:txn>/edit", path("transactions/<txn-type:txn_type>/<txn:txn>/edit",
views.txn_edit, name="transactions.edit"), views.txn_edit, name="transactions.edit"),
path("transactions/<txn-type:txn_type>/<txn:txn>/update", path("transactions/<txn-type:txn_type>/<txn:txn>/update",

View File

@ -799,22 +799,18 @@ def search(request):
}) })
@require_GET @method_decorator(require_GET, name="dispatch")
@login_required @method_decorator(login_required, name="dispatch")
def txn_detail(request, txn_type, txn): class TransactionView(DetailView):
"""The view of the details of an accounting transaction. """The view of the details of an accounting transaction."""
context_object_name = "txn"
Args: def get_object(self, queryset=None):
request (HttpRequest): The request. return self.request.resolver_match.kwargs["txn"]
txn_type (str): The transaction type.
txn (Transaction): The transaction.
Returns: def get_template_names(self):
HttpResponse: The response. return ["accounting/transactions/%s/detail.html"
""" % (self.request.resolver_match.kwargs["txn_type"],)]
return render(request, F"accounting/transactions/{txn_type}/detail.html", {
"txn": txn,
})
@require_GET @require_GET