Created
September 8, 2014 16:07
-
-
Save ad-m/0baa6ad182a562067e34 to your computer and use it in GitHub Desktop.
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
from django.db import models | |
# Create your models here. | |
class Area(models.Model): | |
name = models.CharField(max_length=50) | |
def __unicode__(self): | |
return self.name | |
class DataType(models.Model): | |
title = models.CharField("Tytul", max_length=250) | |
area = models.ManyToManyField(Area) | |
class Meta: | |
abstract = True | |
def __unicode__(self): | |
return self.title | |
class Article(DataType): | |
description = models.TextField("Opis", null=True, blank=True) |
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
import datetime | |
from haystack import indexes | |
from .models import Article | |
class ArticleIndex(indexes.SearchIndex, indexes.Indexable): | |
text = indexes.CharField(document=True, use_template=True) | |
area = indexes.FacetMultiValueField() | |
def get_model(self): | |
return Article | |
def prepare_area(self, obj): | |
return [x.name for x in obj.area.all()] |
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
{% with obj=result.object %} | |
<h3><a href="{{obj.get_absolute_url}}"> {{ obj.title }}</a></h3> | |
{{ obj.description }} | |
{% endwith %} |
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
{% extends '2column.html' %} | |
{% block title %}Search{% endblock %} | |
{% block main %} | |
<h1>Search</h1> | |
<form class=".form-search" action="." method="get">{{ form.as_table }} | |
<input type="submit" value="Search" /></form> | |
{% if query %} | |
<h2>Results</h2> | |
{% for result in page.object_list %} | |
{% include 'search/_result_object.html' %} | |
{% empty %} | |
No results found. | |
{% endfor %} | |
{% if page.has_previous or page.has_next %} | |
{% if page.has_previous %}<a href="?q={{ query }}&page={{ page.previous_page_number }}">{% endif %}« Previous{% if page.has_previous %}</a>{% endif %} | |
| | |
{% if page.has_next %}<a href="?q={{ query }}&page={{ page.next_page_number }}">{% endif %}Next »{% if page.has_next %}</a>{% endif %} | |
{% endif %} | |
{% endif %} | |
{%endblock%} | |
{%block sidebar%} | |
{%if query %} | |
<h2>Filter</h2> | |
{% if facets.fields.area %} | |
<h3>By {{area|title}}</h3> | |
<ul> | |
{% for faced in facets.fields.area %} | |
<li><a href="{{ request.get_full_path }}&selected_facets=area_exact:{{ faced.0|urlencode }}">{{ faced.0 }}</a> ({{ faced.1 }})</li> | |
{% endfor %} | |
</ul> | |
{% endif %} | |
{%endif%} | |
{%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
"""Common settings and globals.""" | |
from os.path import abspath, basename, dirname, join, normpath | |
from sys import path | |
########## PATH CONFIGURATION | |
# Absolute filesystem path to the Django project directory: | |
DJANGO_ROOT = dirname(dirname(abspath(__file__))) | |
# Absolute filesystem path to the top-level project folder: | |
SITE_ROOT = dirname(DJANGO_ROOT) | |
# Site name: | |
SITE_NAME = basename(DJANGO_ROOT) | |
# Add our project to our pythonpath, this way we don't need to type our project | |
# name in our dotted import paths: | |
path.append(DJANGO_ROOT) | |
########## END PATH CONFIGURATION | |
########## DEBUG CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug | |
DEBUG = False | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug | |
TEMPLATE_DEBUG = DEBUG | |
########## END DEBUG CONFIGURATION | |
########## MANAGER CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins | |
ADMINS = ( | |
('Your Name', '[email protected]'), | |
) | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers | |
MANAGERS = ADMINS | |
########## END MANAGER CONFIGURATION | |
########## DATABASE CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.', | |
'NAME': '', | |
'USER': '', | |
'PASSWORD': '', | |
'HOST': '', | |
'PORT': '', | |
} | |
} | |
########## END DATABASE CONFIGURATION | |
########## GENERAL CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone | |
TIME_ZONE = 'America/Los_Angeles' | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code | |
LANGUAGE_CODE = 'en-us' | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id | |
SITE_ID = 1 | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n | |
USE_I18N = True | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n | |
USE_L10N = True | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz | |
USE_TZ = True | |
########## END GENERAL CONFIGURATION | |
########## MEDIA CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root | |
MEDIA_ROOT = normpath(join(SITE_ROOT, 'media')) | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url | |
MEDIA_URL = '/media/' | |
########## END MEDIA CONFIGURATION | |
########## STATIC FILE CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root | |
STATIC_ROOT = normpath(join(SITE_ROOT, 'assets')) | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url | |
STATIC_URL = '/static/' | |
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS | |
STATICFILES_DIRS = ( | |
normpath(join(SITE_ROOT, 'static')), | |
) | |
# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders | |
STATICFILES_FINDERS = ( | |
'django.contrib.staticfiles.finders.FileSystemFinder', | |
'django.contrib.staticfiles.finders.AppDirectoriesFinder', | |
) | |
########## END STATIC FILE CONFIGURATION | |
########## SECRET CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key | |
# Note: This key should only be used for development and testing. | |
SECRET_KEY = r"!5^jtbkym#+eexn*qkht_l!u*$j$f9b=q^w-7wbyp2e@zk7l=5" | |
########## END SECRET CONFIGURATION | |
########## SITE CONFIGURATION | |
# Hosts/domain names that are valid for this site | |
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts | |
ALLOWED_HOSTS = [] | |
########## END SITE CONFIGURATION | |
########## FIXTURE CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS | |
FIXTURE_DIRS = ( | |
normpath(join(SITE_ROOT, 'fixtures')), | |
) | |
########## END FIXTURE CONFIGURATION | |
########## TEMPLATE CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors | |
TEMPLATE_CONTEXT_PROCESSORS = ( | |
'django.contrib.auth.context_processors.auth', | |
'django.core.context_processors.debug', | |
'django.core.context_processors.i18n', | |
'django.core.context_processors.media', | |
'django.core.context_processors.static', | |
'django.core.context_processors.tz', | |
'django.contrib.messages.context_processors.messages', | |
'django.core.context_processors.request', | |
) | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders | |
TEMPLATE_LOADERS = ( | |
'django.template.loaders.filesystem.Loader', | |
'django.template.loaders.app_directories.Loader', | |
) | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs | |
TEMPLATE_DIRS = ( | |
normpath(join(SITE_ROOT, 'templates')), | |
) | |
########## END TEMPLATE CONFIGURATION | |
########## MIDDLEWARE CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes | |
MIDDLEWARE_CLASSES = ( | |
# Default Django middleware. | |
'django.middleware.common.CommonMiddleware', | |
'django.contrib.sessions.middleware.SessionMiddleware', | |
'django.middleware.csrf.CsrfViewMiddleware', | |
'django.contrib.auth.middleware.AuthenticationMiddleware', | |
'django.contrib.messages.middleware.MessageMiddleware', | |
'django.middleware.clickjacking.XFrameOptionsMiddleware', | |
) | |
########## END MIDDLEWARE CONFIGURATION | |
########## URL CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf | |
ROOT_URLCONF = '%s.urls' % SITE_NAME | |
########## END URL CONFIGURATION | |
########## APP CONFIGURATION | |
DJANGO_APPS = ( | |
# Default Django apps: | |
'django.contrib.auth', | |
'django.contrib.contenttypes', | |
'django.contrib.sessions', | |
'django.contrib.sites', | |
'django.contrib.messages', | |
'django.contrib.staticfiles', | |
# Useful template tags: | |
# 'django.contrib.humanize', | |
# Admin panel and documentation: | |
'django.contrib.admin', | |
# 'django.contrib.admindocs', | |
'haystack', | |
'autofixture' | |
) | |
# Apps specific for this project go here. | |
LOCAL_APPS = ( 'blog', | |
) | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps | |
INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS | |
########## END APP CONFIGURATION | |
########## LOGGING CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging | |
# A sample logging configuration. The only tangible logging | |
# performed by this configuration is to send an email to | |
# the site admins on every HTTP 500 error when DEBUG=False. | |
# See http://docs.djangoproject.com/en/dev/topics/logging for | |
# more details on how to customize your logging configuration. | |
LOGGING = { | |
'version': 1, | |
'disable_existing_loggers': False, | |
'filters': { | |
'require_debug_false': { | |
'()': 'django.utils.log.RequireDebugFalse' | |
} | |
}, | |
'handlers': { | |
'mail_admins': { | |
'level': 'ERROR', | |
'filters': ['require_debug_false'], | |
'class': 'django.utils.log.AdminEmailHandler' | |
} | |
}, | |
'loggers': { | |
'django.request': { | |
'handlers': ['mail_admins'], | |
'level': 'ERROR', | |
'propagate': True, | |
}, | |
} | |
} | |
########## END LOGGING CONFIGURATION | |
########## WSGI CONFIGURATION | |
# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application | |
WSGI_APPLICATION = '%s.wsgi.application' % SITE_NAME | |
########## END WSGI CONFIGURATION | |
########## SOUTH CONFIGURATION | |
# See: http://south.readthedocs.org/en/latest/installation.html#configuring-your-django-installation | |
INSTALLED_APPS += ( | |
# Database migration helpers: | |
'south', | |
) | |
# Don't need to use South when setting up a test database. | |
SOUTH_TESTS_MIGRATE = False | |
########## END SOUTH CONFIGURATION | |
HAYSTACK_CONNECTIONS = { | |
'default': { | |
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', | |
'URL': 'http://127.0.0.1:9200/', | |
'INDEX_NAME': 'haystack_test', | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment