Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/sb/settings'
Browse files Browse the repository at this point in the history
* origin/sb/settings:
  put debug toolbar dependency to common requirements so one can use DEBUG=True on the server.
  update prerequisites
  try new primetime validator
  activate only staff middleware for production as well, remove robot instructions
  fix manage.py test
  limit redis version
  add local flake8, import ugettext_lazy for settings
  Feedback von mk, Fehlerbehebungen
  fix base dir path
  settings aufteilen
  • Loading branch information
matthiask committed Sep 1, 2015
2 parents 871de77 + 46c30a2 commit c2dc346
Show file tree
Hide file tree
Showing 19 changed files with 165 additions and 66 deletions.
4 changes: 3 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ Submission guidelines
=====================

If you are creating a pull request, fork the repository and make any changes
on the ``develop`` branch.
in your own feature branch.

Write and run tests.
4 changes: 2 additions & 2 deletions docs/prerequisites.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ An installation of Xcode including command line tools is required::

It is recommended to use Homebrew_ for all additional dependencies::

brew install gettext
brew install libxslt
brew install libxml2
brew install jpeg
brew install freetype
brew install libpng
brew install libtiff
brew install node
brew install iojs
brew install postgresql
brew install redis
brew install sqlite
Expand Down Expand Up @@ -78,6 +77,7 @@ is very much recommended to use pipsi_ for their installation. Instructions
for installing pipsi_ can be found on
`Github <https://github.com/mitsuhiko/pipsi>`_::

pip install virtualenv
pipsi install fabric
pipsi install flake8

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import django_cache_url
from django.utils.translation import ugettext_lazy as _
import os
import sys

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DEBUG = any(r in sys.argv for r in ('runserver', 'shell', 'dbshell'))
TESTING = any(r in sys.argv for r in ('test',))
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(
os.path.abspath(__file__)))
)

DEBUG = False
TESTING = False
TEMPLATE_DEBUG = DEBUG

ADMINS = (
Expand Down Expand Up @@ -54,13 +54,10 @@
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

if not DEBUG:
TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)),
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)

STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
Expand All @@ -76,7 +73,6 @@
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'${PROJECT_NAME}.middleware.OnlyStaffMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
Expand Down Expand Up @@ -246,39 +242,3 @@ def elephantblog_category_url_app(self):
RAVEN_CONFIG = {
'dsn': env('SENTRY_DSN'),
}

if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
LOGGING['loggers'].update({
# Uncomment to dump SQL statements.
# 'django.db.backends': {
# 'level': 'DEBUG',
# 'handlers': ['console'],
# 'propagate': False,
# },
'django.request': {
'level': 'DEBUG',
'handlers': ['console'], # Dump exceptions to the console.
'propagate': False,
},
'${PROJECT_NAME}': {
'level': 'DEBUG',
'handlers': ['console'], # Dump app logs to the console.
'propagate': False,
},
})
try:
__import__('debug_toolbar')
except ImportError:
pass
else:
INSTALLED_APPS += (
'debug_toolbar.apps.DebugToolbarConfig',
)
INTERNAL_IPS = ('127.0.0.1',)
MIDDLEWARE_CLASSES = (
'debug_toolbar.middleware.DebugToolbarMiddleware',
) + MIDDLEWARE_CLASSES
DEBUG_TOOLBAR_PATCH_SETTINGS = False

THUMBNAIL_DEBUG = True
42 changes: 42 additions & 0 deletions fbox/$PROJECT_NAME/settings/local.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# coding: utf-8
"""
Entry point for local development.
"""
from __future__ import absolute_import, unicode_literals
from .common import * # noqa

DEBUG = True
TEMPLATE_DEBUG = True

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
LOGGING['loggers'].update({
# Uncomment to dump SQL statements.
# 'django.db.backends': {
# 'level': 'DEBUG',
# 'handlers': ['console'],
# 'propagate': False,
# },
'django.request': {
'level': 'DEBUG',
'handlers': ['console'], # Dump exceptions to the console.
'propagate': False,
},
'${PROJECT_NAME}': {
'level': 'DEBUG',
'handlers': ['console'], # Dump app logs to the console.
'propagate': False,
},
})

INSTALLED_APPS += (
'debug_toolbar.apps.DebugToolbarConfig',
)
INTERNAL_IPS = ('127.0.0.1',)
MIDDLEWARE_CLASSES = (
'debug_toolbar.middleware.DebugToolbarMiddleware',
) + MIDDLEWARE_CLASSES
DEBUG_TOOLBAR_PATCH_SETTINGS = False

THUMBNAIL_DEBUG = True

RAVEN_CONFIG = {'dsn': ''}
15 changes: 15 additions & 0 deletions fbox/$PROJECT_NAME/settings/production.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# coding: utf-8
"""
Entry point for the production site.
"""
from __future__ import absolute_import, unicode_literals
from .common import * # noqa

TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', TEMPLATE_LOADERS),
)

# TODO: Remove before flight
MIDDLEWARE_CLASSES += (
'${PROJECT_NAME}.middleware.OnlyStaffMiddleware',
)
15 changes: 15 additions & 0 deletions fbox/$PROJECT_NAME/settings/staging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# coding: utf-8
"""
Entry point for the staging site.
"""

from __future__ import absolute_import, unicode_literals
from .common import * # noqa

TEMPLATE_LOADERS = (
('django.template.loaders.cached.Loader', TEMPLATE_LOADERS),
)

MIDDLEWARE_CLASSES += (
'${PROJECT_NAME}.middleware.OnlyStaffMiddleware',
)
35 changes: 35 additions & 0 deletions fbox/$PROJECT_NAME/settings/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# coding: utf-8
""" Entry point for unittests """
from __future__ import absolute_import, unicode_literals
from .common import * # noqa

# IN-MEMORY TEST DATABASE
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:'
},
}

PASSWORD_HASHERS = (
'django.contrib.auth.hashers.MD5PasswordHasher',
)
TESTING = True
LOGGING['loggers'].update({
'': {
'level': 'WARNING',
'handlers': ['console'],
},
'django.request': {
'level': 'ERROR',
'handlers': ['console'], # Dump exceptions to the console.
'propagate': False,
},
'${PROJECT_NAME}': {
'level': 'DEBUG',
'handlers': ['console'], # Dump app logs to the console.
'propagate': False,
},
})

RAVEN_CONFIG = {'dsn': ''}
1 change: 0 additions & 1 deletion fbox/$PROJECT_NAME/templates/site_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="robots" content="index,follow,noodp">

<link rel="shortcut icon" href="{% static '${PROJECT_NAME}/images/feincms.png' %}">

Expand Down
14 changes: 12 additions & 2 deletions fbox/fabfile/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,21 @@ def primetime():
" -- %(box_project_name)s")

step('Checking local settings on server...')

# Shell magic:
# Import production settings and print out some variables.
# Parse the output and compare it.

with cd('%(box_domain)s'):
output = run(
"DJANGO_SETTINGS_MODULE=%(box_project_name)s.settings"
"DJANGO_SETTINGS_MODULE=%(box_project_name)s.settings.production"
" venv/bin/python -c \""
"from django.conf import settings as s;"
"print('fd:%%s\\ndsn:%%s\\nsso:%%s\\ndebug:%%s\\nsk:%%s' %% ("
"print('fd:%%s\\ndsn:%%s\\nsso:%%s\\nstaff:%%s\\ndebug:%%s\\nsk:%%s' %% ("
"getattr(s, 'FORCE_DOMAIN', '-'),"
"getattr(s, 'RAVEN_CONFIG', {}).get('dsn', ''),"
"bool(getattr(s, 'DJANGO_ADMIN_SSO_ADD_LOGIN_BUTTON', False)),"
"bool('${PROJECT_NAME}.middleware.OnlyStaffMiddleware' in s.MIDDLEWARE_CLASSES),"
"bool(s.DEBUG),"
"s.SECRET_KEY,"
"))\"" % env, quiet=True).strip()
Expand All @@ -96,6 +102,10 @@ def primetime():
'Warning: SSO authentication for the administration is not'
' configured.'))

if output['staff'] == 'True':
puts(red(
'OnlyStaffMiddleware is still activated.'))

if output['debug'] == 'True':
puts(red(
'Error: DEBUG = True!?', bold=True))
Expand Down
19 changes: 18 additions & 1 deletion fbox/fabfile/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
"""
This file contains the configuration for the fabric scripts.
The scripts support multiple environments.
Within the fabric commands string formatting is applied with the env object
as argument.
The environment specific values are available as box_<key>
e.g. '%(box_branch)s'.
Usage::
run('git clone -b %(box_branch)s %(box_repository_url)s %(box_domain)s')
"""

from __future__ import unicode_literals

from fabric.api import env

# env.box_environment contains the currently active environment.

# Default values available in all environments
env.box_project_name = '${PROJECT_NAME}'
env.box_domain = '${DOMAIN}'
env.box_database_local = '${DOMAIN_SLUG}'
Expand All @@ -12,6 +28,7 @@
# Remove this for multi-env support
env.box_hardwired_environment = 'production'

# Environment specific values.
env.box_environments = {
'production': {
'shortcut': 'p',
Expand All @@ -20,7 +37,7 @@
'servers': [
'${SERVER}',
],
'remote': 'production',
'remote': 'production', # git remote alias for the server.
'repository': '${DOMAIN_SLUG}',
'database': '${DOMAIN_SLUG}',
},
Expand Down
1 change: 1 addition & 0 deletions fbox/fabfile/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def init_bitbucket():
@task
@require_env
def add_remote():
""" Add a server repository as git remote """
env.box_idx = '' if len(env.hosts) < 2 else '-%d' % (
env.hosts.index(env.host_string) + 1)

Expand Down
1 change: 1 addition & 0 deletions fbox/fabfile/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def create_dotenv():
with open('.env', 'w') as f:
env.box_secret_key = get_random_string(50)
f.write('''\
DJANGO_SETTINGS_MODULE=%(box_project_name)s.settings.local
DATABASE_URL=postgres://localhost:5432/%(box_database_local)s
CACHE_URL=hiredis://localhost:6379/1/%(box_database_local)s
SECRET_KEY=%(box_secret_key)s
Expand Down
4 changes: 1 addition & 3 deletions fbox/fabfile/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def create_database_and_dotenv():
with cd('%(box_domain)s'):

put(StringIO('''\
DJANGO_SETTINGS_MODULE=%(box_project_name)s.settings.%(box_environment)s
DATABASE_URL=postgres://%(box_database)s:%(box_database_pw)s\
@localhost:5432/%(box_database)s
CACHE_URL=hiredis://localhost:6379/1/%(box_database)s
Expand All @@ -88,9 +89,6 @@ def create_database_and_dotenv():
DJANGO_ADMIN_SSO_OAUTH_CLIENT_SECRET=%(box_oauth2_client_secret)s
ALLOWED_HOSTS=['%(box_domain)s', '.%(box_domain)s', '.%(host_string_host)s']
# Do not forget to allow robots to index the site when going live!
# - %(box_project_name)s/templates/base.html: Change "noindex" to "index"
# - htdocs/robots.txt: Remove the "Disallow: /" line
# FORCE_DOMAIN = www.%(box_domain)s
''' % dict(env, host_string_host=env.host_string.split('@')[-1])), '.env')

Expand Down
3 changes: 1 addition & 2 deletions fbox/htdocs/robots.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# www.robotstxt.org/
# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449
# TODO Remove "Disallow" when going live!

User-agent: *
Disallow: /
7 changes: 6 additions & 1 deletion fbox/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

if __name__ == "__main__":
env.read_dotenv()
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "${PROJECT_NAME}.settings")
if 'test' in sys.argv:
os.environ['DJANGO_SETTINGS_MODULE'] = '${PROJECT_NAME}.settings.test'
else:
os.environ.setdefault("DJANGO_SETTINGS_MODULE",
env.env("DJANGO_SETTINGS_MODULE",
"${PROJECT_NAME}.settings.local"))

from django.core.management import execute_from_command_line

Expand Down
3 changes: 2 additions & 1 deletion fbox/requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ dj-database-url==0.3.0
django-admin-sso2==2.0.0
django-cache-url==0.8.0
django-compressor==1.4
django_debug_toolbar==1.3
django-flat-theme==0.9.3
django-mptt==0.7.1
django-redis==3.8.3
django-redis==3.8.4,<4.0
feedparser==5.1.3
FeinCMS==1.11.0
feincms-cleanse==6
Expand Down
1 change: 0 additions & 1 deletion fbox/requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-r common.txt
coverage==3.7.1
django_debug_toolbar==1.3
factory-boy==2.5.1
pip-tools==0.3.6
flake8==2.4.1
4 changes: 2 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def server(string):
'DESTINATION': args.destination,
'DOMAIN': args.domain,
'DOMAIN_SLUG': re.sub(r'[^\w]+', '_', args.domain),
'NICE_NAME': args.nice_name,
'PROJECT_NAME': args.project_name,
'NICE_NAME': args.nice_name, # used for the title
'PROJECT_NAME': args.project_name, # the Django project name
'SERVER': args.server,
'USER_NAME': read_output(
['git', 'config', 'user.name'],
Expand Down

0 comments on commit c2dc346

Please sign in to comment.