diff --git a/apps/note/api/views.py b/apps/note/api/views.py index f230a646dd3240c30c8ed60f5b0ec6011093fa25..977441f7ae1dcc0733a5350b9231b9016d8fd5f7 100644 --- a/apps/note/api/views.py +++ b/apps/note/api/views.py @@ -89,9 +89,9 @@ class TransactionTemplateViewSet(ReadProtectedModelViewSet): """ queryset = TransactionTemplate.objects.all() serializer_class = TransactionTemplateSerializer - filter_backends = [DjangoFilterBackend] + filter_backends = [SearchFilter, DjangoFilterBackend] filterset_fields = ['name', 'amount', 'display', 'category', ] - + search_fields = ['$name', ] class TransactionViewSet(ReadProtectedModelViewSet): """ diff --git a/apps/note/tables.py b/apps/note/tables.py index f50379c4ae2d856836fda1eedb24e8db67a1664d..a2044a215aa20ac1efb665f18b632fc413655a13 100644 --- a/apps/note/tables.py +++ b/apps/note/tables.py @@ -82,6 +82,11 @@ class ButtonTable(tables.Table): 'class': 'table table condensed table-striped table-hover' } + row_attrs = { + 'class': 'table-row', + 'data-href': lambda record: record.pk + } + model = TransactionTemplate def render_amount(self, value): diff --git a/apps/note/views.py b/apps/note/views.py index d656d7fc40ffb4117600984587dd798055315fef..a8118cb2a54709021bef50c3a2e7bbe79bf1e32d 100644 --- a/apps/note/views.py +++ b/apps/note/views.py @@ -8,6 +8,7 @@ from django.db.models import Q from django.utils.translation import gettext_lazy as _ from django.views.generic import CreateView, ListView, UpdateView from django_tables2 import SingleTableView +from django.urls import reverse_lazy from permission.backends import PermissionBackend from .forms import TransactionTemplateForm @@ -108,7 +109,7 @@ class TransactionTemplateCreateView(LoginRequiredMixin, CreateView): """ model = TransactionTemplate form_class = TransactionTemplateForm - + success_url = reverse_lazy('template_list') class TransactionTemplateListView(LoginRequiredMixin, SingleTableView): """ @@ -117,6 +118,14 @@ class TransactionTemplateListView(LoginRequiredMixin, SingleTableView): model = TransactionTemplate table_class = ButtonTable + def get_queryset(self): + name = self.request.GET.get('name','') + if (name != ''): + object_list = self.model.objects.filter(name__icontains = name) + else: + object_list = self.model.objects.all() + return object_list + class TransactionTemplateUpdateView(LoginRequiredMixin, UpdateView): """ diff --git a/templates/note/transactiontemplate_list.html b/templates/note/transactiontemplate_list.html index e888198804038a8d9c9df8a177d16dbf575cf480..d193498807661ecfc819f762bedb8db8d3fa88c9 100644 --- a/templates/note/transactiontemplate_list.html +++ b/templates/note/transactiontemplate_list.html @@ -1,7 +1,26 @@ {% extends "base.html" %} {% load pretty_money %} +{% load i18n %} {% load render_table from django_tables2 %} {% block content %} -<a class="btn btn-primary text-center" href="{% url 'note:template_create' %}">Créer un bouton</a> -{% render_table table %} +<div class="row justify-content-center mb-4"> + <div class="col-md-10 text-center"> + <h4> + {% trans "search button" %} + </h4> + <form action="" method="GET"> + {% csrf_token %} + <input class="form-control mx-auto w-25" type="text" id="name" name="name" value='{{ request.GET.name }}'/> + </form> + <ul class="list-group list-group-flush" id="alias_matched"> + </ul> + <hr> + <a class="btn btn-primary text-center my-4" href="{% url 'note:template_create' %}">Créer un bouton</a> + </div> +</div> +<div class="row justify-content-center"> +<div class="col-md-10"> + {% render_table table %} +</div> +</div> {% endblock %}