From 824d12ba358d9befa88d0dc9ac36bfba24575dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Wed, 1 Oct 2014 11:22:35 -0300 Subject: [PATCH] =?UTF-8?q?Adicionada=20conex=C3=A3o=20a=20banco=20de=20da?= =?UTF-8?q?dos=20Moodle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- moodlerouter.py | 22 ++++++++++++++++++++++ sigi/settings/base.py | 3 +++ sigi/settings/dev.py | 4 ++++ 3 files changed, 29 insertions(+) create mode 100644 moodlerouter.py diff --git a/moodlerouter.py b/moodlerouter.py new file mode 100644 index 0000000..41e4a9a --- /dev/null +++ b/moodlerouter.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +class MoodleRouter(object): + def db_for_read(self, model, **hints): + if model._meta.app_label == 'mdl': + return 'moodle' + return None + + def db_for_write(self, model, **hints): + if model._meta.app_label == 'mdl': + return 'moodle' + return None + + def allow_relation(self, obj1, obj2, **hints): + if obj1._meta.app_label == 'mdl' and obj2._meta.app_label == 'mdl': + return True + return None + + def allow_migrate(self, db, model): + if model._meta.app_label == 'mdl': + return False + return None \ No newline at end of file diff --git a/sigi/settings/base.py b/sigi/settings/base.py index 6eb71b1..01d3857 100644 --- a/sigi/settings/base.py +++ b/sigi/settings/base.py @@ -37,6 +37,9 @@ TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) +# Database routers +DATABASE_ROUTERS = ['moodlerouter.MoodleRouter',] + # Application definition INSTALLED_APPS = ( diff --git a/sigi/settings/dev.py b/sigi/settings/dev.py index c9152e3..c5b35e9 100644 --- a/sigi/settings/dev.py +++ b/sigi/settings/dev.py @@ -8,6 +8,10 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'sigi.db'), + }, + 'moodle': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'moodle.db'), } }