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