SEARCH_PER_PAGE = 10
MAX_PAGING_LINKS = 10
+DAL_MAX_RESULTS = 20
RATINGS_ACCOUNT_REQUIRED = True
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):
class DynamicContentEventView(Select2QuerySetSequenceView):
+ paginate_by = settings.DAL_MAX_RESULTS
+
def get_queryset(self):
articles = Article.objects.all()
qs = self.mixup_querysets(qs)
return qs
+
+ def get_results(self, context):
+ results = autocomplete_result_formatting(self, context)
+ return results
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 *
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 <optgroup> per different content type
+ containing a list of one <option> per model.
+ """
+ groups = {}
+
+ for result in context['object_list']:
+ groups.setdefault(type(result), [])
+ groups[type(result)].append(result)
+
+ all_results = []
+ for model, results in groups.items():
+ children = []
+ for result in results:
+ text = six.text_type(result)
+ if model._meta.verbose_name == "Event":
+ event_date = timezone.localtime(result.start)
+ is_parent = ""
+ if not result.parent:
+ is_parent = " ♦ -"
+ text = "%s -%s%s" % (six.text_type(result), is_parent, formats.date_format(event_date, "d-m-y H:i"))
+
+ children.append({
+ 'id': self.get_result_value(result),
+ 'text': text,
+ })
+
+ curr_model_result = {
+ 'id': None,
+ 'text': capfirst(model._meta.verbose_name),
+ 'children': children
+ }
+ all_results.append(curr_model_result)
+
+ return all_results
from organization.magazine.models import *
from organization.network.models import DepartmentPage
from organization.pages.models import CustomPage, DynamicContentPage
-from organization.core.views import SlugMixin
+from organization.core.views import SlugMixin, autocomplete_result_formatting
from django.template.defaultfilters import slugify
class ObjectAutocomplete(Select2QuerySetSequenceView):
+
+ paginate_by = settings.DAL_MAX_RESULTS
+
def get_queryset(self):
articles = Article.objects.all()
return qs
+ def get_results(self, context):
+ results = autocomplete_result_formatting(self, context)
+ return results
+
class DynamicContentArticleView(Select2QuerySetSequenceView):
+
+ paginate_by = settings.DAL_MAX_RESULTS
+
def get_queryset(self):
articles = Article.objects.all()
qs = self.mixup_querysets(qs)
return qs
+
+ def get_results(self, context):
+ results = autocomplete_result_formatting(self, context)
+ return results
from organization.media.models import *
from organization.core.views import *
from dal import autocomplete
-from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView
from django.core.exceptions import FieldDoesNotExist
# temporarily excluse not ready models
from django.shortcuts import render
from dal import autocomplete
-from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView
from organization.network.models import *
from organization.core.views import *
from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView
from django.core.urlresolvers import reverse, reverse_lazy
from django.utils.translation import ugettext_lazy as _
+from mezzanine.conf import settings
from organization.pages.models import CustomPage
-from organization.core.views import SlugMixin
+from organization.core.views import SlugMixin, autocomplete_result_formatting
from organization.magazine.models import Article, Topic, Brief
from organization.pages.models import Home
from organization.agenda.models import Event
from organization.media.models import Playlist
-
class HomeView(SlugMixin, ListView):
model = Home
return qs
+ def get_results(self, context):
+ results = autocomplete_result_formatting(self, context)
+ return results
+
class DynamicContentHomeBodyView(Select2QuerySetSequenceView):
+ paginate_by = settings.DAL_MAX_RESULTS
+
def get_queryset(self):
articles = Article.objects.all()
return qs
+ def get_results(self, context):
+ results = autocomplete_result_formatting(self, context)
+ return results
+
+
class DynamicContentHomeMediaView(Select2QuerySetSequenceView):
def get_queryset(self):
qs = self.mixup_querysets(qs)
return qs
+
+ def get_results(self, context):
+ results = autocomplete_result_formatting(self, context)
+ return results
from django.shortcuts import render
from dal import autocomplete
from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView
+from mezzanine_agenda.models import Event
+from mezzanine.conf import settings
from organization.projects.models import *
from organization.core.views import *
from organization.magazine.views import Article
-from mezzanine_agenda.models import Event
from organization.pages.models import CustomPage
-
class ProjectDetailView(SlugMixin, DetailView):
model = Project
class DynamicContentProjectView(Select2QuerySetSequenceView):
+ paginate_by = settings.DAL_MAX_RESULTS
+
def get_queryset(self):
articles = Article.objects.all()
return qs
+ def get_results(self, context):
+ results = autocomplete_result_formatting(self, context)
+ return results
+
class ProjectDemoDetailView(SlugMixin, DetailView):
padding: 20px;
background: yellow;
}
+
+.select2-container {
+ min-width: 70em;
+}