Permalink
Browse files

Simplify database settings.

  • Loading branch information...
Michael Nelson
Michael Nelson committed Jun 25, 2014
1 parent c32e2b4 commit efe145623faf160d5d50b2a83f5a54c5b1fcf074
Showing with 22 additions and 25 deletions.
  1. +12 −2 playbook.yml
  2. +9 −0 templates/database_settings.py.j2
  3. +1 −23 templates/settings.py.j2
View
@@ -45,11 +45,21 @@
owner: "{{ wsgi_user }}"
group: "{{ wsgi_group }}"
tags:
- - install
- - upgrade-charm
+ - config-changed
+ notify:
+ - Restart wsgi
+
+ - name: Write the database settings
+ template:
+ src: "templates/database_settings.py.j2"
+ dest: "{{ application_dir }}/django-project/clickreviewsproject/database_settings.py"
+ owner: "{{ wsgi_user }}"
+ group: "{{ wsgi_group }}"
+ tags:
- db-relation-changed
notify:
- Restart wsgi
+ when: "'database' in current_relation"
# XXX Normally our deployment build would ensure these are all available in the tarball.
- name: Install any non-distro dependencies (Don't depend on pip for a real deployment!)
@@ -0,0 +1,9 @@
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.postgresql_psycopg2',
+ 'NAME': '{{ current_relation["database"] }}',
+ 'HOST': '{{ current_relation["host"] }}',
+ 'USER': '{{ current_relation["user"] }}',
+ 'PASSWORD': '{{ current_relation["password"] }}',
+ }
+}
View
@@ -2,29 +2,7 @@ DEBUG = True
TEMPLATE_DEBUG = DEBUG
SECRET_KEY = '{{ django_secret_key }}'
-{% if 'db' in relations %}
-DATABASES = {
- {% for dbrelation in relations['db'] %}
- {% if loop.first %}
- {% set services=relations['db'][dbrelation] %}
- {% for service in services %}
- {% if service.startswith('postgres') %}
- {% set dbdetails = services[service] %}
- {% if 'database' in dbdetails %}
- 'default': {
- 'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': '{{ dbdetails["database"] }}',
- 'HOST': '{{ dbdetails["host"] }}',
- 'USER': '{{ dbdetails["user"] }}',
- 'PASSWORD': '{{ dbdetails["password"] }}',
- }
- {% endif %}
- {% endif %}
- {% endfor %}
- {% endif %}
- {% endfor %}
-}
-{% endif %}
+from database_settings import DATABASES
TIME_ZONE = 'UTC'
ROOT_URLCONF = 'clickreviewsproject.urls'

0 comments on commit efe1456

Please sign in to comment.