Compare commits

...

6 Commits

Author SHA1 Message Date
Benjamin Dauvergne 2055bd0d29 setup.py: use our own get_version() 2017-08-27 00:02:52 +02:00
Frédéric Péters 0b799d7b34 fix custom content type cache __get__ method (#10308) 2017-08-27 00:02:52 +02:00
Frédéric Péters c72ded80d2 import ContentType, ContentTypeManager from contenttypes module (#10308) 2017-08-27 00:02:51 +02:00
Benjamin Dauvergne 7b9313838b clear ContentType on each schema change (fixes #9891)
Also replace the cache dictionnary by a thread local variable to make it safe to
use multitenancy with threads.
2017-08-27 00:00:03 +02:00
Benjamin Dauvergne 6228c4ac6a Only build for python2 2017-08-27 00:00:01 +02:00
Jérôme Schneider 9ecb7cb69e initial import of debian/ packaging 2017-08-26 23:59:29 +02:00
15 changed files with 106 additions and 3 deletions

5
changelog Normal file
View File

@ -0,0 +1,5 @@
django-tenant-schemas (1.4.8-1) unstable; urgency=low
* source package automatically created by stdeb 0.8.2
-- Jérôme Schneider <jschneider@entrouvert.com> Tue, 14 Oct 2014 11:39:16 +0200

1
compat Normal file
View File

@ -0,0 +1 @@
7

11
control Normal file
View File

@ -0,0 +1,11 @@
Source: django-tenant-schemas
Maintainer: Jérôme Schneider <jschneider@entrouvert.com>
Section: python
Priority: optional
Build-Depends: python-setuptools (>= 0.6b3), python-all (>= 2.6.6-3), debhelper (>= 7)
Standards-Version: 3.9.1
Package: python-django-tenant-schemas
Architecture: all
Depends: ${misc:Depends}, ${python:Depends}
Description: Tenant support for Django using PostgreSQL schemas.

2
files Normal file
View File

@ -0,0 +1,2 @@
python-django-tenant-schemas_1.4.8-10-ga5f144a-1_all.deb python optional
python3-django-tenant-schemas_1.4.8-10-ga5f144a-1_all.deb python optional

View File

@ -0,0 +1,7 @@
# Automatically added by dh_python2:
if which pycompile >/dev/null 2>&1; then
pycompile -p python-django-tenant-schemas
fi
# End automatically added section

View File

@ -0,0 +1,12 @@
# Automatically added by dh_python2:
if which pyclean >/dev/null 2>&1; then
pyclean -p python-django-tenant-schemas
else
dpkg -L python-django-tenant-schemas | grep \.py$ | while read file
do
rm -f "${file}"[co] >/dev/null
done
fi
# End automatically added section

View File

@ -0,0 +1,4 @@
python:Versions=2.7
python:Provides=python2.7-django-tenant-schemas
python:Depends=python (>= 2.7), python (<< 2.8), python:any (>= 2.6.6-7~), python-django, python-psycopg2
misc:Depends=

View File

@ -0,0 +1,7 @@
# Automatically added by dhpython:
if which py3compile >/dev/null 2>&1; then
py3compile -p python3-django-tenant-schemas
fi
# End automatically added section

View File

@ -0,0 +1,10 @@
# Automatically added by dhpython:
if which py3clean >/dev/null 2>&1; then
py3clean -p python3-django-tenant-schemas
else
dpkg -L python3-django-tenant-schemas | perl -ne 's,/([^/]*)\.py$,/__pycache__/\1.*, or next; unlink $_ or die $! foreach glob($_)'
find /usr/lib/python3/dist-packages/ -type d -name __pycache__ -empty -print0 | xargs --null --no-run-if-empty rmdir
fi
# End automatically added section

View File

@ -0,0 +1,2 @@
python3:Depends=python3-psycopg2, python3-django, python3:any (>= 3.3.2-2~)
misc:Depends=

7
rules Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/make -f
# This file was automatically generated by stdeb 0.8.2 at
# Tue, 14 Oct 2014 11:39:16 +0200
%:
dh $@ --with python2

View File

@ -1,17 +1,36 @@
#!/usr/bin/env python
import os
import subprocess
from os.path import exists
from version import get_git_version
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
def get_version():
'''Use the VERSION, if absent generates a version with git describe, if not
tag exists, take 0.0.0- and add the length of the commit log.
'''
if os.path.exists('VERSION'):
with open('VERSION', 'r') as v:
return v.read()
if os.path.exists('.git'):
p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
result = p.communicate()[0]
if p.returncode == 0:
result = result.split()[0][1:]
else:
result = '0.0.0-%s' % len(subprocess.check_output(
['git', 'rev-list', 'HEAD']).splitlines())
return result.replace('-', '.').replace('.g', '+g')
return '0.0.0'
setup(
name='django-tenant-schemas',
version=get_git_version(),
version=get_version(),
author='Bernardo Pires Carneiro',
author_email='carneiro.be@gmail.com',
packages=[

1
source/format Normal file
View File

@ -0,0 +1 @@
3.0 (quilt)

1
source/options Normal file
View File

@ -0,0 +1 @@
extend-diff-ignore="\.egg-info$"

View File

@ -1,11 +1,13 @@
import re
import warnings
import psycopg2
import threading
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured, ValidationError
import django.db.utils
from django.contrib.contenttypes.models import ContentType, ContentTypeManager
from tenant_schemas.utils import get_public_schema_name, get_limit_set_calls
from tenant_schemas.postgresql_backend.introspection import DatabaseSchemaIntrospection
@ -72,6 +74,7 @@ class DatabaseWrapper(original_backend.DatabaseWrapper):
self.include_public_schema = include_public
self.set_settings_schema(self.schema_name)
self.search_path_set = False
ContentType.objects.clear_cache()
def set_schema(self, schema_name, include_public=True):
"""
@ -83,6 +86,7 @@ class DatabaseWrapper(original_backend.DatabaseWrapper):
self.include_public_schema = include_public
self.set_settings_schema(schema_name)
self.search_path_set = False
ContentType.objects.clear_cache()
def set_schema_to_public(self):
"""
@ -92,6 +96,7 @@ class DatabaseWrapper(original_backend.DatabaseWrapper):
self.schema_name = get_public_schema_name()
self.set_settings_schema(self.schema_name)
self.search_path_set = False
ContentType.objects.clear_cache()
def set_settings_schema(self, schema_name):
self.settings_dict['SCHEMA'] = schema_name
@ -170,3 +175,12 @@ class FakeTenant:
"""
def __init__(self, schema_name):
self.schema_name = schema_name
# Make the ContentType cache tenant and thread safe
ContentTypeManager._thread_local_cache = threading.local()
class ContentTypeCacheDescriptor(object):
def __get__(self, obj, owner):
if not hasattr(owner._thread_local_cache, '_cache'):
owner._thread_local_cache._cache = {}
return owner._thread_local_cache._cache
ContentTypeManager._cache = ContentTypeCacheDescriptor()