diff --git a/.env-local b/.env-local index 3b73161..4a8be83 100644 --- a/.env-local +++ b/.env-local @@ -1,4 +1,3 @@ DEBUG=True STAGE=local -DEFAULT_HAYSTACK_URL=es+http://es:9200/index-* DATABASE_URL=postgres://postgres@postgres:5432/db diff --git a/Dockerfile b/Dockerfile index 362055a..d8f305c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,7 +47,6 @@ RUN pip-reqs compile && \ --requirement requirements.urls # -RUN mkdir -p /usr/share/whoosh/data && chmod -R 777 /usr/share/whoosh/data # COPY . /app diff --git a/docker-compose.yml b/docker-compose.yml index 0b21a2c..e053ad0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,13 +5,11 @@ services: build: "." links: - "db:postgres" -# - "es:es" ports: - "8009:80" volumes: - ".:/app:rw" - "./data:/data:rw" - - "./whoosh:/usr/share/whoosh/data:rw" command: python manage.py runserver 0.0.0.0:80 env_file: .env-local @@ -22,21 +20,3 @@ services: volumes: - ".:/app:rw" -# es: -# image: elasticsearch:2.4-alpine -# ulimits: -# memlock: -# soft: 5120 -# hard: 5120 -# environment: -# - "ES_JAVA_OPTS=-server -Xms10m -Xmx10m" -# - "ES_HEAP_SIZE=10m" -# - "MAX_LOCKED_MEMORY=5120" -# - index.number_of_shards=1 -# - index.number_of_replicas=0 -# - network.tcp.block=1 -# - bootstrap.memory_lock=1 -# volumes: -# - "./esdata:/usr/share/elasticsearch/data:rw" -# expose: -# - "9200" diff --git a/requirements.in b/requirements.in index 482b9c3..a42e50c 100644 --- a/requirements.in +++ b/requirements.in @@ -11,7 +11,6 @@ https://control.divio.com/api/v1/apps/serve/djangocms-picture/2.0.6/005e8663-d1c https://control.divio.com/api/v1/apps/serve/djangocms-text-ckeditor/3.5.3/a7b5179f-cea5-4af8-b235-6b7f709c4e6a/djangocms-text-ckeditor-3.5.3.tar.gz#egg=djangocms-text-ckeditor==3.5.3 https://control.divio.com/api/v1/apps/serve/django-filer/1.3.0.1/bcb7d25b-6922-48a9-a252-9bc165f6403e/django-filer-1.3.0.1.tar.gz#egg=django-filer==1.3.0.1 # -Whoosh==2.7.4 django-haystack==2.7.0 aldryn-search==0.5.0 django-fontawesome==0.3.1 diff --git a/settings.py b/settings.py index 3115880..a445432 100644 --- a/settings.py +++ b/settings.py @@ -57,18 +57,15 @@ ALDRYN_SEARCH_INDEX_BASE_CLASS = 'project.search.SearchIndex' HAYSTACK_CUSTOM_HIGHLIGHTER = 'project.search.Highlighter' HAYSTACK_DEFAULT_OPERATOR = 'OR' -HAYSTACK_INDEX_PATH = os.path.join('/usr/share/whoosh/data', 'index') HAYSTACK_CONNECTIONS = { 'default': { - 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', - 'PATH': os.path.join(HAYSTACK_INDEX_PATH, 'default'), + 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }, } for lang_code, lang in LANGUAGES: HAYSTACK_CONNECTIONS[lang_code] = {} HAYSTACK_CONNECTIONS[lang_code].update({ - 'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', - 'PATH': os.path.join(HAYSTACK_INDEX_PATH, lang_code), + 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }) HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter', ] diff --git a/src/portal/models.py b/src/portal/models.py index dad269f..073c64b 100644 --- a/src/portal/models.py +++ b/src/portal/models.py @@ -6,12 +6,11 @@ from django.core.files.storage import default_storage from django.conf import settings from django.db import models from django.core.urlresolvers import reverse_lazy -from django.utils import timezone from django.utils.translation import ugettext_lazy as _ from image_cropping import ImageRatioField from parler.models import TranslatableModel, TranslatedFields -#from portal.storage import PrivateS3MediaStorage +from portal.storage import PrivateS3MediaStorage from project.utils import CroppableFilerImageField @@ -92,8 +91,7 @@ class DownloadTag(TranslatableModel): if getattr(settings, 'DEFAULT_STORAGE_DSN', None): - # protected_file_storage = PrivateS3MediaStorage() - protected_file_storage = default_storage + protected_file_storage = PrivateS3MediaStorage() else: protected_file_storage = default_storage diff --git a/src/portal/storage.py b/src/portal/storage.py index 323b06c..1ed4620 100644 --- a/src/portal/storage.py +++ b/src/portal/storage.py @@ -1,58 +1,57 @@ # -*- coding: utf-8 -*- -#import re -#from aldryn_django.storage import S3MediaStorage -#from django.conf import settings -# -#from boto.s3.connection import ( -# SubdomainCallingFormat, -# OrdinaryCallingFormat, -#) -# -# -#class PrivateS3MediaStorage(S3MediaStorage): -# def __init__(self): -# bucket_name = settings.AWS_MEDIA_STORAGE_BUCKET_NAME -# -# if '.' in bucket_name: -# calling_format = OrdinaryCallingFormat() -# else: -# calling_format = SubdomainCallingFormat() -# -# # We cannot use a function call or a partial here. Instead, we have to -# # create a subclass because django tries to recreate a new object by -# # calling the __init__ of the returned object (with no arguments). -# super(S3MediaStorage, self).__init__( -# access_key=settings.AWS_MEDIA_ACCESS_KEY_ID, -# secret_key=settings.AWS_MEDIA_SECRET_ACCESS_KEY, -# bucket_name=bucket_name, -# location=settings.AWS_MEDIA_BUCKET_PREFIX, -# host=settings.AWS_MEDIA_STORAGE_HOST, -# custom_domain=settings.AWS_MEDIA_DOMAIN, -# calling_format=calling_format, -# # Setting an ACL requires us to grant the user the PutObjectAcl -# # permission as well, even if it matches the default bucket ACL. -# # XXX: Ideally we would thus set it to `None`, but due to how -# # easy_thumbnails works internally, that causes thumbnail -# # generation to fail... -# default_acl='private', -# querystring_auth=True, -# ) -# # MEDIA_HEADERS is a list of tuples containing a regular expression -# # to match against a path, and a dictionary of HTTP headers to be -# # returned with the resource identified by the path when it is -# # requested. -# # The headers are applied in the order they where declared, and -# # processing stops at the first match. -# # E.g.: -# # -# # MEDIA_HEADERS = [ -# # (r'media/cache/.*', { -# # 'Cache-Control': 'max-age={}'.format(3600 * 24 * 365), -# # }) -# # ] -# # -# media_headers = getattr(settings, 'MEDIA_HEADERS', []) -# self.media_headers = [ -# (re.compile(r), headers) for r, headers in media_headers -# ] -# \ No newline at end of file +import re +from aldryn_django.storage import S3MediaStorage +from django.conf import settings + +from boto.s3.connection import ( + SubdomainCallingFormat, + OrdinaryCallingFormat, +) + + +class PrivateS3MediaStorage(S3MediaStorage): + def __init__(self): + bucket_name = settings.AWS_MEDIA_STORAGE_BUCKET_NAME + + if '.' in bucket_name: + calling_format = OrdinaryCallingFormat() + else: + calling_format = SubdomainCallingFormat() + + # We cannot use a function call or a partial here. Instead, we have to + # create a subclass because django tries to recreate a new object by + # calling the __init__ of the returned object (with no arguments). + super(S3MediaStorage, self).__init__( + access_key=settings.AWS_MEDIA_ACCESS_KEY_ID, + secret_key=settings.AWS_MEDIA_SECRET_ACCESS_KEY, + bucket_name=bucket_name, + location=settings.AWS_MEDIA_BUCKET_PREFIX, + host=settings.AWS_MEDIA_STORAGE_HOST, + custom_domain=settings.AWS_MEDIA_DOMAIN, + calling_format=calling_format, + # Setting an ACL requires us to grant the user the PutObjectAcl + # permission as well, even if it matches the default bucket ACL. + # XXX: Ideally we would thus set it to `None`, but due to how + # easy_thumbnails works internally, that causes thumbnail + # generation to fail... + default_acl='private', + querystring_auth=True, + ) + # MEDIA_HEADERS is a list of tuples containing a regular expression + # to match against a path, and a dictionary of HTTP headers to be + # returned with the resource identified by the path when it is + # requested. + # The headers are applied in the order they where declared, and + # processing stops at the first match. + # E.g.: + # + # MEDIA_HEADERS = [ + # (r'media/cache/.*', { + # 'Cache-Control': 'max-age={}'.format(3600 * 24 * 365), + # }) + # ] + # + media_headers = getattr(settings, 'MEDIA_HEADERS', []) + self.media_headers = [ + (re.compile(r), headers) for r, headers in media_headers + ]