diff --git a/petitscours/autocomplete.py b/petitscours/autocomplete.py new file mode 100644 index 00000000..9377dc51 --- /dev/null +++ b/petitscours/autocomplete.py @@ -0,0 +1,43 @@ +from django.db.models import Q +from django.urls import reverse +from django.utils.translation import gettext_lazy as _ + +from petitscours.models import PetitCoursDemande +from shared import autocomplete + +class DemandeSearch(autocomplete.ModelSearch): + """ + Classe fille de Modelsearch qui recherche les requêtes selon qu'elles soient traitées ou non + """ + model = PetitCoursDemande + search_fields = [ "name", "email", "phone"] + + def __init__(self, processed, *args, **kwargs): + super().__init__(*args, **kwargs) + self.processed = processed + if processed: + self.verbose_name = _("Demandes traitées") + else: + self.verbose_name = _("Demandes non traitées") + + def get_queryset_filter(self, *args, **kwargs): + qset_filter = super().get_queryset_filter(*args, **kwargs) + qset_filter &= Q(traitee=self.processed) + return qset_filter + + def result_verbose_name(self, result): + return f"{result.name}, {result.created.strftime('%d/%m/%Y')}" + + def result_link(self, demande): + return reverse("petits-cours-demande-details", args=(demande.pk,)) + + + +class DemandeAutocomplete(autocomplete.Compose): + search_units = [ + ("not processed", DemandeSearch(False)), + ("processed", DemandeSearch(True)), + ] + + +demande_autocomplete = DemandeAutocomplete() diff --git a/petitscours/templates/petitscours/demande_list.html b/petitscours/templates/petitscours/demande_list.html index e4c3c782..69440fec 100644 --- a/petitscours/templates/petitscours/demande_list.html +++ b/petitscours/templates/petitscours/demande_list.html @@ -1,8 +1,13 @@ {% extends "petitscours/base_title.html" %} {% load staticfiles %} +{% block extra_head %} + +{% endblock %} + {% block realcontent %} -