summaryrefslogtreecommitdiffstats
path: root/hobo/multitenant/middleware.py
diff options
context:
space:
mode:
Diffstat (limited to 'hobo/multitenant/middleware.py')
-rw-r--r--hobo/multitenant/middleware.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/hobo/multitenant/middleware.py b/hobo/multitenant/middleware.py
index 903d9c0..a855545 100644
--- a/hobo/multitenant/middleware.py
+++ b/hobo/multitenant/middleware.py
@@ -1,6 +1,8 @@
import os
import glob
+import hashlib
+from django.utils.encoding import smart_bytes
from django.conf import settings
from django.db import connection
from django.http import Http404, HttpResponseRedirect
@@ -27,7 +29,11 @@ class TenantMiddleware(object):
'''Convert hostname to PostgreSQL schema name'''
if hostname in getattr(settings, 'TENANT_MAPPING', {}):
return settings.TENANT_MAPPING[hostname]
- return hostname.replace('.', '_').replace('-', '_')
+ schema = hostname.replace('.', '_').replace('-', '_')
+ if len(schema) > 63:
+ digest = hashlib.md5(smart_bytes(schema)).hexdigest()[:4]
+ schema = '%s_%s_%s' % (schema[:29], digest, schema[-28:])
+ return schema
@classmethod
def get_tenant_by_hostname(cls, hostname):