Replaced the function-based search view with the class-based SearchListView in the accounting application.
This commit is contained in:
parent
b6a5bc3166
commit
8c390df4cd
@ -73,7 +73,7 @@ urlpatterns = [
|
||||
path("balance-sheet/<period:period>",
|
||||
views.balance_sheet, name="balance-sheet"),
|
||||
path("search",
|
||||
views.search, name="search"),
|
||||
views.SearchListView.as_view(), name="search"),
|
||||
path("transactions/<txn-type:txn_type>/create",
|
||||
views.TransactionFormView.as_view(), name="transactions.create"),
|
||||
path("transactions/<txn-type:txn_type>/<txn:txn>",
|
||||
|
@ -39,7 +39,7 @@ from django.utils import timezone
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import gettext as _, gettext_noop, gettext
|
||||
from django.views.decorators.http import require_GET, require_POST
|
||||
from django.views.generic import ListView, DetailView
|
||||
from django.views.generic import ListView, DetailView, TemplateView
|
||||
|
||||
from mia_core.period import Period
|
||||
from mia_core.utils import Pagination, PaginationException, add_default_libs, \
|
||||
@ -756,18 +756,13 @@ def balance_sheet(request: HttpRequest, period: Period) -> HttpResponse:
|
||||
})
|
||||
|
||||
|
||||
@require_GET
|
||||
def search(request: HttpRequest) -> HttpResponse:
|
||||
"""The search.
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
class SearchListView(TemplateView):
|
||||
"The search."""
|
||||
template_name = "accounting/search.html"
|
||||
|
||||
Args:
|
||||
request: The request.
|
||||
|
||||
Returns:
|
||||
The response.
|
||||
"""
|
||||
# The accounting records
|
||||
query = request.GET.get("q")
|
||||
def get_context_data(self, **kwargs):
|
||||
query = self.request.GET.get("q")
|
||||
if query is None:
|
||||
records = []
|
||||
else:
|
||||
@ -811,13 +806,13 @@ def search(request: HttpRequest) -> HttpResponse:
|
||||
pass
|
||||
records = Record.objects.filter(conditions)
|
||||
try:
|
||||
pagination = Pagination(request, records, True)
|
||||
pagination = Pagination(self.request, records, True)
|
||||
except PaginationException as e:
|
||||
return redirect(e.url)
|
||||
return render(request, "accounting/search.html", {
|
||||
"record_list": pagination.items,
|
||||
"pagination": pagination,
|
||||
})
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["record_list"] = pagination.items
|
||||
context["pagination"] = pagination
|
||||
return context
|
||||
|
||||
|
||||
@method_decorator(require_GET, name="dispatch")
|
||||
|
Loading…
Reference in New Issue
Block a user