Browse Source

feat(associations): apporte le filtrage des assos dans la liste

pull/106/head
François Poulain François Poulain 6 months ago
parent
commit
76a150a3da
10 changed files with 85 additions and 10 deletions
  1. +8
    -0
      assets/scss/components/_forms.scss
  2. +13
    -0
      benevalibre/association/filters.py
  3. +11
    -0
      benevalibre/association/forms.py
  4. +19
    -0
      benevalibre/association/tests/test_views.py
  5. +6
    -5
      benevalibre/association/views.py
  6. +1
    -0
      benevalibre/settings/base.py
  7. +7
    -0
      benevalibre/templates/association/association_list.html
  8. +12
    -0
      benevalibre/templates/association/forms/fields/search.html
  9. +7
    -5
      benevalibre/templates/base.html
  10. +1
    -0
      requirements/base.txt

+ 8
- 0
assets/scss/components/_forms.scss View File

@@ -55,3 +55,11 @@
margin-top: .5rem;
}
}

// Visible placeholder for search form
.search-input{
border-color: $white;
&::placeholder{
color: $gray-200;
}
}

+ 13
- 0
benevalibre/association/filters.py View File

@@ -0,0 +1,13 @@
from cruditor.filters import MultiCharFilter
from django_filters import FilterSet

from . import forms, models


class AssociationIndexFilter(FilterSet):
search = MultiCharFilter(['name', 'description'], label="Filtrer")

class Meta:
model = models.Association
form = forms.FilterForm
fields = ['search']

+ 11
- 0
benevalibre/association/forms.py View File

@@ -80,3 +80,14 @@ class EngagementUpdateForm(CustomTapeformMixin, forms.ModelForm):
class Meta:
model = models.Engagement
fields = ('role',)


class FilterForm(CustomTapeformMixin, forms.Form):
field_template = 'association/forms/fields/search.html'
field_label_css_class = 'sr-only'
widget_css_class = CustomTapeformMixin.widget_css_class + ' search-input'

def apply_widget_options(self, field_name):
field = self.fields[field_name]
# utilise l'attribut placeholder au lieu du label
field.widget.attrs['placeholder'] = field.label

+ 19
- 0
benevalibre/association/tests/test_views.py View File

@@ -117,6 +117,25 @@ class TestAssociationIndex:
assert len(response.context['object_list']) == 3
assert count_text_in_content(response, "En modération")

def test_search(self, client):
Association.objects.create(name="Asso 4"),

response = client.get(self.url, {'search': 'Asso'})
assert response.status_code == 200
assert len(response.context['object_list']) == 2
assert count_text_in_content(response, "Asso 1")
assert count_text_in_content(response, "Asso 4")

response = client.get(self.url, {'search': 'Asso 1'})
assert response.status_code == 200
assert len(response.context['object_list']) == 1
assert count_text_in_content(response, "Asso 1")
assert not count_text_in_content(response, "Asso 4")

response = client.get(self.url, {'search': 'Asso 6'})
assert response.status_code == 200
assert len(response.context['object_list']) == 0


@pytest.mark.django_db
class TestAssociationDetail:


+ 6
- 5
benevalibre/association/views.py View File

@@ -4,7 +4,7 @@ from django.contrib.auth.mixins import UserPassesTestMixin
from django.http import Http404
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.views.generic import DetailView, ListView
from django.views.generic import DetailView

from cruditor.views import (
CruditorAddView,
@@ -12,12 +12,13 @@ from cruditor.views import (
CruditorDeleteView,
CruditorListView,
)
from django_filters.views import FilterView

from benevalibre.base.tables import EngagementIndexTable
from benevalibre.utils.html import fa_icon
from benevalibre.utils.views import CruditorPageMixin, PageMixin

from . import forms, models, tables
from . import filters, forms, models, tables


def get_management_buttons(association, user):
@@ -129,8 +130,7 @@ class AssociationRelatedFormMixin:
# ASSOCIATIONS
# ------------------------------------------------------------------------------


class AssociationIndex(PageMixin, ListView):
class AssociationIndex(PageMixin, FilterView):
"""
La page « Liste des associations » vous permet de voir les associations
enregistrées et visibles publiquement au sein de l'application. En cliquant
@@ -143,8 +143,9 @@ class AssociationIndex(PageMixin, ListView):
page d'accueil si vous n'êtes pas connecté⋅e.
"""

template_name = 'associations/association_list.html'
template_name = 'association/association_list.html'
title = "Liste des associations"
filterset_class = filters.AssociationIndexFilter

def get_queryset(self):
return (


+ 1
- 0
benevalibre/settings/base.py View File

@@ -83,6 +83,7 @@ THIRD_PARTY_APPS = [
# crud & forms
'tapeforms',
'django_tables2',
'django_filters',
'cruditor',
'docs',
]


+ 7
- 0
benevalibre/templates/association/association_list.html View File

@@ -1,4 +1,11 @@
{% extends "base.html" %}
{% load tapeforms %}

{% block titlebuttons %}
<div class="title-buttons ml-3 mt-2">
{% form filter.form %}
</div>
{% endblock %}

{% block content %}
{% if not object_list and not can_add_association %}


+ 12
- 0
benevalibre/templates/association/forms/fields/search.html View File

@@ -0,0 +1,12 @@
{% extends "tapeforms/fields/bootstrap.html" %}

{% block widget %}
<div class="input-group">
{{ field }}
<div class="input-group-append mr-3">
<button class="btn btn-outline-primary fa fa-search" type="button" id="button-addon"></button>
</div>
</div>
{% endblock %}

{% block errors %}{% endblock %}

+ 7
- 5
benevalibre/templates/base.html View File

@@ -50,11 +50,13 @@
{% endif %}
</div>
<div class="col-sm-auto text-right">
{% if page.titlebuttons %}
<div class="title-buttons ml-3 mt-2">
{% include "includes/buttons.html" with buttons=page.titlebuttons %}
</div>
{% endif %}
{% block titlebuttons %}
{% if page.titlebuttons %}
<div class="title-buttons ml-3 mt-2">
{% include "includes/buttons.html" with buttons=page.titlebuttons %}
</div>
{% endif %}
{% endblock %}
</div>
</div>
</div>


+ 1
- 0
requirements/base.txt View File

@@ -16,6 +16,7 @@ django-stdimage >=4.1,<4.2 # https://github.com/codingjoe/django-stdimage
django-tables2 # https://github.com/jieter/django-tables2
django-tapeforms >=0.2,<0.3 # https://github.com/stephrdev/django-tapeforms
django-cruditor >=1.3,<1.4 # https://github.com/moccu/django-cruditor
django-filter >=2.2,<2.3 # https://github.com/carltongibson/django-filter

# Documentation
# ------------------------------------------------------------------------------


Loading…
Cancel
Save