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",
views.txn_store, name="transactions.store"),
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",
views.txn_edit, name="transactions.edit"),
path("transactions/<txn-type:txn_type>/<txn:txn>/update",

View File

@ -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