From e20ed191c1c1f9d58e97f62a6bf021e0785b8c5f Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 11:00:30 -0400 Subject: [PATCH 01/50] Working on Heroku integration. --- Procfile | 1 + snipt.wsgi | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 Procfile create mode 100644 snipt.wsgi diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..b48e1f5 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: gunicorn hellodjango.wsgi --log-file - diff --git a/snipt.wsgi b/snipt.wsgi new file mode 100644 index 0000000..ecf05ea --- /dev/null +++ b/snipt.wsgi @@ -0,0 +1,14 @@ +""" +WSGI config for what project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ +""" + +import os +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "snipt.settings") + +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() From 8ce33ea1b919d7984f04270ad3729628e4d44a12 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 11:04:39 -0400 Subject: [PATCH 02/50] Working on Heroku integration. --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index b48e1f5..3e30175 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn hellodjango.wsgi --log-file - +web: gunicorn snipt.wsgi --log-file - From d54612c1ab7c1d86a2e0fff4a2a954f6c77a106e Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 11:08:13 -0400 Subject: [PATCH 03/50] Working on Heroku integration. --- Procfile | 2 +- snipt.wsgi => wsgi.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename snipt.wsgi => wsgi.py (82%) diff --git a/Procfile b/Procfile index 3e30175..b94b07e 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn snipt.wsgi --log-file - +web: gunicorn wsgi --log-file - diff --git a/snipt.wsgi b/wsgi.py similarity index 82% rename from snipt.wsgi rename to wsgi.py index ecf05ea..ba081cc 100644 --- a/snipt.wsgi +++ b/wsgi.py @@ -8,7 +8,7 @@ https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/ """ import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "snipt.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() From e7b4b5515a6ac6d35eea21c3403e478a1a733085 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 11:13:02 -0400 Subject: [PATCH 04/50] Working on Heroku integration. --- requirements.txt | 1 + settings.py | 38 +++++++++++++------------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/requirements.txt b/requirements.txt index 296b197..c94876b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,6 +12,7 @@ django-pagination==1.0.7 django-taggit==0.10 django-tastypie==0.10.0 django-templatetag-sugar==0.1 +django-toolbelt==0.0.1 ecdsa==0.10 Fabric==1.8.0 gunicorn==18.0 diff --git a/settings.py b/settings.py index ee9a8ba..97e0d6b 100644 --- a/settings.py +++ b/settings.py @@ -1,6 +1,6 @@ # Django settings for snipt project. -import os +import dj_database_url, os DEBUG = True @@ -12,23 +12,23 @@ ADMINS = ( MANAGERS = ADMINS -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': os.environ.get('DB_NAME', 'snipt'), - 'USER': os.environ.get('DB_USER', ''), - 'PASSWORD': os.environ.get('DB_PASS', ''), - 'HOST': os.environ.get('DB_PORT_5432_TCP_ADDR', '127.0.0.1'), - 'PORT': os.environ.get('DB_PORT_5432_TCP_PORT', ''), - } -} +DATABASES['default'] = dj_database_url.config() +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') +ALLOWED_HOSTS = ['*'] + +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +STATIC_ROOT = 'staticfiles' +STATIC_URL = '/static/' + +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, 'media'), + os.path.join(BASE_DIR, 'static'), +) INTERNAL_IPS = ('127.0.0.1',) SITE_ID = 1 -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. USE_I18N = True # If you set this to False, Django will not format dates, numbers and @@ -57,18 +57,6 @@ MEDIA_ROOT = os.path.join(BASE_PATH, 'media/uploads') # Examples: "http://media.lawrence.com/media/", "http://example.com/media/" MEDIA_URL = '/media/uploads/' -# Absolute path to the directory static files should be collected to. -# Don't put anything in this directory yourself; store your static files -# in apps' "static/" subdirectories and in STATICFILES_DIRS. -# Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = os.path.join(BASE_PATH, 'static') -STATIC_URL = '/static/' - -# Additional locations of static files -STATICFILES_DIRS = ( - os.path.join(BASE_PATH, 'media'), -) - # List of finder classes that know how to find static files in # various locations. STATICFILES_FINDERS = ( From fe425f437dfd7ea744b3d85af79693b34dfe1c84 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 11:18:08 -0400 Subject: [PATCH 05/50] Working on Heroku integration. --- settings.py | 205 ++++++++++++++-------------------------------------- 1 file changed, 53 insertions(+), 152 deletions(-) diff --git a/settings.py b/settings.py index 97e0d6b..76640cc 100644 --- a/settings.py +++ b/settings.py @@ -1,74 +1,45 @@ -# Django settings for snipt project. - import dj_database_url, os -DEBUG = True - -BASE_PATH = os.path.dirname(__file__) - -ADMINS = ( - ('Name', 'name@domain.com'), -) - -MANAGERS = ADMINS - -DATABASES['default'] = dj_database_url.config() -SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') +ABSOLUTE_URL_OVERRIDES = { 'auth.user': lambda u: "/%s/" % u.username, } +ACCOUNT_ACTIVATION_DAYS = 0 +ADMINS = (('Name', 'name@domain.com'),) ALLOWED_HOSTS = ['*'] - +AUTH_PROFILE_MODULE = 'accounts.UserProfile' +AUTHENTICATION_BACKENDS = ('utils.backends.EmailOrUsernameModelBackend',) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +BASE_PATH = os.path.dirname(__file__) +DATABASES = { 'default': dj_database_url.config() } +DEBUG = True +HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }, } +HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' +INTERNAL_IPS = ('127.0.0.1',) +LANGUAGE_CODE = 'en-us' +LOGIN_REDIRECT_URL = '/login-redirect/' +LOGIN_URL = '/login/' +LOGOUT_URL = '/logout/' +MANAGERS = ADMINS +MEDIA_ROOT = os.path.join(BASE_PATH, 'media/uploads') +MEDIA_URL = '/media/uploads/' +MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' +PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) +ROOT_URLCONF = 'urls' +SECRET_KEY = 'changethis' +SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') +SESSION_COOKIE_AGE = 15801100 +SITE_ID = 1 +STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),) +STATICFILES_FINDERS = ('django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder',) STATIC_ROOT = 'staticfiles' STATIC_URL = '/static/' - -STATICFILES_DIRS = ( - os.path.join(BASE_DIR, 'media'), - os.path.join(BASE_DIR, 'static'), -) - -INTERNAL_IPS = ('127.0.0.1',) - -SITE_ID = 1 - -USE_I18N = True - -# If you set this to False, Django will not format dates, numbers and -# calendars according to the current locale -USE_L10N = True - -# Local time zone. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# -# On Unix systems, a value of None will cause Django to use the same timezone as -# the operating system. On a Windows environment, this must be set to the same -# as your system time zone +TASTYPIE_CANNED_ERROR = "There was an error with your request. The site developers have a record of this error, please email api@snipt.net and we'll help you out." +TEMPLATE_DIRS = (os.path.join(PROJECT_PATH, 'templates')) TIME_ZONE = 'America/New_York' +USE_I18N = True +USE_L10N = True USE_TZ = True -# Language code for the Django installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'en-us' - -# Absolute filesystem path to the directory that will hold user-uploaded files. -# Example: "/home/media/media.lawrence.com/media/" -MEDIA_ROOT = os.path.join(BASE_PATH, 'media/uploads') - -# URL that handles the media served from MEDIA_ROOT. Make sure to use a -# trailing slash. -# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" -MEDIA_URL = '/media/uploads/' - -# List of finder classes that know how to find static files in -# various locations. -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', -) - -SECRET_KEY = 'changethis' - INSTALLED_APPS = ( 'gunicorn', - 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.humanize', @@ -77,7 +48,6 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', - 'django_bcrypt', 'haystack', 'markdown_deux', @@ -88,19 +58,31 @@ INSTALLED_APPS = ( 'taggit', 'tastypie', 'typogrify', - 'accounts', 'blogs', 'jobs', 'snipts', 'utils', ) - -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader', -# 'django.template.loaders.eggs.Loader', +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse' + } + }, + 'handlers': {}, + 'loggers': {} +} +MIDDLEWARE_CLASSES = ( + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'pagination.middleware.PaginationMiddleware', + 'blogs.middleware.BlogMiddleware', ) TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', @@ -111,88 +93,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'django.core.context_processors.static', 'django.contrib.messages.context_processors.messages', ) - -MIDDLEWARE_CLASSES = ( - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.messages.middleware.MessageMiddleware', - 'pagination.middleware.PaginationMiddleware', - 'blogs.middleware.BlogMiddleware', +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', ) - -AUTHENTICATION_BACKENDS = ( - 'utils.backends.EmailOrUsernameModelBackend', -) - -ROOT_URLCONF = 'urls' - -PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) - -TEMPLATE_DIRS = ( - os.path.join(PROJECT_PATH, 'templates') -) - -SESSION_COOKIE_AGE = 15801100 - -# 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. -# 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, - #}, - } -} - -HAYSTACK_CONNECTIONS = { - 'default': { - 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', - }, -} -HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' - -# Account settings -LOGIN_REDIRECT_URL = '/login-redirect/' -LOGIN_URL = '/login/' -LOGOUT_URL = '/logout/' -ACCOUNT_ACTIVATION_DAYS = 0 - -# Messages -MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' - -# User absolute URLs -ABSOLUTE_URL_OVERRIDES = { - 'auth.user': lambda u: "/%s/" % u.username, -} - -# Accounts -AUTH_PROFILE_MODULE = 'accounts.UserProfile' - -# API -TASTYPIE_CANNED_ERROR = "There was an error with your request. The site developers have a record of this error, please email api@snipt.net and we'll help you out." - -try: - from settings_local import * -except ImportError: - pass From a5bc4c451ba41c1dd894d614996fa54fe6aed504 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 11:32:18 -0400 Subject: [PATCH 06/50] Working on Heroku integration. Conflicts: fabfile.py --- Dockerfile | 21 -------- accounts/views.py | 2 - fabfile.py | 83 ------------------------------- fig.yml | 32 ------------ gunicorn.conf.server.py | 12 ----- settings.py | 4 +- settings_local-template.py | 89 ---------------------------------- utils/templatetags/intercom.py | 1 - views.py | 2 - wsgi.py | 4 +- 10 files changed, 5 insertions(+), 245 deletions(-) delete mode 100644 Dockerfile delete mode 100644 fabfile.py delete mode 100644 fig.yml delete mode 100644 gunicorn.conf.server.py delete mode 100644 settings_local-template.py diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 6fc3eb5..0000000 --- a/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM debian:jessie -ENV DEBIAN_FRONTEND noninteractive -RUN apt-get update && apt-get install -y \ - build-essential \ - python \ - python-dev \ - python-setuptools \ - git-core \ - mercurial \ - libxml2-dev \ - libxslt-dev \ - libpq-dev -RUN easy_install pip -COPY . /app/snipt -RUN pip install -r /app/snipt/requirements.txt -RUN pip install --index-url https://code.stripe.com --upgrade stripe -ADD .docker/run.sh /docker-run -RUN mkdir -p /tmp/app -WORKDIR /app/snipt -EXPOSE 8000 -CMD ["/docker-run"] diff --git a/accounts/views.py b/accounts/views.py index ed4213d..57a1c97 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -4,8 +4,6 @@ from snipts.models import Snipt import stripe -from settings_local import STRIPE_SECRET_KEY - @login_required @render_to('account.html') diff --git a/fabfile.py b/fabfile.py deleted file mode 100644 index f9c1a20..0000000 --- a/fabfile.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env python -# -- coding: utf-8 -- - -from fabric.api import cd, local, env, run, sudo - -from boto.s3.connection import S3Connection -from boto.s3.key import Key - -import datetime, hashlib, sys - -from settings_local import AMAZON_API_KEY, AMAZON_API_SECRET, ENV_HOST - - -env.hosts = [ENV_HOST] -env.site_path = '/home/nick/snipt' - - -def dep(): - local('python manage.py collectstatic --ignore cache --noinput') - - try: - local('git push') - except: - pass - - with cd(env.site_path): - run('git pull') - run('/home/nick/snipt/.docker/control.sh collectstatic') - run('/home/nick/snipt/.docker/control.sh deploy') - -def db_backup(): - conn = S3Connection(AMAZON_API_KEY, AMAZON_API_SECRET) - snipt_bucket = conn.get_bucket('snipt') - k = Key(snipt_bucket) - k.key = filename - k.set_contents_from_filename('/tmp/snipt.pgdump') - local('rm {}'.format('/tmp/snipt.pgdump')) - -def db(): - with cd(env.site_path): - run('/home/nick/snipt/.docker/control.sh syncdb') - run('/home/nick/snipt/.docker/control.sh migrate') - -def gravatars(): - - from fabric.contrib import django - django.settings_module('settings') - - from django.contrib.auth.models import User - - import requests - - for user in User.objects.all().order_by('id'): - - email_md5 = hashlib.md5(user.email.lower()).hexdigest() - - print 'Email MD5: {}'.format(email_md5) - - greq = requests.get('https://secure.gravatar.com/avatar/{}?s=50&d=404'.format(email_md5)) - - if greq.status_code == 404: - has_gravatar = False - else: - has_gravatar = True - - profile = user.profile - profile.has_gravatar = has_gravatar - profile.save() - - try: - from fabric.colors import green, red - - if has_gravatar: - print 'Has Gravatar: {}'.format(green(has_gravatar)) - else: - print 'Has Gravatar: {}'.format(red(has_gravatar)) - - except ImportError: - print 'Has Gravatar: {}'.format(has_gravatar) - -def re(): - with cd(env.site_path): - run('/home/nick/snipt/.docker/control.sh restart') diff --git a/fig.yml b/fig.yml deleted file mode 100644 index 635c3f7..0000000 --- a/fig.yml +++ /dev/null @@ -1,32 +0,0 @@ -postgres: - image: postgres:9.1 - expose: - - "5432" - -elasticsearch: - image: arcus/elasticsearch - expose: - - "9200" - - "9300" -app: - build: . - links: - - postgres:db - - elasticsearch:es - ports: - - "8000:80" - expose: - - "8000" - environment: - - DB_NAME=postgres - - DB_USER=postgres - -proxy: - image: nginx - ports: - - "80" - volumes: - - .docker/nginx.conf:/etc/nginx.conf - - static:/app/snipt/static - net: "container:snipt_app_1" - diff --git a/gunicorn.conf.server.py b/gunicorn.conf.server.py deleted file mode 100644 index f48c9fb..0000000 --- a/gunicorn.conf.server.py +++ /dev/null @@ -1,12 +0,0 @@ -bind = "0.0.0.0:8000" -daemon = False # Whether work in the background -debug = False # Some extra logging -logfile = ".gunicorn.log" # Name of the log file -loglevel = "info" # The level at which to log -pidfile = ".gunicorn.pid" # Path to a PID file -workers = 9 # Number of workers to initialize -umask = 0 # Umask to set when daemonizing -user = None # Change process owner to user -group = None # Change process group to group -proc_name = "gunicorn-snipt" # Change the process name -tmp_upload_dir = None # Set path used to store temporary uploads diff --git a/settings.py b/settings.py index 76640cc..e3a6c0c 100644 --- a/settings.py +++ b/settings.py @@ -27,9 +27,9 @@ SECRET_KEY = 'changethis' SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SESSION_COOKIE_AGE = 15801100 SITE_ID = 1 -STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),) +STATICFILES_DIRS = (os.path.join(BASE_PATH, 'media'),) STATICFILES_FINDERS = ('django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder',) -STATIC_ROOT = 'staticfiles' +STATIC_ROOT = os.path.join(BASE_PATH, 'static') STATIC_URL = '/static/' TASTYPIE_CANNED_ERROR = "There was an error with your request. The site developers have a record of this error, please email api@snipt.net and we'll help you out." TEMPLATE_DIRS = (os.path.join(PROJECT_PATH, 'templates')) diff --git a/settings_local-template.py b/settings_local-template.py deleted file mode 100644 index bab4930..0000000 --- a/settings_local-template.py +++ /dev/null @@ -1,89 +0,0 @@ -import os -from settings import INSTALLED_APPS, MIDDLEWARE_CLASSES - -DEBUG = True -if os.environ.get('DEBUG', '').lower() == 'false': - DEBUG = False - -TEMPLATE_DEBUG = DEBUG - -BASE_PATH = os.path.dirname(__file__) - -PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) - -ADMINS = ( - ('Name', 'name@domain.com'), -) - -MANAGERS = ADMINS - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': os.environ.get('DB_NAME', 'snipt'), - 'USER': os.environ.get('DB_USER', ''), - 'PASSWORD': os.environ.get('DB_PASS', ''), - 'HOST': os.environ.get('DB_PORT_5432_TCP_ADDR', 'localhost'), - 'PORT': os.environ.get('DB_PORT_5432_TCP_PORT', ''), - } -} - - -TIME_ZONE = 'America/New_York' - -LANGUAGE_CODE = 'en-us' - -MEDIA_ROOT = os.path.join(BASE_PATH, 'media/uploads') - -MEDIA_URL = '/media/uploads/' - -STATIC_URL = '/static/' - -SECRET_KEY = '' - -DEFAULT_FROM_EMAIL = 'support@snipt.net' -SERVER_EMAIL = 'support@snipt.net' -EMAIL_BACKEND = 'postmark.django_backend.EmailBackend' -POSTMARK_API_KEY = '' - -VIRTUALENV_PATH = '' - -AMAZON_API_KEY = '' -AMAZON_API_SECRET = '' - -STRIPE_SECRET_KEY = '' - -ENV_HOST = 'user@domain.com:22' - -USE_HTTPS = False -SESSION_COOKIE_SECURE = False -CSRF_COOKIE_SECURE = False -SESSION_COOKIE_DOMAIN = '.snipt.net' -ALLOWED_HOSTS = ['*'] - -ES_HOST = os.environ.get('ES_PORT_9200_TCP_ADDR', '127.0.0.1') -ES_PORT = os.environ.get('ES_PORT_9200_TCP_PORT', '9200') - -HAYSTACK_CONNECTIONS = { - 'default': { - 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', - 'URL': 'http://{}:{}/'.format(ES_HOST, ES_PORT), - 'INDEX_NAME': 'haystack', - }, -} - -INSTALLED_APPS += ( - 'debug_toolbar', - 'django_extensions', - 'raven.contrib.django.raven_compat', -) - -RAVEN_CONFIG = { - 'dsn': '', -} - -MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES + ( - 'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware', -) - -INTERCOM_SECRET_KEY = '' diff --git a/utils/templatetags/intercom.py b/utils/templatetags/intercom.py index d1a52cc..ced4efa 100644 --- a/utils/templatetags/intercom.py +++ b/utils/templatetags/intercom.py @@ -1,5 +1,4 @@ from django import template -from settings_local import INTERCOM_SECRET_KEY import hmac, hashlib diff --git a/views.py b/views.py index be6b355..e8c78b6 100644 --- a/views.py +++ b/views.py @@ -16,8 +16,6 @@ import datetime import hashlib import stripe -from settings_local import STRIPE_SECRET_KEY - @ajax_request def user_api_key(request): diff --git a/wsgi.py b/wsgi.py index ba081cc..fd45078 100644 --- a/wsgi.py +++ b/wsgi.py @@ -11,4 +11,6 @@ import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") from django.core.wsgi import get_wsgi_application -application = get_wsgi_application() +from dj_static import Cling + +application = Cling(get_wsgi_application()) From 01d943521fd1ff76abd9f162c7a7e3ef15248290 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 11:50:04 -0400 Subject: [PATCH 07/50] Working on Heroku integration. --- README.md | 30 +++++++++++++++++++----------- accounts/views.py | 4 ++-- settings.py | 17 ++++++++++++++--- utils/templatetags/intercom.py | 4 ++-- views.py | 2 +- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 012c4e5..91f3bf9 100644 --- a/README.md +++ b/README.md @@ -2,22 +2,30 @@ This is the codebase for the website, [Snipt.net](https://snipt.net/). -It's a relatively well-kept Django app, so you shouldn't have too many problems getting a local copy running. - -**Note:** These instructions assume you already have [Git](http://git-scm.com/) and [Mercurial](http://mercurial.selenic.com/) installed. - -If you need help, visit `#snipt` on irc.freenode.net. - # Running the Django app 1. Clone the repo. 2. Setup a virtualenv. 3. `pip install -r requirements.txt` 4. `pip install --index-url https://code.stripe.com --upgrade stripe` -5. Copy settings_local-template.py to settings_local.py and edit the settings. Be sure to change the [`SESSION_COOKIE_DOMAIN`](https://github.com/nicksergeant/snipt/blob/master/settings_local-template.py#L58), or authentication won't work. -6. `python manage.py syncdb` -7. `python manage.py migrate` -8. `python manage.py runserver` -9. If you created a superuser in the syncdb step, you need to also run `python manage.py backfill_api_keys` to generate an API key for that user. +5. `python manage.py syncdb` +6. `python manage.py migrate` +7. `python manage.py runserver` +8. If you created a superuser in the syncdb step, you need to also run `python manage.py backfill_api_keys` to generate an API key for that user. + +# Deploying to Heroku + +1. Clone the repo. +2. `heroku create` +3. `heroku config:add DEBUG=True` +3. `heroku config:add INTERCOM_SECRET_KEY=` +3. `heroku config:add POSTMARK_API_KEY=` +3. `heroku config:add RAVEN_CONFIG_DSN=` +3. `heroku config:add SECRET_KEY=` +3. `heroku config:add STRIPE_SECRET_KEY=` +4. `git push heroku` +5. `heroku run pip install --index-url https://code.stripe.com --upgrade stripe` +6. `heroku run python manage.py syncdb` +7. `heroku run python manage.py migrate` Any problems / questions / bugs, [create an issue](https://github.com/nicksergeant/snipt/issues). Thanks! :) diff --git a/accounts/views.py b/accounts/views.py index 57a1c97..903b805 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -18,7 +18,7 @@ def cancel_subscription(request): if request.user.profile.stripe_id is None: return {} else: - stripe.api_key = STRIPE_SECRET_KEY + stripe.api_key = os.environ['STRIPE_SECRET_KEY'] customer = stripe.Customer.retrieve(request.user.profile.stripe_id) customer.delete() @@ -36,7 +36,7 @@ def stripe_account_details(request): if request.user.profile.stripe_id is None: return {} else: - stripe.api_key = STRIPE_SECRET_KEY + stripe.api_key = os.environ['STRIPE_SECRET_KEY'] customer = stripe.Customer.retrieve(request.user.profile.stripe_id) data = { diff --git a/settings.py b/settings.py index e3a6c0c..dbef55a 100644 --- a/settings.py +++ b/settings.py @@ -2,16 +2,20 @@ import dj_database_url, os ABSOLUTE_URL_OVERRIDES = { 'auth.user': lambda u: "/%s/" % u.username, } ACCOUNT_ACTIVATION_DAYS = 0 -ADMINS = (('Name', 'name@domain.com'),) +ADMINS = (('Nick Sergeant', 'nick@snipt.net'),) ALLOWED_HOSTS = ['*'] AUTH_PROFILE_MODULE = 'accounts.UserProfile' AUTHENTICATION_BACKENDS = ('utils.backends.EmailOrUsernameModelBackend',) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_PATH = os.path.dirname(__file__) +CSRF_COOKIE_SECURE = False DATABASES = { 'default': dj_database_url.config() } -DEBUG = True +DEBUG = os.environ['DEBUG'] +DEFAULT_FROM_EMAIL = 'nick@snipt.net' +EMAIL_BACKEND = 'postmark.django_backend.EmailBackend' HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }, } HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' +INTERCOM_SECRET_KEY = os.environ['INTERCOM_SECRET_KEY'] INTERNAL_IPS = ('127.0.0.1',) LANGUAGE_CODE = 'en-us' LOGIN_REDIRECT_URL = '/login-redirect/' @@ -21,11 +25,15 @@ MANAGERS = ADMINS MEDIA_ROOT = os.path.join(BASE_PATH, 'media/uploads') MEDIA_URL = '/media/uploads/' MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' +POSTMARK_API_KEY = os.environ['POSTMARK_API_KEY'] PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) +RAVEN_CONFIG = { 'dsn': os.environ['RAVEN_CONFIG_DSN'] } ROOT_URLCONF = 'urls' -SECRET_KEY = 'changethis' +SECRET_KEY = os.environ['SECRET_KEY'] SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') +SERVER_EMAIL = 'nick@snipt.net' SESSION_COOKIE_AGE = 15801100 +SESSION_COOKIE_SECURE = False SITE_ID = 1 STATICFILES_DIRS = (os.path.join(BASE_PATH, 'media'),) STATICFILES_FINDERS = ('django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder',) @@ -33,13 +41,16 @@ STATIC_ROOT = os.path.join(BASE_PATH, 'static') STATIC_URL = '/static/' TASTYPIE_CANNED_ERROR = "There was an error with your request. The site developers have a record of this error, please email api@snipt.net and we'll help you out." TEMPLATE_DIRS = (os.path.join(PROJECT_PATH, 'templates')) +TEMPLATE_DEBUG = DEBUG TIME_ZONE = 'America/New_York' +USE_HTTPS = False USE_I18N = True USE_L10N = True USE_TZ = True INSTALLED_APPS = ( 'gunicorn', + 'raven.contrib.django.raven_compat', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.humanize', diff --git a/utils/templatetags/intercom.py b/utils/templatetags/intercom.py index ced4efa..25dd15a 100644 --- a/utils/templatetags/intercom.py +++ b/utils/templatetags/intercom.py @@ -1,9 +1,9 @@ from django import template -import hmac, hashlib +import hmac, hashlib, os register = template.Library() @register.filter def intercom_sha_256(user_id): - return hmac.new(INTERCOM_SECRET_KEY, str(user_id), digestmod=hashlib.sha256).hexdigest() + return hmac.new(os.environ['INTERCOM_SECRET_KEY'], str(user_id), digestmod=hashlib.sha256).hexdigest() diff --git a/views.py b/views.py index e8c78b6..7ac17d7 100644 --- a/views.py +++ b/views.py @@ -101,7 +101,7 @@ def pro_complete(request): if request.method == 'POST': token = request.POST['token'] - stripe.api_key = STRIPE_SECRET_KEY + stripe.api_key = os.environ['STRIPE_SECRET_KEY'] customer = stripe.Customer.create(email=request.user.email, card=token) From dc054cebd9469ee7e8c7a66fb22b88ca09bbecd3 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 14:11:23 -0400 Subject: [PATCH 08/50] Working on Heroku integration. --- accounts/views.py | 4 ++-- settings.py | 27 +++++++++++++++++++++------ utils/templatetags/intercom.py | 2 +- views.py | 2 +- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/accounts/views.py b/accounts/views.py index 903b805..572c974 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -18,7 +18,7 @@ def cancel_subscription(request): if request.user.profile.stripe_id is None: return {} else: - stripe.api_key = os.environ['STRIPE_SECRET_KEY'] + stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', '') customer = stripe.Customer.retrieve(request.user.profile.stripe_id) customer.delete() @@ -36,7 +36,7 @@ def stripe_account_details(request): if request.user.profile.stripe_id is None: return {} else: - stripe.api_key = os.environ['STRIPE_SECRET_KEY'] + stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', '') customer = stripe.Customer.retrieve(request.user.profile.stripe_id) data = { diff --git a/settings.py b/settings.py index dbef55a..f1c31e7 100644 --- a/settings.py +++ b/settings.py @@ -1,5 +1,21 @@ import dj_database_url, os +if 'DATABASE_URL' in os.environ: + DATABASES = { + 'default': dj_database_url.config() + } +else: + DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'snipt', + 'USER': '', + 'PASSWORD': '', + 'HOST': 'localhost', + 'PORT': '' + } + } + ABSOLUTE_URL_OVERRIDES = { 'auth.user': lambda u: "/%s/" % u.username, } ACCOUNT_ACTIVATION_DAYS = 0 ADMINS = (('Nick Sergeant', 'nick@snipt.net'),) @@ -9,13 +25,12 @@ AUTHENTICATION_BACKENDS = ('utils.backends.EmailOrUsernameModelBackend',) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_PATH = os.path.dirname(__file__) CSRF_COOKIE_SECURE = False -DATABASES = { 'default': dj_database_url.config() } -DEBUG = os.environ['DEBUG'] +DEBUG = os.environ.get('DEBUG', False) DEFAULT_FROM_EMAIL = 'nick@snipt.net' EMAIL_BACKEND = 'postmark.django_backend.EmailBackend' HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }, } HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' -INTERCOM_SECRET_KEY = os.environ['INTERCOM_SECRET_KEY'] +INTERCOM_SECRET_KEY = os.environ.get('INTERCOM_SECRET_KEY', '') INTERNAL_IPS = ('127.0.0.1',) LANGUAGE_CODE = 'en-us' LOGIN_REDIRECT_URL = '/login-redirect/' @@ -25,11 +40,11 @@ MANAGERS = ADMINS MEDIA_ROOT = os.path.join(BASE_PATH, 'media/uploads') MEDIA_URL = '/media/uploads/' MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' -POSTMARK_API_KEY = os.environ['POSTMARK_API_KEY'] +POSTMARK_API_KEY = os.environ.get('POSTMARK_API_KEY', '') PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) -RAVEN_CONFIG = { 'dsn': os.environ['RAVEN_CONFIG_DSN'] } +RAVEN_CONFIG = { 'dsn': os.environ.get('RAVEN_CONFIG_DSN', '') } ROOT_URLCONF = 'urls' -SECRET_KEY = os.environ['SECRET_KEY'] +SECRET_KEY = os.environ.get('SECRET_KEY', 'changeme') SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SERVER_EMAIL = 'nick@snipt.net' SESSION_COOKIE_AGE = 15801100 diff --git a/utils/templatetags/intercom.py b/utils/templatetags/intercom.py index 25dd15a..b1bdade 100644 --- a/utils/templatetags/intercom.py +++ b/utils/templatetags/intercom.py @@ -6,4 +6,4 @@ register = template.Library() @register.filter def intercom_sha_256(user_id): - return hmac.new(os.environ['INTERCOM_SECRET_KEY'], str(user_id), digestmod=hashlib.sha256).hexdigest() + return hmac.new(os.environ.get('INTERCOM_SECRET_KEY', ''), str(user_id), digestmod=hashlib.sha256).hexdigest() diff --git a/views.py b/views.py index 7ac17d7..fb7f7a0 100644 --- a/views.py +++ b/views.py @@ -101,7 +101,7 @@ def pro_complete(request): if request.method == 'POST': token = request.POST['token'] - stripe.api_key = os.environ['STRIPE_SECRET_KEY'] + stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', '') customer = stripe.Customer.create(email=request.user.email, card=token) From 5faf1b1fb7e425d2c3863f3ef037bf5c1b953013 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 14:12:45 -0400 Subject: [PATCH 09/50] Working on Heroku integration. --- settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/settings.py b/settings.py index f1c31e7..91ccc3b 100644 --- a/settings.py +++ b/settings.py @@ -46,6 +46,7 @@ RAVEN_CONFIG = { 'dsn': os.environ.get('RAVEN_CONFIG_DSN', '') } ROOT_URLCONF = 'urls' SECRET_KEY = os.environ.get('SECRET_KEY', 'changeme') SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') +SEND_BROKEN_LINK_EMAILS = False SERVER_EMAIL = 'nick@snipt.net' SESSION_COOKIE_AGE = 15801100 SESSION_COOKIE_SECURE = False From 7cedbef7cb868fec393924159ff2ada14778c6a9 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 14:16:12 -0400 Subject: [PATCH 10/50] Working on Heroku integration. --- settings.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/settings.py b/settings.py index 91ccc3b..bae3259 100644 --- a/settings.py +++ b/settings.py @@ -4,6 +4,12 @@ if 'DATABASE_URL' in os.environ: DATABASES = { 'default': dj_database_url.config() } + HAYSTACK_CONNECTIONS = { + 'default': { + 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', + 'URL': os.environ.get('BONSAI_URL', ''), + }, + } else: DATABASES = { 'default': { @@ -15,6 +21,11 @@ else: 'PORT': '' } } + HAYSTACK_CONNECTIONS = { + 'default': { + 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', + }, + } ABSOLUTE_URL_OVERRIDES = { 'auth.user': lambda u: "/%s/" % u.username, } ACCOUNT_ACTIVATION_DAYS = 0 @@ -28,7 +39,6 @@ CSRF_COOKIE_SECURE = False DEBUG = os.environ.get('DEBUG', False) DEFAULT_FROM_EMAIL = 'nick@snipt.net' EMAIL_BACKEND = 'postmark.django_backend.EmailBackend' -HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }, } HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor' INTERCOM_SECRET_KEY = os.environ.get('INTERCOM_SECRET_KEY', '') INTERNAL_IPS = ('127.0.0.1',) From 8b47cd27cc68c89b1e11d7927edf7b91bfd4d485 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 14:36:07 -0400 Subject: [PATCH 11/50] Index name for Haystack. --- README.md | 23 +++++++++++++---------- settings.py | 7 ++++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 91f3bf9..b03e334 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,18 @@ This is the codebase for the website, [Snipt.net](https://snipt.net/). 1. Clone the repo. 2. `heroku create` -3. `heroku config:add DEBUG=True` -3. `heroku config:add INTERCOM_SECRET_KEY=` -3. `heroku config:add POSTMARK_API_KEY=` -3. `heroku config:add RAVEN_CONFIG_DSN=` -3. `heroku config:add SECRET_KEY=` -3. `heroku config:add STRIPE_SECRET_KEY=` -4. `git push heroku` -5. `heroku run pip install --index-url https://code.stripe.com --upgrade stripe` -6. `heroku run python manage.py syncdb` -7. `heroku run python manage.py migrate` +3. `heroku addons:add heroku-postgresql:standard-0` +4. `heroku addons:add bonsai` +5. `heroku config:add DEBUG=False` +6. `heroku config:add INTERCOM_SECRET_KEY=` +7. `heroku config:add POSTMARK_API_KEY=` +8. `heroku config:add RAVEN_CONFIG_DSN=` +9. `heroku config:add SECRET_KEY=` +10. `heroku config:add STRIPE_SECRET_KEY=` +11. `heroku config:add USE_SSL=False` +12. `git push heroku` +13. `heroku run pip install --index-url https://code.stripe.com --upgrade stripe` +14. `heroku run python manage.py syncdb` +15. `heroku run python manage.py migrate` Any problems / questions / bugs, [create an issue](https://github.com/nicksergeant/snipt/issues). Thanks! :) diff --git a/settings.py b/settings.py index bae3259..bc9bb95 100644 --- a/settings.py +++ b/settings.py @@ -7,6 +7,7 @@ if 'DATABASE_URL' in os.environ: HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', + 'INDEX_NAME': 'snipt', 'URL': os.environ.get('BONSAI_URL', ''), }, } @@ -35,7 +36,7 @@ AUTH_PROFILE_MODULE = 'accounts.UserProfile' AUTHENTICATION_BACKENDS = ('utils.backends.EmailOrUsernameModelBackend',) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_PATH = os.path.dirname(__file__) -CSRF_COOKIE_SECURE = False +CSRF_COOKIE_SECURE = os.environ.get('USE_SSL', False) DEBUG = os.environ.get('DEBUG', False) DEFAULT_FROM_EMAIL = 'nick@snipt.net' EMAIL_BACKEND = 'postmark.django_backend.EmailBackend' @@ -59,7 +60,7 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SEND_BROKEN_LINK_EMAILS = False SERVER_EMAIL = 'nick@snipt.net' SESSION_COOKIE_AGE = 15801100 -SESSION_COOKIE_SECURE = False +SESSION_COOKIE_SECURE = os.environ.get('USE_SSL', False) SITE_ID = 1 STATICFILES_DIRS = (os.path.join(BASE_PATH, 'media'),) STATICFILES_FINDERS = ('django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder',) @@ -69,7 +70,7 @@ TASTYPIE_CANNED_ERROR = "There was an error with your request. The site develope TEMPLATE_DIRS = (os.path.join(PROJECT_PATH, 'templates')) TEMPLATE_DEBUG = DEBUG TIME_ZONE = 'America/New_York' -USE_HTTPS = False +USE_HTTPS = os.environ.get('USE_SSL', False) USE_I18N = True USE_L10N = True USE_TZ = True From 7c23bed425b83d143d14d59c489075fc82905dae Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 14:43:53 -0400 Subject: [PATCH 12/50] Index name for Haystack. --- settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.py b/settings.py index bc9bb95..7943e62 100644 --- a/settings.py +++ b/settings.py @@ -7,7 +7,7 @@ if 'DATABASE_URL' in os.environ: HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', - 'INDEX_NAME': 'snipt', + 'INDEX_NAME': os.environ.get('BONSAI_INDEX', ''), 'URL': os.environ.get('BONSAI_URL', ''), }, } From 6f364cc067de02f901c6d7aac71828c4fa636783 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 14:49:17 -0400 Subject: [PATCH 13/50] Index name for Haystack. --- settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.py b/settings.py index 7943e62..bc9bb95 100644 --- a/settings.py +++ b/settings.py @@ -7,7 +7,7 @@ if 'DATABASE_URL' in os.environ: HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', - 'INDEX_NAME': os.environ.get('BONSAI_INDEX', ''), + 'INDEX_NAME': 'snipt', 'URL': os.environ.get('BONSAI_URL', ''), }, } From 319aff67808a10a996f05015cdbb78c007ee8691 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 14:52:03 -0400 Subject: [PATCH 14/50] Index name for Haystack. --- settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.py b/settings.py index bc9bb95..9b61506 100644 --- a/settings.py +++ b/settings.py @@ -7,7 +7,7 @@ if 'DATABASE_URL' in os.environ: HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', - 'INDEX_NAME': 'snipt', + 'INDEX_NAME': 'snipt-net', 'URL': os.environ.get('BONSAI_URL', ''), }, } From ce7670fb9c5d722ee5b8734a92a2026bc854bafc Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 14:55:33 -0400 Subject: [PATCH 15/50] Index name for Haystack. --- settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.py b/settings.py index 9b61506..54b569b 100644 --- a/settings.py +++ b/settings.py @@ -7,7 +7,7 @@ if 'DATABASE_URL' in os.environ: HAYSTACK_CONNECTIONS = { 'default': { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', - 'INDEX_NAME': 'snipt-net', + 'INDEX_NAME': 'cherry-3928285', 'URL': os.environ.get('BONSAI_URL', ''), }, } From d144fabb650d6d1e78f5ac035b0b1c4a5407ba98 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 19:01:52 -0400 Subject: [PATCH 16/50] Cookie domain for Heroku. --- settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/settings.py b/settings.py index 54b569b..3dedbff 100644 --- a/settings.py +++ b/settings.py @@ -36,6 +36,7 @@ AUTH_PROFILE_MODULE = 'accounts.UserProfile' AUTHENTICATION_BACKENDS = ('utils.backends.EmailOrUsernameModelBackend',) BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_PATH = os.path.dirname(__file__) +CSRF_COOKIE_DOMAIN = 'snipt-net.herokuapp.com' CSRF_COOKIE_SECURE = os.environ.get('USE_SSL', False) DEBUG = os.environ.get('DEBUG', False) DEFAULT_FROM_EMAIL = 'nick@snipt.net' From 855d82674d93bf5752f84d0384590fd292c065f9 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 19:20:54 -0400 Subject: [PATCH 17/50] Testing search. --- settings.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/settings.py b/settings.py index 3dedbff..3dc5eac 100644 --- a/settings.py +++ b/settings.py @@ -6,9 +6,7 @@ if 'DATABASE_URL' in os.environ: } HAYSTACK_CONNECTIONS = { 'default': { - 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', - 'INDEX_NAME': 'cherry-3928285', - 'URL': os.environ.get('BONSAI_URL', ''), + 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', }, } else: From 731b1b9ebe1847590ce7b81fa92067bd9c438216 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 19:26:16 -0400 Subject: [PATCH 18/50] Working on ES integration for Heroku. --- settings.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/settings.py b/settings.py index 3dc5eac..29415b6 100644 --- a/settings.py +++ b/settings.py @@ -1,14 +1,26 @@ import dj_database_url, os +from urlparse import urlparse + + if 'DATABASE_URL' in os.environ: - DATABASES = { - 'default': dj_database_url.config() - } + + DATABASES = { 'default': dj_database_url.config() } + + es = urlparse(os.environ.get('SEARCHBOX_URL') or 'http://127.0.0.1:9200/') + port = es.port or 80 + HAYSTACK_CONNECTIONS = { 'default': { - 'ENGINE': 'haystack.backends.simple_backend.SimpleEngine', + 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', + 'URL': es.scheme + '://' + es.hostname + ':' + str(port), + 'INDEX_NAME': 'snipts', }, } + + if es.username: + HAYSTACK_CONNECTIONS['default']['KWARGS'] = {"http_auth": es.username + ':' + es.password} + else: DATABASES = { 'default': { From d9a7c4f2fe151fdc61a1b3a9cc1c06fe6417bc07 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 19:29:56 -0400 Subject: [PATCH 19/50] Working on ES integration for Heroku. --- settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.py b/settings.py index 29415b6..ff8858d 100644 --- a/settings.py +++ b/settings.py @@ -7,7 +7,7 @@ if 'DATABASE_URL' in os.environ: DATABASES = { 'default': dj_database_url.config() } - es = urlparse(os.environ.get('SEARCHBOX_URL') or 'http://127.0.0.1:9200/') + es = urlparse(os.environ.get('SEARCHBOX_SSL_URL') or 'http://127.0.0.1:9200/') port = es.port or 80 HAYSTACK_CONNECTIONS = { From c56161986e4eab957cb1e2d79398b33f0a9fc4a1 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Mon, 20 Oct 2014 20:01:35 -0400 Subject: [PATCH 20/50] S3 static URLs. --- .../blogs/themes/pro-adams/base.html | 14 +-- media/css/blog-themes/default/style.css | 2 +- media/css/blog-themes/default/style.scss | 4 +- media/css/blog-themes/pro-adams/style.css | 2 +- media/css/blog-themes/pro-adams/style.scss | 2 +- media/css/pro.css | 2 +- media/css/snipt.css | 2 +- media/js/snipt-all.min.js | 4 +- media/js/src/account.js | 8 +- media/js/src/account.min.js | 2 +- media/js/src/application.js | 30 +++--- media/js/src/application.min.js | 2 +- snipts/templates/snipts/raw.html | 4 +- .../templates/snipts/snipt-js-template.html | 2 +- snipts/templates/snipts/snipt-list.html | 2 +- templates/base.html | 96 +++++++++---------- templates/homepage.html | 2 +- templates/pro.html | 8 +- urls.py | 4 - 19 files changed, 94 insertions(+), 98 deletions(-) diff --git a/blogs/templates/blogs/themes/pro-adams/base.html b/blogs/templates/blogs/themes/pro-adams/base.html index ecda596..4d93d87 100644 --- a/blogs/templates/blogs/themes/pro-adams/base.html +++ b/blogs/templates/blogs/themes/pro-adams/base.html @@ -27,15 +27,15 @@ {% endif %} {% if debug %} - - - - + + + + {% else %} - + {% endif %} - + {% if custom_css %}