Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update to search API changes in PyLucid:

  • Loading branch information...
commit c2b57b049bd8ac67ca026ae679b8f8b65bd6d710 1 parent af3c2ba
@jedie authored
Showing with 32 additions and 28 deletions.
  1. +32 −28 djangobb_plugin/search.py
View
60 djangobb_plugin/search.py
@@ -16,45 +16,49 @@
from pylucid_project.apps.pylucid.models.pluginpage import PluginPage
-def get_search_results(request, search_languages, search_strings, search_results):
- groups = request.user.groups.all() or []
- queryset = Post.objects.all()
- queryset = queryset.filter(
- Q(topic__forum__category__groups__in=groups) | Q(topic__forum__category__groups__isnull=True)
- )
+class Search(object):
+ def get_queryset(self, request, search_languages, search_strings):
+ groups = request.user.groups.all() or []
- for term in search_strings:
+ queryset = Post.objects.all()
queryset = queryset.filter(
- Q(body__icontains=term) | Q(topic__name__icontains=term)
+ Q(topic__forum__category__groups__in=groups) | Q(topic__forum__category__groups__isnull=True)
)
- # TODO: How can we resolve the url better?
- plugin_page = PluginPage.objects.get_by_plugin_name("djangobb_plugin")
- base_url = plugin_page.get_absolute_url()
+ for term in search_strings:
+ queryset = queryset.filter(
+ Q(body__icontains=term) | Q(topic__name__icontains=term)
+ )
+ return queryset
- # FIXME: This doesn't work:
-# plugin_url_resolver = PluginPage.objects.get_url_resolver("djangobb_plugin")
-
- for item in queryset:
+ def add_search_results(self, request, queryset, search_results):
+ # TODO: How can we resolve the url better?
+ plugin_page = PluginPage.objects.get_by_plugin_name("djangobb_plugin")
+ base_url = plugin_page.get_absolute_url()
# FIXME: This doesn't work:
-# url = plugin_url_resolver.reverse("djangobb:post", kwargs={"post_id":item.id})
+ # plugin_url_resolver = PluginPage.objects.get_url_resolver("djangobb_plugin")
- search_results.add(
- model_instance=item,
+ for item in queryset:
- # displayed headline of the result hit
- headline=item.topic.name,
+ # FIXME: This doesn't work:
+ # url = plugin_url_resolver.reverse("djangobb:post", kwargs={"post_id":item.id})
- # displayed in the result list
- language=request.PYLUCID.current_language,
+ search_results.add(
+ model_instance=item,
- # Link to the hit
- url="%spost/%s/" % (base_url, item.id),
+ # displayed headline of the result hit
+ headline=item.topic.name,
- content=item.body_html,
+ # displayed in the result list
+ language=request.PYLUCID.current_language,
- # hits in meta content has a higher score, but the content would not displayed
- meta_content="",
- )
+ # Link to the hit
+ url="%spost/%s/" % (base_url, item.id),
+
+ content=item.body_html,
+
+ # hits in meta content has a higher score, but the content would not displayed
+ meta_content="",
+ )
Please sign in to comment.
Something went wrong with that request. Please try again.