Disable search until we can get ES going again.
parent
8c8e9436d6
commit
59f86ae040
|
@ -55,6 +55,7 @@ header.main div.inner div.shadey {
|
||||||
background: transparent url("../img/header-inner-bg.png") top left no-repeat;
|
background: transparent url("../img/header-inner-bg.png") top left no-repeat;
|
||||||
height: 65px;
|
height: 65px;
|
||||||
left: -157px;
|
left: -157px;
|
||||||
|
pointer-events: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
width: 432px;
|
width: 432px;
|
||||||
|
|
|
@ -126,6 +126,7 @@ header.main {
|
||||||
background: transparent url('../img/header-inner-bg.png') top left no-repeat;
|
background: transparent url('../img/header-inner-bg.png') top left no-repeat;
|
||||||
height: 65px;
|
height: 65px;
|
||||||
left: -157px;
|
left: -157px;
|
||||||
|
pointer-events: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
width: 432px;
|
width: 432px;
|
||||||
|
|
18
settings.py
18
settings.py
|
@ -18,14 +18,14 @@ CORS_ORIGIN_ALLOW_ALL = True
|
||||||
DEBUG = True if "DEBUG" in os.environ else False
|
DEBUG = True if "DEBUG" in os.environ else False
|
||||||
DEFAULT_FROM_EMAIL = os.environ.get("POSTMARK_EMAIL", "support@siftie.com")
|
DEFAULT_FROM_EMAIL = os.environ.get("POSTMARK_EMAIL", "support@siftie.com")
|
||||||
EMAIL_BACKEND = "postmark.django_backend.EmailBackend"
|
EMAIL_BACKEND = "postmark.django_backend.EmailBackend"
|
||||||
HAYSTACK_CONNECTIONS = {
|
# HAYSTACK_CONNECTIONS = {
|
||||||
"default": {
|
# "default": {
|
||||||
"ENGINE": "haystack.backends.whoosh_backend.WhooshEngine",
|
# "ENGINE": "haystack.backends.whoosh_backend.WhooshEngine",
|
||||||
"PATH": os.environ.get("WHOOSH_PATH", "./.whoosh_index"),
|
# "PATH": os.environ.get("WHOOSH_PATH", "./.whoosh_index"),
|
||||||
"STORAGE": "file",
|
# "STORAGE": "file",
|
||||||
}
|
# }
|
||||||
}
|
# }
|
||||||
HAYSTACK_SIGNAL_PROCESSOR = "haystack.signals.RealtimeSignalProcessor"
|
# HAYSTACK_SIGNAL_PROCESSOR = "haystack.signals.RealtimeSignalProcessor"
|
||||||
INTERNAL_IPS = ("127.0.0.1",)
|
INTERNAL_IPS = ("127.0.0.1",)
|
||||||
LANGUAGE_CODE = "en-us"
|
LANGUAGE_CODE = "en-us"
|
||||||
LOGIN_REDIRECT_URL = "/login-redirect/"
|
LOGIN_REDIRECT_URL = "/login-redirect/"
|
||||||
|
@ -105,7 +105,7 @@ INSTALLED_APPS = (
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
"django_extensions",
|
"django_extensions",
|
||||||
"gunicorn",
|
"gunicorn",
|
||||||
"haystack",
|
# "haystack",
|
||||||
"markdown_deux",
|
"markdown_deux",
|
||||||
"pagination",
|
"pagination",
|
||||||
"postmark",
|
"postmark",
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.template.defaultfilters import date, urlize, linebreaksbr
|
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 snipts.models import Favorite, Snipt
|
||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
from taggit.utils import edit_string_for_tags, parse_tags
|
from taggit.utils import edit_string_for_tags, parse_tags
|
||||||
|
@ -294,9 +294,9 @@ class PublicSniptResource(ModelResource):
|
||||||
tagged_items = tag.taggit_taggeditem_items.all()
|
tagged_items = tag.taggit_taggeditem_items.all()
|
||||||
orm_filters["pk__in"] = [i.object_id for i in tagged_items]
|
orm_filters["pk__in"] = [i.object_id for i in tagged_items]
|
||||||
|
|
||||||
if "q" in filters:
|
# if "q" in filters:
|
||||||
sqs = SearchQuerySet().auto_query(filters["q"])
|
# sqs = SearchQuerySet().auto_query(filters["q"])
|
||||||
orm_filters["pk__in"] = [i.pk for i in sqs]
|
# orm_filters["pk__in"] = [i.pk for i in sqs]
|
||||||
|
|
||||||
return orm_filters
|
return orm_filters
|
||||||
|
|
||||||
|
@ -520,10 +520,10 @@ class PrivateSniptResource(ModelResource):
|
||||||
tagged_items = tag.taggit_taggeditem_items.all()
|
tagged_items = tag.taggit_taggeditem_items.all()
|
||||||
orm_filters["pk__in"] = [i.object_id for i in tagged_items]
|
orm_filters["pk__in"] = [i.object_id for i in tagged_items]
|
||||||
|
|
||||||
if "q" in filters:
|
# if "q" in filters:
|
||||||
user = User.objects.get(username=filters["username"])
|
# user = User.objects.get(username=filters["username"])
|
||||||
sqs = SearchQuerySet().filter(author=user, content=filters["q"])
|
# sqs = SearchQuerySet().filter(author=user, content=filters["q"])
|
||||||
orm_filters["pk__in"] = [i.pk for i in sqs]
|
# orm_filters["pk__in"] = [i.pk for i in sqs]
|
||||||
|
|
||||||
return orm_filters
|
return orm_filters
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
import datetime
|
# import datetime
|
||||||
|
|
||||||
from haystack import indexes
|
# from haystack import indexes
|
||||||
from snipts.models import Snipt
|
# from snipts.models import Snipt
|
||||||
|
|
||||||
|
|
||||||
class SniptIndex(indexes.SearchIndex, indexes.Indexable):
|
# class SniptIndex(indexes.SearchIndex, indexes.Indexable):
|
||||||
text = indexes.CharField(document=True, use_template=True)
|
# text = indexes.CharField(document=True, use_template=True)
|
||||||
author = indexes.CharField(model_attr="user")
|
# author = indexes.CharField(model_attr="user")
|
||||||
pub_date = indexes.DateTimeField(model_attr="created")
|
# pub_date = indexes.DateTimeField(model_attr="created")
|
||||||
public = indexes.BooleanField(model_attr="public")
|
# public = indexes.BooleanField(model_attr="public")
|
||||||
typ = indexes.CharField(model_attr="lexer")
|
# typ = indexes.CharField(model_attr="lexer")
|
||||||
|
|
||||||
def get_model(self):
|
# def get_model(self):
|
||||||
return Snipt
|
# return Snipt
|
||||||
|
|
||||||
def index_queryset(self, **kwargs):
|
# def index_queryset(self, **kwargs):
|
||||||
"""Used when the entire index for model is updated."""
|
# """Used when the entire index for model is updated."""
|
||||||
return self.get_model().objects.filter(created__lte=datetime.datetime.now())
|
# return self.get_model().objects.filter(created__lte=datetime.datetime.now())
|
||||||
|
|
132
snipts/views.py
132
snipts/views.py
|
@ -16,8 +16,8 @@ from django.http import (
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.views.decorators.cache import never_cache
|
from django.views.decorators.cache import never_cache
|
||||||
from haystack.forms import ModelSearchForm
|
# from haystack.forms import ModelSearchForm
|
||||||
from haystack.query import EmptySearchQuerySet, SearchQuerySet
|
# from haystack.query import EmptySearchQuerySet, SearchQuerySet
|
||||||
from pygments.lexers import get_lexer_by_name
|
from pygments.lexers import get_lexer_by_name
|
||||||
from snipts.models import Favorite, Snipt, SniptSecureView
|
from snipts.models import Favorite, Snipt, SniptSecureView
|
||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
|
@ -26,7 +26,7 @@ from teams.models import Team
|
||||||
import os
|
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")
|
@render_to("snipts/detail.html")
|
||||||
|
@ -290,86 +290,86 @@ def rss(request, context):
|
||||||
return render(request, "rss.xml", context, content_type="application/rss+xml")
|
return render(request, "rss.xml", context, content_type="application/rss+xml")
|
||||||
|
|
||||||
|
|
||||||
@never_cache
|
# @never_cache
|
||||||
def search(
|
# def search(
|
||||||
request,
|
# request,
|
||||||
template="search/search.html",
|
# template="search/search.html",
|
||||||
load_all=True,
|
# load_all=True,
|
||||||
form_class=ModelSearchForm,
|
# form_class=ModelSearchForm,
|
||||||
searchqueryset=None,
|
# searchqueryset=None,
|
||||||
context_class=RequestContext,
|
# context_class=RequestContext,
|
||||||
extra_context=None,
|
# extra_context=None,
|
||||||
results_per_page=None,
|
# results_per_page=None,
|
||||||
):
|
# ):
|
||||||
|
|
||||||
query = ""
|
# query = ""
|
||||||
results = EmptySearchQuerySet()
|
# results = EmptySearchQuerySet()
|
||||||
|
|
||||||
if request.GET.get("q"):
|
# if request.GET.get("q"):
|
||||||
|
|
||||||
searchqueryset = (
|
# searchqueryset = (
|
||||||
SearchQuerySet()
|
# SearchQuerySet()
|
||||||
.filter(Q(public=True) | Q(author=request.user))
|
# .filter(Q(public=True) | Q(author=request.user))
|
||||||
.order_by("-pub_date")
|
# .order_by("-pub_date")
|
||||||
)
|
# )
|
||||||
|
|
||||||
if request.user.is_authenticated() and "mine-only" in request.GET:
|
# if request.user.is_authenticated() and "mine-only" in request.GET:
|
||||||
searchqueryset = (
|
# searchqueryset = (
|
||||||
SearchQuerySet().filter(author=request.user).order_by("-pub_date")
|
# SearchQuerySet().filter(author=request.user).order_by("-pub_date")
|
||||||
)
|
# )
|
||||||
|
|
||||||
elif request.user.is_authenticated() and (
|
# elif request.user.is_authenticated() and (
|
||||||
"author" in request.GET and request.GET.get("author")
|
# "author" in request.GET and request.GET.get("author")
|
||||||
):
|
# ):
|
||||||
|
|
||||||
author = request.GET.get("author")
|
# author = request.GET.get("author")
|
||||||
|
|
||||||
if author == request.user.username:
|
# if author == request.user.username:
|
||||||
searchqueryset = (
|
# searchqueryset = (
|
||||||
SearchQuerySet().filter(author=request.user).order_by("-pub_date")
|
# SearchQuerySet().filter(author=request.user).order_by("-pub_date")
|
||||||
)
|
# )
|
||||||
|
|
||||||
else:
|
# else:
|
||||||
team = get_object_or_None(Team, slug=author)
|
# team = get_object_or_None(Team, slug=author)
|
||||||
|
|
||||||
if team and team.user_is_member(request.user):
|
# if team and team.user_is_member(request.user):
|
||||||
searchqueryset = (
|
# searchqueryset = (
|
||||||
SearchQuerySet().filter(author=team).order_by("-pub_date")
|
# SearchQuerySet().filter(author=team).order_by("-pub_date")
|
||||||
)
|
# )
|
||||||
|
|
||||||
form = ModelSearchForm(
|
# form = ModelSearchForm(
|
||||||
request.GET, searchqueryset=searchqueryset, load_all=load_all
|
# request.GET, searchqueryset=searchqueryset, load_all=load_all
|
||||||
)
|
# )
|
||||||
|
|
||||||
if form.is_valid():
|
# if form.is_valid():
|
||||||
query = form.cleaned_data["q"]
|
# query = form.cleaned_data["q"]
|
||||||
results = form.search()
|
# results = form.search()
|
||||||
else:
|
# else:
|
||||||
form = form_class(searchqueryset=searchqueryset, load_all=load_all)
|
# form = form_class(searchqueryset=searchqueryset, load_all=load_all)
|
||||||
|
|
||||||
paginator = Paginator(results, results_per_page or RESULTS_PER_PAGE)
|
# paginator = Paginator(results, results_per_page or RESULTS_PER_PAGE)
|
||||||
|
|
||||||
try:
|
# try:
|
||||||
page = paginator.page(int(request.GET.get("page", 1)))
|
# page = paginator.page(int(request.GET.get("page", 1)))
|
||||||
except InvalidPage:
|
# except InvalidPage:
|
||||||
raise Http404("No such page of results!")
|
# raise Http404("No such page of results!")
|
||||||
|
|
||||||
context = {
|
# context = {
|
||||||
"form": form,
|
# "form": form,
|
||||||
"has_snipts": True,
|
# "has_snipts": True,
|
||||||
"page": page,
|
# "page": page,
|
||||||
"paginator": paginator,
|
# "paginator": paginator,
|
||||||
"query": query,
|
# "query": query,
|
||||||
"suggestion": None,
|
# "suggestion": None,
|
||||||
}
|
# }
|
||||||
|
|
||||||
if results.query.backend.include_spelling:
|
# if results.query.backend.include_spelling:
|
||||||
context["suggestion"] = form.get_suggestion()
|
# context["suggestion"] = form.get_suggestion()
|
||||||
|
|
||||||
if extra_context:
|
# if extra_context:
|
||||||
context.update(extra_context)
|
# context.update(extra_context)
|
||||||
|
|
||||||
return render(request, template, context)
|
# return render(request, template, context)
|
||||||
|
|
||||||
|
|
||||||
def redirect_snipt(request, snipt_key, lexer=None):
|
def redirect_snipt(request, snipt_key, lexer=None):
|
||||||
|
|
|
@ -73,16 +73,16 @@
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<div class="shadey"></div>
|
<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>
|
<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">
|
<!-- <form class="search" action="/search/" method="get"> -->
|
||||||
<fieldset>
|
<!-- <fieldset> -->
|
||||||
<div class="fields">
|
<!-- <div class="fields"> -->
|
||||||
<input ng-model="search.query" type="text" class="search-query" name="q"
|
<!-- <input ng-model="search.query" type="text" class="search-query" name="q" -->
|
||||||
ng-init="search.query='{{ query|escapejs }}'"
|
<!-- ng-init="search.query='{{ query|escapejs }}'" -->
|
||||||
placeholder="Search snippets" id="id_q"
|
<!-- placeholder="Search snippets" id="id_q" -->
|
||||||
value="{{ query }}" />
|
<!-- value="{{ query }}" /> -->
|
||||||
</div>
|
<!-- </div> -->
|
||||||
</fieldset>
|
<!-- </fieldset> -->
|
||||||
</form>
|
<!-- </form> -->
|
||||||
<nav class="public">
|
<nav class="public">
|
||||||
<ul>
|
<ul>
|
||||||
{% if not request.user.is_authenticated %}
|
{% if not request.user.is_authenticated %}
|
||||||
|
|
|
@ -32,9 +32,9 @@
|
||||||
<li>
|
<li>
|
||||||
<a href="/public/">Public snippets</a>
|
<a href="/public/">Public snippets</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<!-- <li> -->
|
||||||
<a href="/search/">Search</a>
|
<!-- <a href="/search/">Search</a> -->
|
||||||
</li>
|
<!-- </li> -->
|
||||||
{% if not request.user.is_authenticated %}
|
{% if not request.user.is_authenticated %}
|
||||||
<li>
|
<li>
|
||||||
<a class="button" href="/login/">Log in</a>
|
<a class="button" href="/login/">Log in</a>
|
||||||
|
|
4
urls.py
4
urls.py
|
@ -15,7 +15,7 @@ from snipts.api import (
|
||||||
PrivateUserResource,
|
PrivateUserResource,
|
||||||
PublicTagResource,
|
PublicTagResource,
|
||||||
)
|
)
|
||||||
from snipts.views import search
|
# from snipts.views import search
|
||||||
from tastypie.api import Api
|
from tastypie.api import Api
|
||||||
from views import homepage, lexers, login_redirect, tags, user_api_key
|
from views import homepage, lexers, login_redirect, tags, user_api_key
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ urlpatterns += [
|
||||||
url(r"^api/private/key/$", user_api_key),
|
url(r"^api/private/key/$", user_api_key),
|
||||||
url(r"^api/", include(public_api.urls)),
|
url(r"^api/", include(public_api.urls)),
|
||||||
url(r"^api/", include(private_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("teams.urls")),
|
||||||
url(r"^", include("snipts.urls")),
|
url(r"^", include("snipts.urls")),
|
||||||
url(
|
url(
|
||||||
|
|
Loading…
Reference in New Issue