From 59f89307850b92d65a856c5caf50fb30f05cc5e9 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 15 May 2015 17:00:56 +0200 Subject: [PATCH 01/20] First dockerfile attempt --- deployment/docker/standalone/Dockerfile | 23 +++++++++++++++++++ deployment/docker/standalone/Makefile | 2 ++ .../docker/standalone/gunicorn_starter.bash | 7 ++++++ deployment/docker/standalone/src | 1 + deployment/docker/standalone/supervisord.conf | 5 ++++ 5 files changed, 38 insertions(+) create mode 100644 deployment/docker/standalone/Dockerfile create mode 100644 deployment/docker/standalone/Makefile create mode 100644 deployment/docker/standalone/gunicorn_starter.bash create mode 120000 deployment/docker/standalone/src create mode 100644 deployment/docker/standalone/supervisord.conf diff --git a/deployment/docker/standalone/Dockerfile b/deployment/docker/standalone/Dockerfile new file mode 100644 index 0000000000..6dc6f99eab --- /dev/null +++ b/deployment/docker/standalone/Dockerfile @@ -0,0 +1,23 @@ +FROM debian:jessie + +RUN apt-get update && apt-get install -y supervisor python3 git python3-pip \ + libxml2-dev libxslt1-dev python-dev python-virtualenv locales libffi-dev \ + build-essential python3-dev --no-install-recommends + +RUN dpkg-reconfigure locales && \ + locale-gen C.UTF-8 && \ + /usr/sbin/update-locale LANG=C.UTF-8 +ENV LC_ALL C.UTF-8 + +RUN apt-get clean && rm -rf /var/lib/apt/lists/* + +ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf +ADD gunicorn_starter.bash /gunicorn_starter.bash +ADD src /src +WORKDIR /src +RUN pip3 install -r requirements.txt +RUN pip3 install gunicorn + +EXPOSE 80 +CMD ["/usr/bin/supervisord"] + diff --git a/deployment/docker/standalone/Makefile b/deployment/docker/standalone/Makefile new file mode 100644 index 0000000000..9444b355ef --- /dev/null +++ b/deployment/docker/standalone/Makefile @@ -0,0 +1,2 @@ +main: + tar ch --exclude=_static --exclude=htmlcov --exclude=db.sqlite3 . | docker build -t test - diff --git a/deployment/docker/standalone/gunicorn_starter.bash b/deployment/docker/standalone/gunicorn_starter.bash new file mode 100644 index 0000000000..d4aff98c31 --- /dev/null +++ b/deployment/docker/standalone/gunicorn_starter.bash @@ -0,0 +1,7 @@ +#!/bin/bash +cd /src +export DJANGO_SETTINGS_MODULE=pretix.settings +gunicorn \ + -b '0.0.0.0:80' \ + -w 3 --max-requests 1000 --max-requests-jitter 50 \ + pretix.wsgi diff --git a/deployment/docker/standalone/src b/deployment/docker/standalone/src new file mode 120000 index 0000000000..dabb0e15a9 --- /dev/null +++ b/deployment/docker/standalone/src @@ -0,0 +1 @@ +../../../src \ No newline at end of file diff --git a/deployment/docker/standalone/supervisord.conf b/deployment/docker/standalone/supervisord.conf new file mode 100644 index 0000000000..a8e43c7218 --- /dev/null +++ b/deployment/docker/standalone/supervisord.conf @@ -0,0 +1,5 @@ +[supervisord] +nodaemon=true + +[program:gunicorn] +command=/bin/bash gunicorn_starter.bash From d1473b99583d6d04d84a1bc7725a9151a40d5074 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 15 May 2015 22:54:12 +0200 Subject: [PATCH 02/20] Pin version requirements, add more tasks to makefile, specify python version in manage.py shebang --- src/Makefile | 13 ++++++++++--- src/manage.py | 2 +- src/requirements/banktransfer.txt | 2 +- src/requirements/dev.txt | 2 +- src/requirements/paypal.txt | 2 +- src/requirements/production.txt | 10 +++++----- src/requirements/stripe.txt | 2 +- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Makefile b/src/Makefile index 75067417f0..d79277f041 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,14 @@ -all: localecompile +all: localecompile staticfiles +production: localecompile staticfiles compress localecompile: - django-admin compilemessages + ./manage.py compilemessages localegen: - django-admin makemessages --all + ./manage.py makemessages --all + +staticfiles: + ./manage.py collectstatic --noinput + +compress: + ./manage.py compress diff --git a/src/manage.py b/src/manage.py index 4dbadaca86..ff13d7d950 100755 --- a/src/manage.py +++ b/src/manage.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import os import sys diff --git a/src/requirements/banktransfer.txt b/src/requirements/banktransfer.txt index c60139b830..9bbf199d32 100644 --- a/src/requirements/banktransfer.txt +++ b/src/requirements/banktransfer.txt @@ -1,2 +1,2 @@ -chardet +chardet>=2.3,<3 diff --git a/src/requirements/dev.txt b/src/requirements/dev.txt index 2f51e53d24..1b891edfb0 100644 --- a/src/requirements/dev.txt +++ b/src/requirements/dev.txt @@ -1 +1 @@ -django-debug-toolbar>=1.3.0 +django-debug-toolbar>=1.3.0,<2.0 diff --git a/src/requirements/paypal.txt b/src/requirements/paypal.txt index 19b7672089..5bf92ed3b6 100644 --- a/src/requirements/paypal.txt +++ b/src/requirements/paypal.txt @@ -1,2 +1,2 @@ -paypalrestsdk +paypalrestsdk>=1.9,<1.10,<2.0 diff --git a/src/requirements/production.txt b/src/requirements/production.txt index dc61324746..46b6d34eb7 100644 --- a/src/requirements/production.txt +++ b/src/requirements/production.txt @@ -1,12 +1,12 @@ # Functional requirements Django==1.8.1 -python-dateutil +python-dateutil>=2.4,<2.5 pytz -django-bootstrap3 +django-bootstrap3>=5.4,<5.5 -e git+https://github.com/pretix/django-formset-js.git@master#egg=django-formset-js -e git+https://github.com/pretix/cleanerversion.git@pretix#egg=cleanerversion -django-compressor -reportlab +django-compressor>=1.5,<2.0 +reportlab>=3.1.44,<3.2 -e git+https://github.com/pretix/PyPDF2.git@pretix#egg=PyPDF2 # Deployment / static file compilation requirements @@ -14,4 +14,4 @@ BeautifulSoup4 html5lib slimit lxml -dj-static +dj-static==0.0.6 diff --git a/src/requirements/stripe.txt b/src/requirements/stripe.txt index 599f08002d..51f26a42aa 100644 --- a/src/requirements/stripe.txt +++ b/src/requirements/stripe.txt @@ -1,2 +1,2 @@ -stripe +stripe>=1.22,<1.23 From 2a6b1b7b564aa8dd08212b2e4ca7348b21a8b71b Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 15 May 2015 23:10:22 +0200 Subject: [PATCH 03/20] Dockerfile now basically works --- deployment/docker/standalone/Dockerfile | 14 +++++++++++++- deployment/docker/standalone/local_settings.py | 5 +++++ deployment/docker/standalone/supervisord.conf | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 deployment/docker/standalone/local_settings.py diff --git a/deployment/docker/standalone/Dockerfile b/deployment/docker/standalone/Dockerfile index 6dc6f99eab..9f708d3435 100644 --- a/deployment/docker/standalone/Dockerfile +++ b/deployment/docker/standalone/Dockerfile @@ -2,7 +2,13 @@ FROM debian:jessie RUN apt-get update && apt-get install -y supervisor python3 git python3-pip \ libxml2-dev libxslt1-dev python-dev python-virtualenv locales libffi-dev \ - build-essential python3-dev --no-install-recommends + build-essential python3-dev zlib1g-dev libssl-dev npm gettext \ + --no-install-recommends + +WORKDIR / +RUN npm install -g less@2.5.0 +RUN ln -s /usr/bin/nodejs /usr/bin/node +RUN ln -s /node_modules/.bin/lessc /usr/bin/lessc RUN dpkg-reconfigure locales && \ locale-gen C.UTF-8 && \ @@ -13,11 +19,17 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf ADD gunicorn_starter.bash /gunicorn_starter.bash + ADD src /src WORKDIR /src + RUN pip3 install -r requirements.txt RUN pip3 install gunicorn +ADD local_settings.py /src/pretix/local_settings.py + +RUN make production + EXPOSE 80 CMD ["/usr/bin/supervisord"] diff --git a/deployment/docker/standalone/local_settings.py b/deployment/docker/standalone/local_settings.py new file mode 100644 index 0000000000..f517bed92f --- /dev/null +++ b/deployment/docker/standalone/local_settings.py @@ -0,0 +1,5 @@ +COMPRESS_OFFLINE = True +COMPRESS_ENABLED = True +#DEBUG = False +#TEMPLATE_DEBUG = False + diff --git a/deployment/docker/standalone/supervisord.conf b/deployment/docker/standalone/supervisord.conf index a8e43c7218..72e2c78055 100644 --- a/deployment/docker/standalone/supervisord.conf +++ b/deployment/docker/standalone/supervisord.conf @@ -2,4 +2,4 @@ nodaemon=true [program:gunicorn] -command=/bin/bash gunicorn_starter.bash +command=/bin/bash /gunicorn_starter.bash From 62b5d1c6ebd85689579c802444bd6fe034e27b40 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sat, 16 May 2015 00:56:09 +0200 Subject: [PATCH 04/20] Improved dockerfile, config file usage and documentation --- .gitignore | 1 + deployment/docker/standalone/Dockerfile | 12 +- deployment/docker/standalone/Makefile | 3 +- .../docker/standalone/gunicorn_starter.bash | 3 +- .../docker/standalone/local_settings.py | 5 - deployment/docker/standalone/src | 1 - doc/admin/config.rst | 153 ++++++++++++++++++ doc/admin/index.rst | 11 ++ doc/index.rst | 1 + src/pretix/settings.py | 95 ++++++----- 10 files changed, 222 insertions(+), 63 deletions(-) delete mode 100644 deployment/docker/standalone/local_settings.py delete mode 120000 deployment/docker/standalone/src create mode 100644 doc/admin/config.rst create mode 100644 doc/admin/index.rst diff --git a/.gitignore b/.gitignore index fc6eb78d0f..07f4c08826 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ htmlcov/ __pycache__/ _static/ .idea +.secret diff --git a/deployment/docker/standalone/Dockerfile b/deployment/docker/standalone/Dockerfile index 9f708d3435..9afd78432d 100644 --- a/deployment/docker/standalone/Dockerfile +++ b/deployment/docker/standalone/Dockerfile @@ -2,7 +2,7 @@ FROM debian:jessie RUN apt-get update && apt-get install -y supervisor python3 git python3-pip \ libxml2-dev libxslt1-dev python-dev python-virtualenv locales libffi-dev \ - build-essential python3-dev zlib1g-dev libssl-dev npm gettext \ + build-essential python3-dev zlib1g-dev libssl-dev npm gettext git \ --no-install-recommends WORKDIR / @@ -20,16 +20,18 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf ADD gunicorn_starter.bash /gunicorn_starter.bash -ADD src /src -WORKDIR /src +RUN git clone --recursive --depth 1 https://github.com/pretix/pretix.git /pretix +WORKDIR /pretix/src RUN pip3 install -r requirements.txt RUN pip3 install gunicorn -ADD local_settings.py /src/pretix/local_settings.py - RUN make production +RUN mkdir /etc/pretix +RUN mkdir /data +VOLUME /etc/pretix + EXPOSE 80 CMD ["/usr/bin/supervisord"] diff --git a/deployment/docker/standalone/Makefile b/deployment/docker/standalone/Makefile index 9444b355ef..372b7fdbd4 100644 --- a/deployment/docker/standalone/Makefile +++ b/deployment/docker/standalone/Makefile @@ -1,2 +1,3 @@ main: - tar ch --exclude=_static --exclude=htmlcov --exclude=db.sqlite3 . | docker build -t test - + #tar ch --exclude=_static --exclude=htmlcov --exclude=db.sqlite3 . | + docker build -t raphaelm/pretix-standalone . diff --git a/deployment/docker/standalone/gunicorn_starter.bash b/deployment/docker/standalone/gunicorn_starter.bash index d4aff98c31..3366dd68fe 100644 --- a/deployment/docker/standalone/gunicorn_starter.bash +++ b/deployment/docker/standalone/gunicorn_starter.bash @@ -1,6 +1,7 @@ #!/bin/bash -cd /src +cd /pretix/src export DJANGO_SETTINGS_MODULE=pretix.settings +export MEDIA_ROOT=/data/ gunicorn \ -b '0.0.0.0:80' \ -w 3 --max-requests 1000 --max-requests-jitter 50 \ diff --git a/deployment/docker/standalone/local_settings.py b/deployment/docker/standalone/local_settings.py deleted file mode 100644 index f517bed92f..0000000000 --- a/deployment/docker/standalone/local_settings.py +++ /dev/null @@ -1,5 +0,0 @@ -COMPRESS_OFFLINE = True -COMPRESS_ENABLED = True -#DEBUG = False -#TEMPLATE_DEBUG = False - diff --git a/deployment/docker/standalone/src b/deployment/docker/standalone/src deleted file mode 120000 index dabb0e15a9..0000000000 --- a/deployment/docker/standalone/src +++ /dev/null @@ -1 +0,0 @@ -../../../src \ No newline at end of file diff --git a/doc/admin/config.rst b/doc/admin/config.rst new file mode 100644 index 0000000000..73b6ab054c --- /dev/null +++ b/doc/admin/config.rst @@ -0,0 +1,153 @@ +.. highlight:: ini + +Configuration file +================== + +Pretix reads its configuration from a configuration file. It tries to find this file +at the following locations. It will try to read the file from the specified paths in +the following order. The file that is found *last* will override the settings from +the files found before. + +1. ``/etc/pretix/pretix.cfg`` +2. ``~/.pretix.cfg`` +3. ``pretix.cfg`` in the current working directory + +The file is expected to be in the INI format as specified in the `Python documentation`_. + +The config file may contain the following sections (all settings are optional and have default values). + +pretix settings +--------------- + +Example:: + + [pretix] + instance_name=pretix.de + global_registration=off + site_url=http://localhost + currency=EUR + +``instance_name`` + The name of this installation. Default: ``pretix.de`` + +``global_registration`` + Whether or not this installation supports global user accounts (in addition to + event-bound accounts). Defaults to ``True``. + +``site_url`` + The installation's full URL, without a trailing slash. + +``currency`` + The default currency as a three-letter code. Defaults to ``EUR``. + +Locale settings +--------------- + +Example:: + + [locale] + default=de + timezone=Europe/Berlin + +``default`` + The system's default locale. Default: ``en`` + +``timezone`` + The system's default timezone as a ``pytz`` name. Default: ``UTC`` + +Database settings +----------------- + +Example:: + + [database] + backend=mysql + name=pretix + user=pretix + password=abcd + host=localhost + port=3306 + +``backend`` + One of ``mysql``, ``sqlite3``, ``oracle`` and ``postgresql_psycopg2``. + Default: ``sqlite3``. + +``name`` + The database's name. Default: ``db.sqlite3``. + +``user``, ``password``, ``host``, ``port`` + Connection details for the database connection. Empty by default. + +Uploaded files +-------------- + +Example:: + + [media] + url=/media/ + root=media + +``root`` + The filesystem location to store user-uploaded content at. By default, this takes + the value of the environment variable ``MEDIA_ROOT``, if present, or ``media`` if not. + +``url`` + The URL to be used to serve user-uploaded content. You should not need to modify + this. Default: ``/media/`` + +Email +----- + +Example:: + + [mail] + from=hello@localhost + +``from`` + The email address to set as ``From`` header in outgoing emails by the system. + Default: ``pretix@localhost`` + +Django settings +--------------- + +Example:: + + [django] + hosts=localhost + secret=j1kjps5a5&4ilpn912s7a1!e2h!duz^i3&idu@_907s$wrz@x- + debug=off + +``hosts`` + Comma-seperated list of allowed host names for this installation. + Default: ``localhost`` + +``secret`` + The secret to be used by Django for signing and verification purposes. If this + setting is not provided, pretix will generate a random secret on the first start + and store it in the filesystem for later usage. + +``debug`` + Whether or not to run in debug mode. Default is ``False``. + + .. WARNING:: Never set this to ``True`` in production! + +Static files +------------ + +You should *not* need to modify these settings as logn as you don't want to use a +custom delivery method for static files such as an external CDN. + +Example:: + + [static] + url=/static/ + root=_static + +``url`` + The URL to be used to serve static files. Default: ``/static/``. + +``root`` + The filesystem path to be used for static file storage. Default: ``_static`` + + +.. _Python documentation: https://docs.python.org/3/library/configparser.html?highlight=configparser#supported-ini-file-structure \ No newline at end of file diff --git a/doc/admin/index.rst b/doc/admin/index.rst new file mode 100644 index 0000000000..570fb70844 --- /dev/null +++ b/doc/admin/index.rst @@ -0,0 +1,11 @@ +Administrator documentation +=========================== + +This documentation is for everyone who wants to install pretix on a server. + +Contents: + +.. toctree:: + :maxdepth: 2 + + config diff --git a/doc/index.rst b/doc/index.rst index 387b86ee81..eadea83f7c 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -11,5 +11,6 @@ Contents: .. toctree:: :maxdepth: 2 + admin/index development/index diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 2b950625f8..054265e888 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -1,32 +1,57 @@ -""" -Django settings for pretix project. - -For more information on this file, see -https://docs.djangoproject.com/en/dev/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/dev/ref/settings/ -""" - +import configparser import os +from django.utils.crypto import get_random_string + +config = configparser.ConfigParser() +config.read(['/etc/pretix/pretix.cfg', os.path.expanduser('~/.pretix.cfg'), 'pretix.cfg'], + encoding='utf-8') -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(__file__)) +if config.has_option('django', 'secret'): + SECRET_KEY = config.get('django', 'secret') +else: + SECRET_FILE = os.path.join(BASE_DIR, '.secret') + if os.path.exists(SECRET_FILE): + with open(SECRET_FILE, 'r') as f: + SECRET_KEY = f.read().strip() + else: + chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' + SECRET_KEY = get_random_string(50, chars) + with open(SECRET_FILE, 'w') as f: + f.write(SECRET_KEY) -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/ +DEBUG = TEMPLATE_DEBUG = config.getboolean('django', 'debug', fallback=False) -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '0ro^46+8k#dv3ej=oen-2ww)i30#$$^&x&eajyj&_&h)$nc6@5' +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.' + config.get('database', 'backend', fallback='sqlite3'), + 'NAME': config.get('database', 'name', fallback=os.path.join(BASE_DIR, 'db.sqlite3')), + 'USER': config.get('database', 'user', fallback=''), + 'PASSWORD': config.get('database', 'user', fallback=''), + 'HOST': config.get('database', 'host', fallback=''), + 'PORT': config.get('database', 'port', fallback='') + } +} -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +STATIC_URL = config.get('static', 'url', fallback='/static/') +STATIC_ROOT = config.get('static', 'root', fallback='_static') -TEMPLATE_DEBUG = True +MEDIA_URL = config.get('media', 'url', fallback=os.environ.get('MEDIA_ROOT', '/media/')) +MEDIA_ROOT = config.get('media', 'root', fallback='media') -ALLOWED_HOSTS = [] +PRETIX_INSTANCE_NAME = config.get('pretix', 'instance_name', fallback='pretix.de') +PRETIX_GLOBAL_REGISTRATION = config.getboolean('pretix', 'global_registration', fallback=True) +MAIL_FROM = config.get('mail', 'from', fallback='pretix@localhost') +SITE_URL = config.get('pretix', 'url', fallback='http://localhost') + +DEFAULT_CURRENCY = config.get('pretix', 'currency', fallback='EUR') + +ALLOWED_HOSTS = config.get('django', 'hosts', fallback='localhost').split(',') + +LANGUAGE_CODE = config.get('locale', 'default', fallback='en') +TIME_ZONE = config.get('locale', 'timezone', fallback='UTC') # Application definition @@ -84,27 +109,8 @@ ROOT_URLCONF = 'pretix.urls' WSGI_APPLICATION = 'pretix.wsgi.application' -# Database -# https://docs.djangoproject.com/en/dev/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - -# Internationalization -# https://docs.djangoproject.com/en/dev/topics/i18n/ - -LANGUAGE_CODE = 'en' - -TIME_ZONE = 'UTC' - USE_I18N = True - USE_L10N = True - USE_TZ = True LOCALE_PATHS = ( @@ -127,10 +133,6 @@ LOGIN_URL_CONTROL = '/control/login' # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/dev/howto/static-files/ -STATIC_URL = '/static/' -STATIC_ROOT = '_static' -MEDIA_ROOT = 'media' -MEDIA_URL = '/media/' STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', @@ -142,7 +144,7 @@ COMPRESS_PRECOMPILERS = ( ('text/less', 'pretix.helpers.lessabsolutefilter.LessFilter'), ) -COMPRESS_OFFLINE = not DEBUG +COMPRESS_ENABLED = COMPRESS_OFFLINE = not DEBUG COMPRESS_CSS_FILTERS = ( 'compressor.filters.css_default.CssAbsoluteFilter', @@ -157,10 +159,6 @@ DEBUG_TOOLBAR_CONFIG = { # Pretix specific settings -PRETIX_INSTANCE_NAME = 'pretix.de' -PRETIX_GLOBAL_REGISTRATION = True - -DEFAULT_CURRENCY = 'EUR' INTERNAL_IPS = ('127.0.0.1', '::1') @@ -197,9 +195,6 @@ LOGGING = { }, } -MAIL_FROM = 'pretix@localhost' -SITE_URL = 'http://localhost' - try: from .local_settings import * # NOQA except ImportError: From d9d0b7366b349a3de7f06a4fda41379c0fd06d91 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sat, 16 May 2015 09:52:47 +0200 Subject: [PATCH 05/20] Do perform compression in tests --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7ab7743caf..c653df5bc9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,8 @@ before_script: - cd src - flake8 --ignore=E123,F403,F401,N802,C901,W503 . - python manage.py check - - python manage.py validate + - python manage.py collectstatic --noinput + - python manage.py compress script: - coverage run manage.py test -v 2 after_success: From 95c3f28794bb4566323725eb4cf0eb234d1248de Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sat, 16 May 2015 09:54:06 +0200 Subject: [PATCH 06/20] Use Makefile in travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c653df5bc9..e11b038a3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,9 +9,8 @@ before_script: - cd src - flake8 --ignore=E123,F403,F401,N802,C901,W503 . - python manage.py check - - python manage.py collectstatic --noinput - - python manage.py compress script: + - make - coverage run manage.py test -v 2 after_success: - coveralls From 8b880e17fd5dac90d565d394e8756fd0027a5b62 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sat, 16 May 2015 10:03:29 +0200 Subject: [PATCH 07/20] Travis: Install node --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e11b038a3c..bfb3256c77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ python: - "3.4" install: - pip install -q -r src/requirements.txt + - npm install less@2.5.0 before_script: - cd src - flake8 --ignore=E123,F403,F401,N802,C901,W503 . From 00250d5c74120b2fd1219b2b2731d717b9c51ae5 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sat, 16 May 2015 10:17:34 +0200 Subject: [PATCH 08/20] Travis was not compressing files --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index bfb3256c77..9ec1911155 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ before_script: - python manage.py check script: - make + - make compress - coverage run manage.py test -v 2 after_success: - coveralls From f6e8b0ea37580522a76b83859ee1c09d03681de2 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sat, 16 May 2015 10:38:48 +0200 Subject: [PATCH 09/20] Try to fix travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9ec1911155..fceef13222 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ python: - "3.4" install: - pip install -q -r src/requirements.txt - - npm install less@2.5.0 + - npm install -g less@2.5.0 before_script: - cd src - flake8 --ignore=E123,F403,F401,N802,C901,W503 . From 73169b78b61dea9380934fd925423f28bb524dfa Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Sat, 16 May 2015 11:02:50 +0200 Subject: [PATCH 10/20] Further improve settings --- doc/admin/config.rst | 28 +++++++++++++ src/pretix/local_settings.py | 2 - src/pretix/settings.py | 80 +++++++++++++++++++++++------------- 3 files changed, 79 insertions(+), 31 deletions(-) delete mode 100644 src/pretix/local_settings.py diff --git a/doc/admin/config.rst b/doc/admin/config.rst index 73b6ab054c..6423ecd33d 100644 --- a/doc/admin/config.rst +++ b/doc/admin/config.rst @@ -25,7 +25,10 @@ Example:: instance_name=pretix.de global_registration=off site_url=http://localhost + scriptname=/presale/ currency=EUR + cookiedomain=.pretix.de + securecookie=on ``instance_name`` The name of this installation. Default: ``pretix.de`` @@ -34,12 +37,22 @@ Example:: Whether or not this installation supports global user accounts (in addition to event-bound accounts). Defaults to ``True``. +``scriptname`` + The path pretix runs at, if it does not run under its own subdomain. + ``site_url`` The installation's full URL, without a trailing slash. ``currency`` The default currency as a three-letter code. Defaults to ``EUR``. +``cookiedomain`` + The domain to be used for session cookies, csrf protection cookies and locale cookies. + Empty by default. + +``securecookie`` + Set the ``secure`` and ``httponly`` flags on session cookies. Off by default. + Locale settings --------------- @@ -102,11 +115,26 @@ Example:: [mail] from=hello@localhost + host=127.0.0.71 + user=pretix + password=foobar + port=1025 + tls=on + ssl=off + +``host``, ``port`` + The SMTP Host to connect to. Defaults to ``localhost`` and ``25``. + +``user``, ``password`` + The SMTP user data to use for the connection. Empty by default. ``from`` The email address to set as ``From`` header in outgoing emails by the system. Default: ``pretix@localhost`` +``tls``, ``ssl`` + Use STARTTLS or SSL for the SMTP connection. Off by default. + Django settings --------------- diff --git a/src/pretix/local_settings.py b/src/pretix/local_settings.py deleted file mode 100644 index bb21042958..0000000000 --- a/src/pretix/local_settings.py +++ /dev/null @@ -1,2 +0,0 @@ -EMAIL_PORT = 1025 -EMAIL_HOST = '127.0.0.1' diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 054265e888..0c1d685075 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -21,6 +21,8 @@ else: with open(SECRET_FILE, 'w') as f: f.write(SECRET_KEY) +# Adjustable settings + DEBUG = TEMPLATE_DEBUG = config.getboolean('django', 'debug', fallback=False) DATABASES = { @@ -43,8 +45,8 @@ MEDIA_ROOT = config.get('media', 'root', fallback='media') PRETIX_INSTANCE_NAME = config.get('pretix', 'instance_name', fallback='pretix.de') PRETIX_GLOBAL_REGISTRATION = config.getboolean('pretix', 'global_registration', fallback=True) -MAIL_FROM = config.get('mail', 'from', fallback='pretix@localhost') SITE_URL = config.get('pretix', 'url', fallback='http://localhost') +FORCE_SCRIPT_NAME = config.get('pretix', 'scriptname', fallback=None) DEFAULT_CURRENCY = config.get('pretix', 'currency', fallback='EUR') @@ -53,7 +55,23 @@ ALLOWED_HOSTS = config.get('django', 'hosts', fallback='localhost').split(',') LANGUAGE_CODE = config.get('locale', 'default', fallback='en') TIME_ZONE = config.get('locale', 'timezone', fallback='UTC') -# Application definition +MAIL_FROM = SERVER_EMAIL = DEFAULT_FROM_EMAIL = config.get( + 'mail', 'from', fallback='pretix@localhost') +EMAIL_HOST = config.get('mail', 'host', fallback='localhost') +EMAIL_PORT = config.getint('mail', 'port', fallback=25) +EMAIL_HOST_USER = config.get('mail', 'user', fallback='') +EMAIL_HOST_PASSWORD = config.get('mail', 'password', fallback='') + +SESSION_COOKIE_SECURE = SESSION_COOKIE_HTTPONLY = config.getboolean( + 'pretix', 'securecookie', fallback=False) +LANGUAGE_COOKIE_DOMAIN = SESSION_COOKIE_DOMAIN = CSRF_COOKIE_DOMAIN = config.get( + 'pretix', 'cookiedomain', fallback=None) + +# Internal settings + +SESSION_COOKIE_NAME = 'pretix_session' +LANGUAGE_COOKIE_NAME = 'pretix_language' +CSRF_COOKIE_NAME = 'pretix_csrftoken' INSTALLED_APPS = ( 'django.contrib.admin', @@ -91,24 +109,10 @@ MIDDLEWARE_CLASSES = ( 'pretix.base.middleware.LocaleMiddleware', ) -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.request", - "django.core.context_processors.static", - "django.core.context_processors.tz", - "django.contrib.messages.context_processors.messages", - 'pretix.control.context.contextprocessor', - 'pretix.presale.context.contextprocessor', -) - ROOT_URLCONF = 'pretix.urls' WSGI_APPLICATION = 'pretix.wsgi.application' - USE_I18N = True USE_L10N = True USE_TZ = True @@ -123,16 +127,42 @@ LANGUAGES = ( ('de', _('German')), ) - -# Authentication - AUTH_USER_MODEL = 'pretixbase.User' LOGIN_URL = '/login' LOGIN_URL_CONTROL = '/control/login' -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/dev/howto/static-files/ +template_loaders = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +) +if DEBUG: + template_loaders = ( + ('django.template.loaders.cached.Loader', template_loaders), + ) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ + os.path.join(BASE_DIR, 'templates') + ], + 'OPTIONS': { + 'context_processors': [ + 'django.contrib.auth.context_processors.auth', + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.media', + "django.template.context_processors.request", + 'django.template.context_processors.static', + 'django.template.context_processors.tz', + 'django.contrib.messages.context_processors.messages', + 'pretix.control.context.contextprocessor', + 'pretix.presale.context.contextprocessor', + ], + 'loaders': template_loaders + }, + }, +] STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', @@ -157,9 +187,6 @@ DEBUG_TOOLBAR_CONFIG = { 'JQUERY_URL': '' } - -# Pretix specific settings - INTERNAL_IPS = ('127.0.0.1', '::1') from django.contrib.messages import constants as messages # NOQA @@ -194,8 +221,3 @@ LOGGING = { }, }, } - -try: - from .local_settings import * # NOQA -except ImportError: - pass From 3fbd57add7ce397dc74c884fb205cda25721ddea Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 18 May 2015 13:02:59 +0200 Subject: [PATCH 11/20] Temporary usage of our own static3 patch --- src/requirements/production.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/requirements/production.txt b/src/requirements/production.txt index 46b6d34eb7..97a08c8bf3 100644 --- a/src/requirements/production.txt +++ b/src/requirements/production.txt @@ -14,4 +14,5 @@ BeautifulSoup4 html5lib slimit lxml +-e git+https://github.com/pretix/static3.git@readme#egg=static3 dj-static==0.0.6 From 73a469485b8984775708c33ec846f85d1b8afc61 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 18 May 2015 16:28:55 +0200 Subject: [PATCH 12/20] Docker standalone: migrate before start --- deployment/docker/standalone/gunicorn_starter.bash | 1 + 1 file changed, 1 insertion(+) diff --git a/deployment/docker/standalone/gunicorn_starter.bash b/deployment/docker/standalone/gunicorn_starter.bash index 3366dd68fe..6e5fc5701c 100644 --- a/deployment/docker/standalone/gunicorn_starter.bash +++ b/deployment/docker/standalone/gunicorn_starter.bash @@ -2,6 +2,7 @@ cd /pretix/src export DJANGO_SETTINGS_MODULE=pretix.settings export MEDIA_ROOT=/data/ +python3 manage.py migrate gunicorn \ -b '0.0.0.0:80' \ -w 3 --max-requests 1000 --max-requests-jitter 50 \ From 5a4952eb7ffcaeb3928c57caa69ada37d06f322f Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 18 May 2015 16:47:14 +0200 Subject: [PATCH 13/20] Add MySQL und Postgres drivers to the deployment --- deployment/docker/standalone/Dockerfile | 2 ++ src/requirements/mysql.txt | 2 ++ src/requirements/postgres.txt | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 src/requirements/mysql.txt create mode 100644 src/requirements/postgres.txt diff --git a/deployment/docker/standalone/Dockerfile b/deployment/docker/standalone/Dockerfile index 9afd78432d..0513a092ff 100644 --- a/deployment/docker/standalone/Dockerfile +++ b/deployment/docker/standalone/Dockerfile @@ -24,6 +24,8 @@ RUN git clone --recursive --depth 1 https://github.com/pretix/pretix.git /pretix WORKDIR /pretix/src RUN pip3 install -r requirements.txt +RUN pip3 install -r requirements/mysql.txt +RUN pip3 install -r requirements/postgres.txt RUN pip3 install gunicorn RUN make production diff --git a/src/requirements/mysql.txt b/src/requirements/mysql.txt new file mode 100644 index 0000000000..0095ffd8de --- /dev/null +++ b/src/requirements/mysql.txt @@ -0,0 +1,2 @@ +--allow-external mysql-connector-python +mysql-connector-python diff --git a/src/requirements/postgres.txt b/src/requirements/postgres.txt new file mode 100644 index 0000000000..6ccfa4b1a5 --- /dev/null +++ b/src/requirements/postgres.txt @@ -0,0 +1,2 @@ +psycopg2 + From 262f69a499306a9f33f9c911538d920877707a00 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 18 May 2015 17:02:27 +0200 Subject: [PATCH 14/20] Add dependencies for psycopg to Dockerfile --- deployment/docker/standalone/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/deployment/docker/standalone/Dockerfile b/deployment/docker/standalone/Dockerfile index 0513a092ff..f79b1e4b95 100644 --- a/deployment/docker/standalone/Dockerfile +++ b/deployment/docker/standalone/Dockerfile @@ -3,6 +3,7 @@ FROM debian:jessie RUN apt-get update && apt-get install -y supervisor python3 git python3-pip \ libxml2-dev libxslt1-dev python-dev python-virtualenv locales libffi-dev \ build-essential python3-dev zlib1g-dev libssl-dev npm gettext git \ + libpq-dev \ --no-install-recommends WORKDIR / From aa7fcc1923032f73a85b4e72651a1cc35af2cd6b Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 18 May 2015 21:28:03 +0200 Subject: [PATCH 15/20] Use mysql-connector instead of MySQLdb --- src/pretix/settings.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 0c1d685075..fadbc4ed1c 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -25,9 +25,12 @@ else: DEBUG = TEMPLATE_DEBUG = config.getboolean('django', 'debug', fallback=False) +dbengine = 'django.db.backends.' + config.get('database', 'backend', fallback='sqlite3') +if dbengine == 'django.db.backends.mysql': + dbengine = 'mysql.connector.django' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.' + config.get('database', 'backend', fallback='sqlite3'), + 'ENGINE': dbengine, 'NAME': config.get('database', 'name', fallback=os.path.join(BASE_DIR, 'db.sqlite3')), 'USER': config.get('database', 'user', fallback=''), 'PASSWORD': config.get('database', 'user', fallback=''), From f89fd9c3a255752b197c83b62e90faca77de8082 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Mon, 18 May 2015 22:28:51 +0200 Subject: [PATCH 16/20] Use the MySQL connector that is recommended by Django --- deployment/docker/standalone/Dockerfile | 2 +- src/pretix/settings.py | 5 +---- src/requirements/mysql.txt | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/deployment/docker/standalone/Dockerfile b/deployment/docker/standalone/Dockerfile index f79b1e4b95..920de70145 100644 --- a/deployment/docker/standalone/Dockerfile +++ b/deployment/docker/standalone/Dockerfile @@ -3,7 +3,7 @@ FROM debian:jessie RUN apt-get update && apt-get install -y supervisor python3 git python3-pip \ libxml2-dev libxslt1-dev python-dev python-virtualenv locales libffi-dev \ build-essential python3-dev zlib1g-dev libssl-dev npm gettext git \ - libpq-dev \ + libpq-dev libmysqlclient-dev \ --no-install-recommends WORKDIR / diff --git a/src/pretix/settings.py b/src/pretix/settings.py index fadbc4ed1c..0c1d685075 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -25,12 +25,9 @@ else: DEBUG = TEMPLATE_DEBUG = config.getboolean('django', 'debug', fallback=False) -dbengine = 'django.db.backends.' + config.get('database', 'backend', fallback='sqlite3') -if dbengine == 'django.db.backends.mysql': - dbengine = 'mysql.connector.django' DATABASES = { 'default': { - 'ENGINE': dbengine, + 'ENGINE': 'django.db.backends.' + config.get('database', 'backend', fallback='sqlite3'), 'NAME': config.get('database', 'name', fallback=os.path.join(BASE_DIR, 'db.sqlite3')), 'USER': config.get('database', 'user', fallback=''), 'PASSWORD': config.get('database', 'user', fallback=''), diff --git a/src/requirements/mysql.txt b/src/requirements/mysql.txt index 0095ffd8de..93c8d852b9 100644 --- a/src/requirements/mysql.txt +++ b/src/requirements/mysql.txt @@ -1,2 +1,2 @@ ---allow-external mysql-connector-python -mysql-connector-python +mysqlclient + From 82bd843aa38653fb05575568d6228beb03f4ef0c Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Tue, 19 May 2015 18:07:33 +0200 Subject: [PATCH 17/20] Fix a bug in database settings --- src/pretix/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 0c1d685075..05b6578040 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -30,7 +30,7 @@ DATABASES = { 'ENGINE': 'django.db.backends.' + config.get('database', 'backend', fallback='sqlite3'), 'NAME': config.get('database', 'name', fallback=os.path.join(BASE_DIR, 'db.sqlite3')), 'USER': config.get('database', 'user', fallback=''), - 'PASSWORD': config.get('database', 'user', fallback=''), + 'PASSWORD': config.get('database', 'password', fallback=''), 'HOST': config.get('database', 'host', fallback=''), 'PORT': config.get('database', 'port', fallback='') } From 18a83d7e3803b1d6006dc644f913de26c658a3c4 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 20 May 2015 10:22:45 +0200 Subject: [PATCH 18/20] Re-use official static3 package as 0.6.1 fixed the bug we found Use own dj-static fork as long as our patch is in review Remove setting for FORCE_SCRIPT_NAME --- doc/admin/config.rst | 4 ---- src/pretix/settings.py | 1 - src/requirements/production.txt | 4 ++-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/doc/admin/config.rst b/doc/admin/config.rst index 6423ecd33d..edeb60ad17 100644 --- a/doc/admin/config.rst +++ b/doc/admin/config.rst @@ -25,7 +25,6 @@ Example:: instance_name=pretix.de global_registration=off site_url=http://localhost - scriptname=/presale/ currency=EUR cookiedomain=.pretix.de securecookie=on @@ -37,9 +36,6 @@ Example:: Whether or not this installation supports global user accounts (in addition to event-bound accounts). Defaults to ``True``. -``scriptname`` - The path pretix runs at, if it does not run under its own subdomain. - ``site_url`` The installation's full URL, without a trailing slash. diff --git a/src/pretix/settings.py b/src/pretix/settings.py index 05b6578040..2c731ae5bc 100644 --- a/src/pretix/settings.py +++ b/src/pretix/settings.py @@ -46,7 +46,6 @@ PRETIX_INSTANCE_NAME = config.get('pretix', 'instance_name', fallback='pretix.de PRETIX_GLOBAL_REGISTRATION = config.getboolean('pretix', 'global_registration', fallback=True) SITE_URL = config.get('pretix', 'url', fallback='http://localhost') -FORCE_SCRIPT_NAME = config.get('pretix', 'scriptname', fallback=None) DEFAULT_CURRENCY = config.get('pretix', 'currency', fallback='EUR') diff --git a/src/requirements/production.txt b/src/requirements/production.txt index 97a08c8bf3..368288571d 100644 --- a/src/requirements/production.txt +++ b/src/requirements/production.txt @@ -14,5 +14,5 @@ BeautifulSoup4 html5lib slimit lxml --e git+https://github.com/pretix/static3.git@readme#egg=static3 -dj-static==0.0.6 +static3==0.6.1 +-e git+https://github.com/pretix/dj-static.git@script-path#egg=dj-static From d658303da376003d7b93af5d6b16f9b8e86f81a3 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 20 May 2015 18:17:08 +0200 Subject: [PATCH 19/20] Try to make pretix compatible with SCRIPT_NAME Remove unnecessary resolve() calls --- src/pretix/control/context.py | 4 ++-- src/pretix/control/middleware.py | 6 +++--- src/pretix/control/views/item.py | 27 +++++++++------------------ 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/pretix/control/context.py b/src/pretix/control/context.py index c34a9d6791..aa3cbeb1de 100644 --- a/src/pretix/control/context.py +++ b/src/pretix/control/context.py @@ -1,5 +1,5 @@ from django.conf import settings -from django.core.urlresolvers import resolve +from django.core.urlresolvers import resolve, get_script_prefix from .signals import html_head, nav_event @@ -8,7 +8,7 @@ def contextprocessor(request): Adds data to all template contexts """ url = resolve(request.path_info) - if not request.path.startswith('/control'): + if not request.path.startswith(get_script_prefix() + 'control'): return {} ctx = { 'url_name': url.url_name, diff --git a/src/pretix/control/middleware.py b/src/pretix/control/middleware.py index 512ba5a6f4..e5aea9e817 100644 --- a/src/pretix/control/middleware.py +++ b/src/pretix/control/middleware.py @@ -1,7 +1,7 @@ +from urllib.parse import urlparse from django.conf import settings -from django.core.urlresolvers import resolve +from django.core.urlresolvers import resolve, get_script_prefix from django.utils.encoding import force_str -from django.utils.six.moves.urllib.parse import urlparse from django.shortcuts import resolve_url from django.contrib.auth import REDIRECT_FIELD_NAME from django.http import HttpResponseNotFound @@ -25,7 +25,7 @@ class PermissionMiddleware: def process_request(self, request): url = resolve(request.path_info) url_name = url.url_name - if not request.path.startswith('/control') or url_name in self.EXCEPTIONS: + if not request.path.startswith(get_script_prefix() + 'control') or url_name in self.EXCEPTIONS: return if not request.user.is_authenticated(): # Taken from django/contrib/auth/decorators.py diff --git a/src/pretix/control/views/item.py b/src/pretix/control/views/item.py index 5d7d1cc9a4..76415975bb 100644 --- a/src/pretix/control/views/item.py +++ b/src/pretix/control/views/item.py @@ -52,9 +52,8 @@ class CategoryDelete(EventPermissionRequiredMixin, DeleteView): context_object_name = 'category' def get_object(self, queryset=None) -> ItemCategory: - url = resolve(self.request.path_info) return self.request.event.categories.current.get( - identity=url.kwargs['category'] + identity=self.kwargs['category'] ) def delete(self, request, *args, **kwargs): @@ -199,17 +198,15 @@ class PropertyUpdate(EventPermissionRequiredMixin, UpdateView): context_object_name = 'property' def get_object(self, queryset=None) -> Property: - url = resolve(self.request.path_info) return self.request.event.properties.current.get( - identity=url.kwargs['property'] + identity=self.kwargs['property'] ) def get_success_url(self) -> str: - url = resolve(self.request.path_info) return reverse('control:event.items.properties.edit', kwargs={ 'organizer': self.request.event.organizer.slug, 'event': self.request.event.slug, - 'property': url.kwargs['property'] + 'property': self.kwargs['property'] }) + '?success=true' def get_formset(self): @@ -322,9 +319,8 @@ class PropertyDelete(EventPermissionRequiredMixin, DeleteView): def get_object(self, queryset=None) -> Property: if not hasattr(self, 'object') or not self.object: - url = resolve(self.request.path_info) self.object = self.request.event.properties.current.get( - identity=url.kwargs['property'] + identity=self.kwargs['property'] ) return self.object @@ -371,9 +367,8 @@ class QuestionDelete(EventPermissionRequiredMixin, DeleteView): context_object_name = 'question' def get_object(self, queryset=None) -> Question: - url = resolve(self.request.path_info) return self.request.event.questions.current.get( - identity=url.kwargs['question'] + identity=self.kwargs['question'] ) def get_context_data(self, *args, **kwargs) -> dict: @@ -402,9 +397,8 @@ class QuestionUpdate(EventPermissionRequiredMixin, UpdateView): context_object_name = 'question' def get_object(self, queryset=None) -> Question: - url = resolve(self.request.path_info) return self.request.event.questions.current.get( - identity=url.kwargs['question'] + identity=self.kwargs['question'] ) def get_success_url(self) -> str: @@ -559,9 +553,8 @@ class QuotaUpdate(EventPermissionRequiredMixin, QuotaEditorMixin, UpdateView): context_object_name = 'quota' def get_object(self, queryset=None) -> Quota: - url = resolve(self.request.path_info) return self.request.event.quotas.current.get( - identity=url.kwargs['quota'] + identity=self.kwargs['quota'] ) def get_success_url(self) -> str: @@ -578,9 +571,8 @@ class QuotaDelete(EventPermissionRequiredMixin, DeleteView): context_object_name = 'quota' def get_object(self, queryset=None) -> Quota: - url = resolve(self.request.path_info) return self.request.event.quotas.current.get( - identity=url.kwargs['quota'] + identity=self.kwargs['quota'] ) def get_context_data(self, *args, **kwargs) -> dict: @@ -607,9 +599,8 @@ class ItemDetailMixin(SingleObjectMixin): def get_object(self, queryset=None) -> Item: if not hasattr(self, 'object') or not self.object: - url = resolve(self.request.path_info) self.item = self.request.event.items.current.get( - identity=url.kwargs['item'] + identity=self.kwargs['item'] ) self.object = self.item return self.object From fbe9f5874d8cb39ab806f6171cfd681eca7697c5 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Wed, 20 May 2015 18:28:54 +0200 Subject: [PATCH 20/20] We need to run compress at docker startup time as it depends on STATIC_URL :( --- deployment/docker/standalone/Dockerfile | 2 +- deployment/docker/standalone/Makefile | 2 +- deployment/docker/standalone/gunicorn_starter.bash | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deployment/docker/standalone/Dockerfile b/deployment/docker/standalone/Dockerfile index 920de70145..fa975afc01 100644 --- a/deployment/docker/standalone/Dockerfile +++ b/deployment/docker/standalone/Dockerfile @@ -29,7 +29,7 @@ RUN pip3 install -r requirements/mysql.txt RUN pip3 install -r requirements/postgres.txt RUN pip3 install gunicorn -RUN make production +RUN make RUN mkdir /etc/pretix RUN mkdir /data diff --git a/deployment/docker/standalone/Makefile b/deployment/docker/standalone/Makefile index 372b7fdbd4..a912853c55 100644 --- a/deployment/docker/standalone/Makefile +++ b/deployment/docker/standalone/Makefile @@ -1,3 +1,3 @@ main: #tar ch --exclude=_static --exclude=htmlcov --exclude=db.sqlite3 . | - docker build -t raphaelm/pretix-standalone . + docker build -t pretix/standalone . diff --git a/deployment/docker/standalone/gunicorn_starter.bash b/deployment/docker/standalone/gunicorn_starter.bash index 6e5fc5701c..225990978b 100644 --- a/deployment/docker/standalone/gunicorn_starter.bash +++ b/deployment/docker/standalone/gunicorn_starter.bash @@ -3,6 +3,7 @@ cd /pretix/src export DJANGO_SETTINGS_MODULE=pretix.settings export MEDIA_ROOT=/data/ python3 manage.py migrate +python3 manage.py compress gunicorn \ -b '0.0.0.0:80' \ -w 3 --max-requests 1000 --max-requests-jitter 50 \