Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added search interface function for page search @see PageManager.sear…

…ch(...)
  • Loading branch information...
commit 390b012e953efdda977e7bc47a83bb21ff0a66bf 1 parent 858775b
@pcicman pcicman authored
Showing with 45 additions and 5 deletions.
  1. +6 −5 cms/appresolver.py
  2. +39 −0 cms/models/managers.py
View
11 cms/appresolver.py
@@ -1,5 +1,5 @@
from django.conf import settings
-from cms.settings import CMS_FLAT_URLS
+from cms import settings as cms_settings
from django.core.urlresolvers import RegexURLResolver, Resolver404, reverse
from cms.utils.moderator import get_page_queryset
from cms.models import Page
@@ -93,7 +93,8 @@ def __init__(self, title, default_kwargs={}):
# will they be be than passed to pattern, and from pattern to view?
# If it will work, will be give us possibility to configure one
# application for multiple hooks.
- if CMS_FLAT_URLS:
+
+ if cms_settings.CMS_FLAT_URLS:
regex = r'^%s' % title.slug
else:
regex = r'^%s' % title.path
@@ -126,18 +127,18 @@ def urlpatterns(self):
Caches result, so db lookup is required only once, or when the cache
is reseted.
"""
+
if not self._urlpatterns:
# TODO: will this work with multiple sites? how are they exactly
# implemented ?
# probably will be better to make caching per site
self._urlpatterns, included = [], []
-
# we don't have a request here so get_page_queryset() can't be used,
# so, if CMS_MODERATOR, use, public() queryset, otherwise
# use draft(). This can be done, because url patterns are used just
# in frontend
- if getattr(settings, "CMS_MODERATOR", False):
+ if cms_settings.CMS_MODERATOR:
pages = Page.objects.public()
else:
pages = Page.objects.drafts()
@@ -146,7 +147,7 @@ def urlpatterns(self):
# get all titles with application
title_set = page.title_set.filter(application_urls__gt="")
for title in title_set:
- if CMS_FLAT_URLS:
+ if cms_settings.CMS_FLAT_URLS:
mixid = "%s:%s" % (title.slug + "/", title.application_urls)
else:
mixid = "%s:%s" % (title.path + "/", title.application_urls)
View
39 cms/models/managers.py
@@ -89,7 +89,46 @@ def get_all_pages_with_application(self):
def get_home(self, site=None):
return self.get_query_set().get_home(site)
+
+ def search(self, q, language=None, current_site_only=True):
+ """Simple search function
+
+ NOTE:For future may be better if every plugin defines Q object relative
+ to page, and search function just takes them. This will give us
+ posibillity to search over custom plugins.
+ """
+ qs = self.public()
+
+ if current_site_only:
+ site = Site.objects.get_current()
+ qs = qs.filter(site=site)
+
+ qt = Q(title_set__title__icontains=q)
+
+ plugins = (
+ ('cms.plugins.text', Q(cmsplugin__text__body__icontains=q)),
+ ('cms.plugins.file', Q(cmsplugin__file__title__icontains=q)),
+ ('cms.plugins.snippet', Q(cmsplugin__snippetptr__snippet__html__icontains=q)),
+ ('cms.plugins.link', Q(cmsplugin__link__name__icontains=q)),
+ ('cms.plugins.teaser', Q(cmsplugin__teaser__description__icontains=q)),
+ )
+
+ qp = Q()
+ # build plugin query depending on installed plugins
+ for app_name, q in plugins:
+ if not app_name in settings.INSTALLED_APPS:
+ continue
+ qp |= q
+
+ if language:
+ qt &= Q(title_set__language=language)
+ qp &= Q(cmsplugin__language=language)
+
+ qs = qs.filter(qt | qp)
+ return qs.distinct()
+
+
class TitleManager(PublisherManager):
def get_title(self, page, language, language_fallback=False, latest_by='creation_date'):
Please sign in to comment.
Something went wrong with that request. Please try again.