Commit f7908e1e04f6b81348c584c97d39a06589a5c14a
1 parent
c6bb392a
Exists in
master
and in
39 other branches
Adding trac database and routers
Showing
2 changed files
with
42 additions
and
0 deletions
Show diff stats
src/colab/custom_settings.py
@@ -22,6 +22,25 @@ HAYSTACK_CONNECTIONS = { | @@ -22,6 +22,25 @@ HAYSTACK_CONNECTIONS = { | ||
22 | } | 22 | } |
23 | } | 23 | } |
24 | 24 | ||
25 | +DATABASES = { | ||
26 | + 'default': { | ||
27 | + 'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
28 | + 'NAME': 'colab', | ||
29 | + 'USER': 'colab', | ||
30 | + 'PASSWORD': os.environ.get('COLAB_DEFAULT_DB_PWD'), | ||
31 | + 'HOST': os.environ.get('COLAB_DEFAULT_DB_HOST'), | ||
32 | + }, | ||
33 | + 'trac': { | ||
34 | + 'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
35 | + 'NAME': 'trac', | ||
36 | + 'USER': 'trac', | ||
37 | + 'PASSWORD': os.environ.get('COLAB_TRAC_DB_PWD'), | ||
38 | + 'HOST': os.environ.get('COLAB_TRAC_DB_HOST'), | ||
39 | + } | ||
40 | +} | ||
41 | + | ||
42 | +DATABASE_ROUTERS = ['colab.routers.TracRouter',] | ||
43 | + | ||
25 | INSTALLED_APPS = INSTALLED_APPS + ( | 44 | INSTALLED_APPS = INSTALLED_APPS + ( |
26 | 45 | ||
27 | # Not standard apps | 46 | # Not standard apps |
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +class TracRouter(object): | ||
2 | + def db_for_read(self, model, **hints): | ||
3 | + if model._meta.app_label == 'proxy': | ||
4 | + return 'trac' | ||
5 | + return None | ||
6 | + | ||
7 | + def db_for_write(self, model, **hints): | ||
8 | + if model._meta.app_label == 'proxy': | ||
9 | + return 'trac' | ||
10 | + return None | ||
11 | + | ||
12 | + def allow_relation(self, obj1, obj2, **hints): | ||
13 | + if obj1._meta.app_label == 'proxy' or \ | ||
14 | + obj2._meta.app_label == 'proxy': | ||
15 | + return True | ||
16 | + return None | ||
17 | + | ||
18 | + def allow_migrate(self, db, model): | ||
19 | + if db == 'trac': | ||
20 | + return model._meta.app_label == 'proxy' | ||
21 | + elif model._meta.app_label == 'proxy': | ||
22 | + False | ||
23 | + return None |