]> git.parisson.com Git - mezzo.git/commitdiff
Search: cleaning
authorEmilie <zawadzki@ircam.fr>
Fri, 14 Oct 2016 10:52:52 +0000 (12:52 +0200)
committerEmilie <zawadzki@ircam.fr>
Fri, 14 Oct 2016 10:52:52 +0000 (12:52 +0200)
app/local_settings.py
app/organization/core/managers.py
app/organization/pages/models.py

index 9d4386cbf70725a8c6779fc9da37a632a1ce7a5f..3239f2d915e785f3a23029bdce3556acfc8b0401 100644 (file)
@@ -143,7 +143,7 @@ PAGES_MODELS = ('organization-pages.CustomPage',
                 'organization-network.DepartmentPage',
                 'organization-network.TeamPage',
                 'organization-projects.ProjectTopicPage',
-                'organization-pages.PageLink')
+                )
 
 SEARCH_PER_PAGE = 10
 MAX_PAGING_LINKS = 10
index b16ae9dbf350676f80b52bc01f7474b15fd225d1..92a60caf901f488fdfedea67c29431aa2aefef0b 100644 (file)
@@ -19,65 +19,9 @@ from django.utils.translation import ugettext_lazy as _
 from mezzanine.conf import settings
 from mezzanine.utils.sites import current_site_id
 from mezzanine.utils.urls import home_slug
-from mezzanine.core.managers import search_fields_to_dict, SearchableQuerySet
+from mezzanine.core.managers import search_fields_to_dict, SearchableQuerySet, SearchableManager
 
-class CustomSearchableManager(Manager):
-
-    """
-    Manager providing a chainable queryset.
-    Adapted from http://www.djangosnippets.org/snippets/562/
-    search method supports spanning across models that subclass the
-    model being used to search.
-    """
-
-    def __init__(self, *args, **kwargs):
-        self._search_fields = kwargs.pop("search_fields", {})
-        super(CustomSearchableManager, self).__init__(*args, **kwargs)
-
-    def get_search_fields(self):
-        """
-        Returns the search field names mapped to weights as a dict.s
-        Used in ``get_queryset`` below to tell ``SearchableQuerySet``
-        which search fields to use. Also used by ``DisplayableAdmin``
-        to populate Django admin's ``search_fields`` attribute.
-        Search fields can be populated via
-        ``SearchableManager.__init__``, which then get stored in
-        ``SearchableManager._search_fields``, which serves as an
-        approach for defining an explicit set of fields to be used.
-        Alternatively and more commonly, ``search_fields`` can be
-        defined on models themselves. In this case, we look at the
-        model and all its base classes, and build up the search
-        fields from all of those, so the search fields are implicitly
-        built up from the inheritence chain.
-        Finally if no search fields have been defined at all, we
-        fall back to any fields that are ``CharField`` or ``TextField``
-        instances.
-        """
-        search_fields = self._search_fields.copy()
-        if not search_fields:
-            for cls in reversed(self.model.__mro__):
-                super_fields = getattr(cls, "search_fields", {})
-                search_fields.update(search_fields_to_dict(super_fields))
-        if not search_fields:
-            search_fields = []
-            for f in self.model._meta.fields:
-                if isinstance(f, (CharField, TextField)):
-                    search_fields.append(f.name)
-            search_fields = search_fields_to_dict(search_fields)
-        return search_fields
-
-    def get_queryset(self):
-        search_fields = self.get_search_fields()
-        return SearchableQuerySet(self.model, search_fields=search_fields)
-
-    def contribute_to_class(self, model, name):
-        """
-        Newer versions of Django explicitly prevent managers being
-        accessed from abstract classes, which is behaviour the search
-        API has always relied on. Here we reinstate it.
-        """
-        super(CustomSearchableManager, self).contribute_to_class(model, name)
-        setattr(model, name, ManagerDescriptor(self))
+class CustomSearchableManager(SearchableManager):
 
     def search(self, *args, **kwargs):
         """
index f38143f27d1d9bcb84b3c7c24857e6bf1a7f1791..d301a5ceede05320b8baab84eeb23fb866333234 100644 (file)
@@ -59,7 +59,6 @@ class PageVideo(Video):
 class PageLink(Link):
 
     page = models.ForeignKey(Page, verbose_name=_('page'), related_name='links', blank=True, null=True, on_delete=models.SET_NULL)
-    objects = CustomSearchableManager()
     
     class Meta:
         verbose_name = _("link")