This repository has been archived by the owner on Apr 10, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
from challenges.models import SubmissionParent | |||
from haystack import indexes | |||
|
|||
class SubmissionParentIndex(indexes.SearchIndex, indexes.Indexable): | |||
text = indexes.CharField(document=True, use_template=True) | |||
user = indexes.CharField(model_attr='submission__created_by__name') | |||
category = indexes.CharField(model_attr='submission__category__name', | |||
faceted=True) | |||
|
|||
def get_model(self): | |||
return SubmissionParent |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
from haystack.forms import FacetedSearchForm | |||
|
|||
class CustomFacetedSearchForm(FacetedSearchForm): | |||
"""Override the results settings""" | |||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
from django.db import models | |||
|
|||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
""" | |||
This file demonstrates writing tests using the unittest module. These will pass | |||
when you run "manage.py test". | |||
Replace this with more appropriate tests for your application. | |||
""" | |||
|
|||
from django.test import TestCase | |||
|
|||
|
|||
class SimpleTest(TestCase): | |||
def test_basic_addition(self): | |||
""" | |||
Tests that 1 + 1 always equals 2. | |||
""" | |||
self.assertEqual(1 + 1, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,7 @@ | |||
from django.conf.urls.defaults import patterns, url | |||
from search.views import CustomSearchView | |||
|
|||
urlpatterns = patterns( | |||
'', | |||
url(r'^$', CustomSearchView(), name='search'), | |||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
import jingo | |||
|
|||
from django.http import Http404 | |||
from django.views.decorators.http import require_GET | |||
from haystack.query import SearchQuerySet | |||
from haystack.views import FacetedSearchView | |||
from search.forms import CustomFacetedSearchForm | |||
|
|||
# @require_GET | |||
# def search(request): | |||
# """Performs the search on the ``Submissions``""" | |||
# form = SearchForm(request.GET) | |||
# if not form.is_valid(): | |||
# raise Http404 | |||
# query = form.cleaned_data['q'] | |||
# sqs = SearchQuerySet().auto_query(query) | |||
# context = { | |||
# 'results': sqs, | |||
# 'form': form, | |||
# } | |||
# return jingo.render(request, 'search/search.html', context) | |||
|
|||
|
|||
class CustomSearchView(FacetedSearchView): | |||
"""Uses jingo to render the pages""" | |||
|
|||
def __init__(self, *args, **kwargs): | |||
# Needed to switch out the default form class. | |||
if kwargs.get('form_class') is None: | |||
kwargs['form_class'] = CustomFacetedSearchForm | |||
super(FacetedSearchView, self).__init__(*args, **kwargs) | |||
|
|||
def create_response(self): | |||
"""Generates the actual HttpResponse to send back to the user.""" | |||
(paginator, page) = self.build_page() | |||
context = { | |||
'query': self.query, | |||
'form': self.form, | |||
'page': page, | |||
'paginator': paginator, | |||
'suggestion': None, | |||
} | |||
if self.results and hasattr(self.results, 'query') and self.results.query.backend.include_spelling: | |||
context['suggestion'] = self.form.get_suggestion() | |||
context.update(self.extra_context()) | |||
return jingo.render(self.request, self.template, context) | |||
|
|||
def extra_context(self): | |||
extra = super(CustomSearchView, self).extra_context() | |||
extra['days_remaining'] = self.request.phase['days_remaining'] | |||
return extra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
templates_ignite/search/indexes/challenges/submissionparent_text.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
{{ object.submission.title|safe }} | |||
{{ object.submission.brief_description|safe }} | |||
{{ object.submission.description|safe }} | |||
{{ object.submission.category.name|safe }} | |||
{{ object.submission.created_by.name|safe }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
{% extends "challenges/all.html" %} | |||
|
|||
{% block title_listing %}Search Ideas{% endblock title_listing %} | |||
|
|||
{% block content %} | |||
<div class="content_columns columns with_nav"> | |||
|
|||
<nav class="tags col box nav"> | |||
<form method="get" id="form-search-id" action="{{ url('search:search') }}"> | |||
<ul> | |||
{{ form.as_ul() }} | |||
<li> | |||
<input class="cta" type="submit" value="Search"> | |||
</li> | |||
</ul> | |||
</form> | |||
</nav> | |||
|
|||
<div class="highlight col box main"> | |||
<ol class="submissions columns"> | |||
{% for result in page.object_list %} | |||
<li class="box col"> | |||
<article> | |||
<a class="title" href="{{ result.object.get_absolute_url() }}"> | |||
<h3 class="title wimper"> | |||
<div class="frame box"> | |||
<img src="http://src.sencha.io/200/{{ app_url }}{{ result.object.submission.get_image_src() }}" alt=""> | |||
</div> | |||
{{ result.object.submission.title }} | |||
</h3> | |||
</a> | |||
<p>{{ result.object.submission.brief_description }}</p> | |||
<address>{{ created_by(result.object.submission, footer=False) }}</address> | |||
</article> | |||
</li> | |||
{% endfor %} | |||
</ol> | |||
|
|||
{% if query %} | |||
{{ footer_pagination(page, query) }} | |||
{% endif %} | |||
|
|||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
</section> | |||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters