From ef4194eba5259b85740a1ad461eac7fcfc49ecac Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Tue, 7 Jan 2020 01:56:32 +0100 Subject: [PATCH] Remove unmaintained haystack plugin --- docs/release_notes.rst | 2 +- src/wiki/plugins/haystack/README.md | 13 ---- src/wiki/plugins/haystack/__init__.py | 61 ------------------- src/wiki/plugins/haystack/search_indexes.py | 24 -------- .../search/indexes/wiki/article_text.txt | 2 - .../wiki/plugins/haystack/search.html | 7 --- src/wiki/plugins/haystack/views.py | 32 ---------- testproject/testproject/settings/haystack.py | 32 ---------- 8 files changed, 1 insertion(+), 172 deletions(-) delete mode 100644 src/wiki/plugins/haystack/README.md delete mode 100644 src/wiki/plugins/haystack/__init__.py delete mode 100644 src/wiki/plugins/haystack/search_indexes.py delete mode 100644 src/wiki/plugins/haystack/templates/search/indexes/wiki/article_text.txt delete mode 100644 src/wiki/plugins/haystack/templates/wiki/plugins/haystack/search.html delete mode 100644 src/wiki/plugins/haystack/views.py delete mode 100644 testproject/testproject/settings/haystack.py diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 79c1b8d1..cc89c2c5 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -37,7 +37,7 @@ Removed ~~~~~~~ * Python 3.4 support more or less definitively removed (no longer supported by test suite PyTest) - +* Removed unmaintained plugin ``wiki.plugins.haystack`` 0.5 --- diff --git a/src/wiki/plugins/haystack/README.md b/src/wiki/plugins/haystack/README.md deleted file mode 100644 index b82e3ba5..00000000 --- a/src/wiki/plugins/haystack/README.md +++ /dev/null @@ -1,13 +0,0 @@ -Haystack plugin -=============== - -***July 16 2013*** -Tested backend, xapian with Haystack 2.0. NB! Get the xapian from Git - -https://github.com/notanumber/xapian-haystack - -Not working ------------ - -Do not use Whoosh, it has broken SearchQuerySet support and therefore will leak -articles that are set non-public. diff --git a/src/wiki/plugins/haystack/__init__.py b/src/wiki/plugins/haystack/__init__.py deleted file mode 100644 index 10e233e2..00000000 --- a/src/wiki/plugins/haystack/__init__.py +++ /dev/null @@ -1,61 +0,0 @@ -from django.db.models import Q -from django.shortcuts import redirect -from django.utils.decorators import classonlymethod -from haystack import views as haystack_views -from wiki import models -from wiki.conf import settings -from wiki.core import permissions - - -class SearchViewHaystack(haystack_views.SearchView): - results_per_page = 25 - template = "search/search.html" - - def __name__(self): # @ReservedAssignment - return "SearchViewHaystack" - - @classonlymethod - def as_view(cls, *args, **kwargs): - return haystack_views.search_view_factory(view_class=cls, *args, **kwargs) - - def dispatch(self, request, *args, **kwargs): - # Do not allow anonymous users to search if they cannot read content - if request.user.is_anonymous and not settings.ANONYMOUS: - return redirect(settings.LOGIN_URL) - return super().dispatch(request, *args, **kwargs) - - def __filter_can_read(self, user): - """Filter objects so only the ones with a user's reading access - are included""" - if user.has_perm('wiki.moderator'): - return self.results - if user.is_anonymous: - q = self.results.filter(other_read='True') - return q - else: - q = self.results.filter( - Q(other_read=True) | - Q(owner=user) | - (Q(group__user=user) & Q(group_read=True)) - ) - return q - - def __call__(self, request): - self.request = request - if self.request.user.is_anonymous and not settings.ANONYMOUS: - return redirect(settings.LOGIN_URL) - - self.form = self.build_form() - self.query = self.get_query() - self.results = self.get_results() - if not permissions.can_moderate( - models.URLPath.root().article, - self.request.user): - self.results = self.__filter_can_read(self.request.user) - - return self.create_response() - - def extra_context(self): - extra = super().extra_context() - extra['search_query'] = self.query - return extra diff --git a/src/wiki/plugins/haystack/search_indexes.py b/src/wiki/plugins/haystack/search_indexes.py deleted file mode 100644 index 085cedc9..00000000 --- a/src/wiki/plugins/haystack/search_indexes.py +++ /dev/null @@ -1,24 +0,0 @@ -from haystack import indexes -from wiki import models - - -class ArticleIndex(indexes.SearchIndex, indexes.Indexable): - text = indexes.CharField(document=True, use_template=True) - created = indexes.DateTimeField(model_attr='created') - modified = indexes.DateTimeField(model_attr='modified') - - # default because indexing fails with whoosh. see. - # http://stackoverflow.com/questions/11995367/how-do-i-use-a-boolean-field-in-django-haystack-search-query - # https://github.com/toastdriven/django-haystack/issues/382 - other_read = indexes.BooleanField(model_attr='other_read', default=False) - group_read = indexes.BooleanField(model_attr='group_read', default=False) - - owner_id = indexes.IntegerField(model_attr='owner__id', null=True) - group_id = indexes.IntegerField(model_attr='group__id', null=True) - - def get_model(self): - return models.Article - - def index_queryset(self, using=None): - """Used when the entire index for model is updated.""" - return self.get_model().objects.all() diff --git a/src/wiki/plugins/haystack/templates/search/indexes/wiki/article_text.txt b/src/wiki/plugins/haystack/templates/search/indexes/wiki/article_text.txt deleted file mode 100644 index 8ed6633d..00000000 --- a/src/wiki/plugins/haystack/templates/search/indexes/wiki/article_text.txt +++ /dev/null @@ -1,2 +0,0 @@ -{{ object.current_revision.title }} -{{ object.render|striptags }} diff --git a/src/wiki/plugins/haystack/templates/wiki/plugins/haystack/search.html b/src/wiki/plugins/haystack/templates/wiki/plugins/haystack/search.html deleted file mode 100644 index d758e4af..00000000 --- a/src/wiki/plugins/haystack/templates/wiki/plugins/haystack/search.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "wiki/search.html" %} - -{% block wiki_search_loop %} -{% with article.object as article %} -{% include "wiki/includes/searchresult.html" %} -{% endwith %} -{% endblock %} diff --git a/src/wiki/plugins/haystack/views.py b/src/wiki/plugins/haystack/views.py deleted file mode 100644 index 97327340..00000000 --- a/src/wiki/plugins/haystack/views.py +++ /dev/null @@ -1,32 +0,0 @@ -from haystack.backends import SQ -from haystack.inputs import AutoQuery -from haystack.query import SearchQuerySet -from wiki import models -from wiki.core import permissions -from wiki.views.article import SearchView - - -class HaystackSearchView(SearchView): - - template_name = 'wiki/plugins/haystack/search.html' - - def get_queryset(self): - qs = SearchQuerySet().all() - if self.request.user.is_authenticated: - if not permissions.can_moderate( - models.URLPath.root().article, - self.request.user): - qs = qs.filter( - SQ(owner_id=self.request.user.id) | - ( - SQ(group_id__in=self.request.user.groups.values_list('id', flat=True)) & - SQ(group_read=True) - ) | - SQ(other_read=True) - ) - else: - qs = qs.exclude(other_read=False) - - qs = qs.filter(content=AutoQuery(self.query)) - qs = qs.load_all() - return qs diff --git a/testproject/testproject/settings/haystack.py b/testproject/testproject/settings/haystack.py deleted file mode 100644 index 3fc578ed..00000000 --- a/testproject/testproject/settings/haystack.py +++ /dev/null @@ -1,32 +0,0 @@ -from .base import * # noqa @UnusedWildImport - -# Django Haystack - -HAYSTACK_WHOOSH_PATH = os.path.join(PROJECT_DIR, 'index_woosh') - -INSTALLED_APPS += ['haystack', 'wiki.plugins.haystack'] - -HAYSTACK_CONNECTIONS = { - 'default': { - 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', - }, -} - - -HAYSTACK_CONNECTIONS = { - 'default': { - 'ENGINE': 'xapian_backend.XapianEngine', - 'PATH': os.path.join(PROJECT_DIR, 'xapian_index'), - }, -} - -# Whoosh backend is completely broken -# https://github.com/toastdriven/django-haystack/issues/522 -# https://github.com/toastdriven/django-haystack/issues/382 -# https://github.com/toastdriven/django-haystack/issues/447 -# HAYSTACK_CONNECTIONS = { -# 'default': { -# 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', -# 'PATH': os.path.join(PROJECT_PATH, 'whoosh_index'), -# }, -# } -- 2.45.2