Test project and examples now compatible with Django 1.7

This commit is contained in:
Bernardo Pires 2015-01-05 15:34:47 +01:00
parent 69441977a8
commit 845e19be9c
6 changed files with 36 additions and 5 deletions

View File

@ -1 +0,0 @@
__author__ = 'bernardo'

View File

@ -46,7 +46,11 @@ TENANT_APPS = (
TENANT_MODEL = "customers.Client" # app.Model
INSTALLED_APPS = TENANT_APPS + SHARED_APPS + ('tenant_schemas',)
import django
if django.VERSION >= (1, 7, 0):
INSTALLED_APPS = list(set(TENANT_APPS + SHARED_APPS))
else:
INSTALLED_APPS = TENANT_APPS + SHARED_APPS + ('tenant_schemas',)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',

View File

@ -1 +0,0 @@
/home/bernardo/projects/django-tenant-schemas/tenant_schemas

View File

@ -18,7 +18,11 @@
</ul><br>
<p>Just run the command below on your shell to sync <code>SHARED_APPS</code>. Make sure your environment
has <code>Django</code> and <code>django-tenant-schemas</code> available.</p>
{% if DJANGO17 %}
<pre>$ python manage.py migrate_schemas --shared</pre>
{% else %}
<pre>$ python manage.py sync_schemas --shared</pre>
{% endif %}
<p>When you're done refresh this page.</p>
{% elif no_public_tenant %}
<h2>Second Step: Create a public tenant</h2>
@ -81,7 +85,18 @@ Client(domain_url='tenant1.trendy-sass.com',
description='Our first real tenant, awesome!').save()</pre>
<p>Saving a tenant that didn't exist before will create their schema and sync <code>TENANT_APPS</code> automatically. You should see
the following lines as the result.</p>
<pre>=== Running syncdb for schema: tenant1
{% if DJANGO17 %}<pre>Operations to perform:
Synchronize unmigrated apps: customers, tenant_schemas
Apply all migrations: contenttypes, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying sessions.0001_initial... OK</pre>
{% else %}<pre>=== Running syncdb for schema: tenant1
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
@ -93,6 +108,7 @@ Creating table django_content_type
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)</pre>
{% endif %}
<p>This means your tenant was installed successfully. Now create the second tenant.</p>
<pre>
Client(domain_url='tenant2.trendy-sass.com',

View File

@ -89,6 +89,10 @@ TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.Loader',
)
DATABASE_ROUTERS = (
'tenant_schemas.routers.TenantSyncRouter',
)
MIDDLEWARE_CLASSES = (
'tenant_tutorial.middleware.TenantTutorialMiddleware',
'django.middleware.common.CommonMiddleware',
@ -137,7 +141,11 @@ TENANT_APPS = (
TENANT_MODEL = "customers.Client" # app.Model
INSTALLED_APPS = TENANT_APPS + SHARED_APPS + ('tenant_schemas',)
import django
if django.VERSION >= (1, 7, 0):
INSTALLED_APPS = list(set(TENANT_APPS + SHARED_APPS))
else:
INSTALLED_APPS = TENANT_APPS + SHARED_APPS + ('tenant_schemas',)
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.JSONSerializer'

View File

@ -1,3 +1,4 @@
import django
from django.conf import settings
from django.db import utils
from django.views.generic import TemplateView
@ -12,6 +13,10 @@ class HomeView(TemplateView):
context = super(HomeView, self).get_context_data(**kwargs)
hostname_without_port = remove_www(self.request.get_host().split(':')[0])
if django.VERSION >= (1, 7, 0):
context['DJANGO17'] = True
try:
Client.objects.get(schema_name='public')
except utils.DatabaseError: