Updated search view to process post via class-based view
This commit is contained in:
parent
a6805212fc
commit
0d37594f0b
4 changed files with 26 additions and 24 deletions
|
@ -48,7 +48,7 @@
|
|||
accesskey="s">
|
||||
{% translate "Snapshot" %}
|
||||
</a>
|
||||
<form id="search" action="{% url 'search_post' %}" method="post">
|
||||
<form id="search" action="{% url 'search' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="text"
|
||||
name="search"
|
||||
|
|
|
@ -13,20 +13,24 @@
|
|||
{% endblock %}
|
||||
{% block body %}
|
||||
<h1>{% translate "Transactions" %}</h1>
|
||||
{% transaction_table transactions %}
|
||||
{% if page_obj %}
|
||||
<div class="pagination">
|
||||
<span class="step-links">
|
||||
{% if page_obj.has_previous %}
|
||||
<a href="?page=1">↞</a>
|
||||
<a href="?page={{ page_obj.previous_page_number }}">←</a>
|
||||
{% endif %}
|
||||
<span class="current">{{ page_obj.number }}/{{ page_obj.paginator.num_pages }}</span>
|
||||
{% if page_obj.has_next %}
|
||||
<a href="?page={{ page_obj.next_page_number }}">→</a>
|
||||
<a href="?page={{ page_obj.paginator.num_pages }}">↠</a>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
{% if transactions %}
|
||||
{% transaction_table transactions %}
|
||||
{% if page_obj %}
|
||||
<div class="pagination">
|
||||
<span class="step-links">
|
||||
{% if page_obj.has_previous %}
|
||||
<a href="?page=1">↞</a>
|
||||
<a href="?page={{ page_obj.previous_page_number }}">←</a>
|
||||
{% endif %}
|
||||
<span class="current">{{ page_obj.number }}/{{ page_obj.paginator.num_pages }}</span>
|
||||
{% if page_obj.has_next %}
|
||||
<a href="?page={{ page_obj.next_page_number }}">→</a>
|
||||
<a href="?page={{ page_obj.paginator.num_pages }}">↠</a>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<p>{% translate "No transactions to show" %}</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -39,6 +39,6 @@ urlpatterns = [
|
|||
path(
|
||||
"snapshot/<pk>/delete", views.SnapshotDeleteView.as_view(), name="del_snapshot"
|
||||
),
|
||||
path("search", views.search, name="search_post"),
|
||||
path("search", views.SearchView.as_view(), name="search"),
|
||||
path("search/<search>", views.SearchView.as_view(), name="search"),
|
||||
]
|
||||
|
|
|
@ -13,6 +13,7 @@ from django.http import HttpResponse
|
|||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic import CreateView, DeleteView, ListView, UpdateView
|
||||
from django.views.generic.edit import ProcessFormView
|
||||
|
||||
from .models import (
|
||||
Category,
|
||||
|
@ -144,18 +145,15 @@ class SnapshotDeleteView(LoginRequiredMixin, DeleteView):
|
|||
success_url = reverse_lazy("index")
|
||||
|
||||
|
||||
@login_required
|
||||
def search(request):
|
||||
_search = request.POST.get("search")
|
||||
return redirect("search", search=_search)
|
||||
|
||||
|
||||
class SearchView(LoginRequiredMixin, ListView):
|
||||
class SearchView(LoginRequiredMixin, ListView, ProcessFormView):
|
||||
paginate_by = 24
|
||||
model = Transaction
|
||||
template_name = "main/transactions.html"
|
||||
context_object_name = "transactions"
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
return redirect("search", search=self.request.POST.get("search"))
|
||||
|
||||
def get_queryset(self):
|
||||
self.search = self.kwargs["search"]
|
||||
return (
|
||||
|
|
Loading…
Reference in a new issue