From: Emilie Date: Wed, 23 Nov 2016 17:54:41 +0000 (+0100) Subject: Autocomplete : add event info while searching : is_parent + date X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=308ce1ea2fb330904f7c1583c1dc749c2aafabee;p=mezzo.git Autocomplete : add event info while searching : is_parent + date --- diff --git a/app/local_settings.py b/app/local_settings.py index 763359f6..0fe59bd7 100644 --- a/app/local_settings.py +++ b/app/local_settings.py @@ -167,6 +167,7 @@ PAGES_PUBLISHED_INCLUDE_LOGIN_REQUIRED = True SEARCH_PER_PAGE = 10 MAX_PAGING_LINKS = 10 +DAL_MAX_RESULTS = 20 RATINGS_ACCOUNT_REQUIRED = True diff --git a/app/organization/agenda/views.py b/app/organization/agenda/views.py index acaddea1..3482cb68 100644 --- a/app/organization/agenda/views.py +++ b/app/organization/agenda/views.py @@ -5,6 +5,7 @@ from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView from organization.magazine.models import Article from organization.pages.models import CustomPage from mezzanine_agenda.models import Event +from organization.core.views import autocomplete_result_formatting class ConfirmationView(TemplateView): @@ -18,6 +19,8 @@ class ConfirmationView(TemplateView): class DynamicContentEventView(Select2QuerySetSequenceView): + paginate_by = settings.DAL_MAX_RESULTS + def get_queryset(self): articles = Article.objects.all() @@ -37,3 +40,7 @@ class DynamicContentEventView(Select2QuerySetSequenceView): qs = self.mixup_querysets(qs) return qs + + def get_results(self, context): + results = autocomplete_result_formatting(self, context) + return results diff --git a/app/organization/core/views.py b/app/organization/core/views.py index 19b750da..785075a0 100644 --- a/app/organization/core/views.py +++ b/app/organization/core/views.py @@ -3,8 +3,10 @@ from django.http import Http404 from django.views.generic.base import View from django.views.generic import DetailView, ListView, TemplateView from django.apps import apps +from django.utils import six, timezone, formats from django.utils.translation import ugettext_lazy as _ from django.http import QueryDict +from django.template.defaultfilters import capfirst from mezzanine.conf import settings from mezzanine.utils.views import paginate from organization.core.models import * @@ -133,3 +135,42 @@ class CustomSearchView(TemplateView): context['filter_dict'] = filter_dict # context.update(extra_context or {}) return self.render_to_response(context) + + +def autocomplete_result_formatting(self, context): + """ + Return a list of results usable by Select2. + It will render as a list of one per different content type + containing a list of one