Skip to content
Permalink
Browse files

Disable search until we can get ES going again.

  • Loading branch information
nicksergeant committed Jan 31, 2019
1 parent 8c8e943 commit 59f86ae040a16ca92a25272069bd03b6dd31d9fa
Showing with 131 additions and 129 deletions.
  1. +1 βˆ’0 media/css/style.css
  2. +1 βˆ’0 media/css/style.scss
  3. +9 βˆ’9 settings.py
  4. +8 βˆ’8 snipts/api.py
  5. +14 βˆ’14 snipts/search_indexes.py
  6. +83 βˆ’83 snipts/views.py
  7. +10 βˆ’10 templates/base.html
  8. +3 βˆ’3 templates/homepage.html
  9. +2 βˆ’2 urls.py
@@ -55,6 +55,7 @@ header.main div.inner div.shadey {
background: transparent url("../img/header-inner-bg.png") top left no-repeat;
height: 65px;
left: -157px;
pointer-events: none;
position: absolute;
top: 0;
width: 432px;
@@ -126,6 +126,7 @@ header.main {
background: transparent url('../img/header-inner-bg.png') top left no-repeat;
height: 65px;
left: -157px;
pointer-events: none;
position: absolute;
top: 0;
width: 432px;
@@ -18,14 +18,14 @@
DEBUG = True if "DEBUG" in os.environ else False
DEFAULT_FROM_EMAIL = os.environ.get("POSTMARK_EMAIL", "support@siftie.com")
EMAIL_BACKEND = "postmark.django_backend.EmailBackend"
HAYSTACK_CONNECTIONS = {
"default": {
"ENGINE": "haystack.backends.whoosh_backend.WhooshEngine",
"PATH": os.environ.get("WHOOSH_PATH", "./.whoosh_index"),
"STORAGE": "file",
}
}
HAYSTACK_SIGNAL_PROCESSOR = "haystack.signals.RealtimeSignalProcessor"
# HAYSTACK_CONNECTIONS = {
# "default": {
# "ENGINE": "haystack.backends.whoosh_backend.WhooshEngine",
# "PATH": os.environ.get("WHOOSH_PATH", "./.whoosh_index"),
# "STORAGE": "file",
# }
# }
# HAYSTACK_SIGNAL_PROCESSOR = "haystack.signals.RealtimeSignalProcessor"
INTERNAL_IPS = ("127.0.0.1",)
LANGUAGE_CODE = "en-us"
LOGIN_REDIRECT_URL = "/login-redirect/"
@@ -105,7 +105,7 @@
"django.contrib.staticfiles",
"django_extensions",
"gunicorn",
"haystack",
# "haystack",
"markdown_deux",
"pagination",
"postmark",
@@ -10,7 +10,7 @@
from django.contrib.auth.models import User
from django.db import models
from django.template.defaultfilters import date, urlize, linebreaksbr
from haystack.query import SearchQuerySet
# from haystack.query import SearchQuerySet
from snipts.models import Favorite, Snipt
from taggit.models import Tag
from taggit.utils import edit_string_for_tags, parse_tags
@@ -294,9 +294,9 @@ def build_filters(self, filters=None, **kwargs):
tagged_items = tag.taggit_taggeditem_items.all()
orm_filters["pk__in"] = [i.object_id for i in tagged_items]

if "q" in filters:
sqs = SearchQuerySet().auto_query(filters["q"])
orm_filters["pk__in"] = [i.pk for i in sqs]
# if "q" in filters:
# sqs = SearchQuerySet().auto_query(filters["q"])
# orm_filters["pk__in"] = [i.pk for i in sqs]

return orm_filters

@@ -520,10 +520,10 @@ def build_filters(self, filters=None, **kwargs):
tagged_items = tag.taggit_taggeditem_items.all()
orm_filters["pk__in"] = [i.object_id for i in tagged_items]

if "q" in filters:
user = User.objects.get(username=filters["username"])
sqs = SearchQuerySet().filter(author=user, content=filters["q"])
orm_filters["pk__in"] = [i.pk for i in sqs]
# if "q" in filters:
# user = User.objects.get(username=filters["username"])
# sqs = SearchQuerySet().filter(author=user, content=filters["q"])
# orm_filters["pk__in"] = [i.pk for i in sqs]

return orm_filters

@@ -1,19 +1,19 @@
import datetime
# import datetime

from haystack import indexes
from snipts.models import Snipt
# from haystack import indexes
# from snipts.models import Snipt


class SniptIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
author = indexes.CharField(model_attr="user")
pub_date = indexes.DateTimeField(model_attr="created")
public = indexes.BooleanField(model_attr="public")
typ = indexes.CharField(model_attr="lexer")
# class SniptIndex(indexes.SearchIndex, indexes.Indexable):
# text = indexes.CharField(document=True, use_template=True)
# author = indexes.CharField(model_attr="user")
# pub_date = indexes.DateTimeField(model_attr="created")
# public = indexes.BooleanField(model_attr="public")
# typ = indexes.CharField(model_attr="lexer")

def get_model(self):
return Snipt
# def get_model(self):
# return Snipt

def index_queryset(self, **kwargs):
"""Used when the entire index for model is updated."""
return self.get_model().objects.filter(created__lte=datetime.datetime.now())
# def index_queryset(self, **kwargs):
# """Used when the entire index for model is updated."""
# return self.get_model().objects.filter(created__lte=datetime.datetime.now())
@@ -16,8 +16,8 @@
from django.shortcuts import get_object_or_404, render
from django.template import RequestContext
from django.views.decorators.cache import never_cache
from haystack.forms import ModelSearchForm
from haystack.query import EmptySearchQuerySet, SearchQuerySet
# from haystack.forms import ModelSearchForm
# from haystack.query import EmptySearchQuerySet, SearchQuerySet
from pygments.lexers import get_lexer_by_name
from snipts.models import Favorite, Snipt, SniptSecureView
from taggit.models import Tag
@@ -26,7 +26,7 @@
import os


RESULTS_PER_PAGE = getattr(settings, "HAYSTACK_SEARCH_RESULTS_PER_PAGE", 20)
# RESULTS_PER_PAGE = getattr(settings, "HAYSTACK_SEARCH_RESULTS_PER_PAGE", 20)


@render_to("snipts/detail.html")
@@ -290,86 +290,86 @@ def rss(request, context):
return render(request, "rss.xml", context, content_type="application/rss+xml")


@never_cache
def search(
request,
template="search/search.html",
load_all=True,
form_class=ModelSearchForm,
searchqueryset=None,
context_class=RequestContext,
extra_context=None,
results_per_page=None,
):

query = ""
results = EmptySearchQuerySet()

if request.GET.get("q"):

searchqueryset = (
SearchQuerySet()
.filter(Q(public=True) | Q(author=request.user))
.order_by("-pub_date")
)

if request.user.is_authenticated() and "mine-only" in request.GET:
searchqueryset = (
SearchQuerySet().filter(author=request.user).order_by("-pub_date")
)

elif request.user.is_authenticated() and (
"author" in request.GET and request.GET.get("author")
):

author = request.GET.get("author")

if author == request.user.username:
searchqueryset = (
SearchQuerySet().filter(author=request.user).order_by("-pub_date")
)

else:
team = get_object_or_None(Team, slug=author)

if team and team.user_is_member(request.user):
searchqueryset = (
SearchQuerySet().filter(author=team).order_by("-pub_date")
)

form = ModelSearchForm(
request.GET, searchqueryset=searchqueryset, load_all=load_all
)

if form.is_valid():
query = form.cleaned_data["q"]
results = form.search()
else:
form = form_class(searchqueryset=searchqueryset, load_all=load_all)

paginator = Paginator(results, results_per_page or RESULTS_PER_PAGE)

try:
page = paginator.page(int(request.GET.get("page", 1)))
except InvalidPage:
raise Http404("No such page of results!")

context = {
"form": form,
"has_snipts": True,
"page": page,
"paginator": paginator,
"query": query,
"suggestion": None,
}

if results.query.backend.include_spelling:
context["suggestion"] = form.get_suggestion()

if extra_context:
context.update(extra_context)

return render(request, template, context)
# @never_cache
# def search(
# request,
# template="search/search.html",
# load_all=True,
# form_class=ModelSearchForm,
# searchqueryset=None,
# context_class=RequestContext,
# extra_context=None,
# results_per_page=None,
# ):

# query = ""
# results = EmptySearchQuerySet()

# if request.GET.get("q"):

# searchqueryset = (
# SearchQuerySet()
# .filter(Q(public=True) | Q(author=request.user))
# .order_by("-pub_date")
# )

# if request.user.is_authenticated() and "mine-only" in request.GET:
# searchqueryset = (
# SearchQuerySet().filter(author=request.user).order_by("-pub_date")
# )

# elif request.user.is_authenticated() and (
# "author" in request.GET and request.GET.get("author")
# ):

# author = request.GET.get("author")

# if author == request.user.username:
# searchqueryset = (
# SearchQuerySet().filter(author=request.user).order_by("-pub_date")
# )

# else:
# team = get_object_or_None(Team, slug=author)

# if team and team.user_is_member(request.user):
# searchqueryset = (
# SearchQuerySet().filter(author=team).order_by("-pub_date")
# )

# form = ModelSearchForm(
# request.GET, searchqueryset=searchqueryset, load_all=load_all
# )

# if form.is_valid():
# query = form.cleaned_data["q"]
# results = form.search()
# else:
# form = form_class(searchqueryset=searchqueryset, load_all=load_all)

# paginator = Paginator(results, results_per_page or RESULTS_PER_PAGE)

# try:
# page = paginator.page(int(request.GET.get("page", 1)))
# except InvalidPage:
# raise Http404("No such page of results!")

# context = {
# "form": form,
# "has_snipts": True,
# "page": page,
# "paginator": paginator,
# "query": query,
# "suggestion": None,
# }

# if results.query.backend.include_spelling:
# context["suggestion"] = form.get_suggestion()

# if extra_context:
# context.update(extra_context)

# return render(request, template, context)


def redirect_snipt(request, snipt_key, lexer=None):
@@ -73,16 +73,16 @@
<div class="inner">
<div class="shadey"></div>
<h1 class="main-logo"><a href="{% if request.user.is_authenticated %}/{{ request.user.username }}/{% else %}/{% endif %}">snip<span>t</span></a></h1>
<form class="search" action="/search/" method="get">
<fieldset>
<div class="fields">
<input ng-model="search.query" type="text" class="search-query" name="q"
ng-init="search.query='{{ query|escapejs }}'"
placeholder="Search snippets" id="id_q"
value="{{ query }}" />
</div>
</fieldset>
</form>
<!-- <form class="search" action="/search/" method="get"> -->
<!-- <fieldset> -->
<!-- <div class="fields"> -->
<!-- <input ng-model="search.query" type="text" class="search-query" name="q" -->
<!-- ng-init="search.query='{{ query|escapejs }}'" -->
<!-- placeholder="Search snippets" id="id_q" -->
<!-- value="{{ query }}" /> -->
<!-- </div> -->
<!-- </fieldset> -->
<!-- </form> -->
<nav class="public">
<ul>
{% if not request.user.is_authenticated %}
@@ -32,9 +32,9 @@ <h1 class="main-logo span2">
<li>
<a href="/public/">Public snippets</a>
</li>
<li>
<a href="/search/">Search</a>
</li>
<!-- <li> -->
<!-- <a href="/search/">Search</a> -->
<!-- </li> -->
{% if not request.user.is_authenticated %}
<li>
<a class="button" href="/login/">Log in</a>
@@ -15,7 +15,7 @@
PrivateUserResource,
PublicTagResource,
)
from snipts.views import search
# from snipts.views import search
from tastypie.api import Api
from views import homepage, lexers, login_redirect, tags, user_api_key

@@ -56,7 +56,7 @@
url(r"^api/private/key/$", user_api_key),
url(r"^api/", include(public_api.urls)),
url(r"^api/", include(private_api.urls)),
url(r"^search/$", search),
# url(r"^search/$", search),
url(r"^", include("teams.urls")),
url(r"^", include("snipts.urls")),
url(

0 comments on commit 59f86ae

Please sign in to comment.
You can’t perform that action at this time.