Beispiel #1
0
 def override_settings(self, settings, folder_name):
     "pull settings from the respective settings.py and override those in django settings"
     site_package = 'sites.' + folder_name
     smod = importlib.import_module('.settings', package=site_package)
     skeys = [k for k in dir(smod) if not k.startswith('__')]
     self.stash = {}
     for k in skeys:
         self.stash[k] = getattr(settings, k, None)
         setattr(settings.__dict__['_wrapped'].__class__, k, make_tls_property(getattr(smod, k)))
 def override_settings(self, settings, folder_name):
     "pull settings from the respective settings.py and override those in django settings"
     site_package = 'sites.' + folder_name
     smod = importlib.import_module('.settings', package=site_package)
     skeys = [k for k in dir(smod) if not k.startswith('__')]
     self.stash = {}
     for k in skeys:
         if k in ('SITE_ID', 'TEMPLATE_DIRS'):
             # ignore site_id, because it is set in lookup()
             continue
         self.stash[k] = getattr(settings, k, None)
         setattr(settings.__dict__['_wrapped'].__class__, k, make_tls_property(getattr(smod, k)))
from django.conf import settings
from django.core.cache import cache
from django.contrib.sites.models import Site
from django.http import HttpResponsePermanentRedirect, Http404
from django.shortcuts import render_to_response
from django.utils.cache import patch_vary_headers
from django.utils.http import urlquote
from utils import make_tls_property

import logging
import os

SITE_ID = settings.__dict__['_wrapped'].__class__.SITE_ID = make_tls_property()
TEMPLATE_DIRS = settings.__dict__['_wrapped'].__class__.TEMPLATE_DIRS = make_tls_property(settings.TEMPLATE_DIRS)

class DynamicSitesError(Exception):
    pass

class DynamicSitesMiddleware(object):
    """
    Sets settings.SITE_ID based on request's domain.
    Also handles hostname redirects, and ensures the 
    proper subdomain is requested for the site
    """
    def process_request(self, request):
        self.logger = logging.getLogger(__name__)
        self.HOSTNAME_REDIRECTS = getattr(settings, "HOSTNAME_REDIRECTS", None)
        self.ENV_HOSTNAMES = getattr(settings, "ENV_HOSTNAMES", None)
        self.request = request
        self.site = None
        self.domain, self.port = self.get_domain_and_port()
from django.conf import settings

from utils import make_tls_property


to_monkeypatch = settings.__dict__['_wrapped'].__class__
SESSION_COOKIE_DOMAIN = make_tls_property()
to_monkeypatch.SESSION_COOKIE_DOMAIN = SESSION_COOKIE_DOMAIN
CSRF_COOKIE_DOMAIN = make_tls_property()
to_monkeypatch.CSRF_COOKIE_DOMAIN = CSRF_COOKIE_DOMAIN


class Middleware(object):
    '''
    Sets settings.SESSION_COOKIE_DOMAIN and settings.CSRF_COOKIE_DOMAIN
    to the host requested. All the browsers but IE would consider a cookie
    without domain specified to like this, howether IE is *special*.

    Be sure to put this middleware *before*
    django.contrib.sessions.middleware.SessionMiddleware in the
    MIDDLEWARE_CALSSES list.
    '''

    def process_request(self, request):
        host = request.get_host()
        if ':' in host:
            host, port = host.split(':')
        host = host.lower()

        SESSION_COOKIE_DOMAIN.value = host
        CSRF_COOKIE_DOMAIN.value = host
Beispiel #5
0
import logging

from django.conf import settings
from django.core.cache import cache
from django.contrib.sites.models import Site
from django.http import HttpResponsePermanentRedirect, Http404
from django.shortcuts import render_to_response
from django.utils.cache import patch_vary_headers
from django.utils.http import urlquote
from utils import make_tls_property
import os

SITE_ID = settings.__dict__['_wrapped'].__class__.SITE_ID = make_tls_property()
ROOT_URLCONF = settings.__dict__[
    '_wrapped'].__class__.ROOT_URLCONF = make_tls_property(
        settings.ROOT_URLCONF)
TEMPLATE_DIRS = settings.__dict__[
    '_wrapped'].__class__.TEMPLATE_DIRS = make_tls_property(
        settings.TEMPLATE_DIRS)


class DynamicSitesMiddleware(object):
    """
    Sets settings.SITE_ID based on request's domain
    Also handles hostname redirects, and ensures the
    proper subdomain is requested for the site
    """
    def process_request(self, request):
        self.logger = logging.getLogger(__name__)
        self.HOSTNAME_REDIRECTS = getattr(settings, "HOSTNAME_REDIRECTS", None)
        self.ENV_HOSTNAMES = getattr(settings, "ENV_HOSTNAMES", None)
Beispiel #6
0
from django.contrib.sites.models import Site
from django.core.cache import cache
from django.http import HttpResponse
from django.utils.cache import patch_vary_headers
from django.utils.translation import ugettext as _
from django.utils import translation


from models import SiteSettings
from utils import make_tls_property


_default_site_id = getattr(settings, 'SITE_ID', None)
_default_root_site_id = getattr(settings, 'ROOT_SITE_ID', None)
_default_language_code = getattr(settings, 'LANGUAGE_CODE', None)
SITE_ID = settings.__class__.SITE_ID = make_tls_property()
ROOT_SITE_ID = settings.__class__.ROOT_SITE_ID = make_tls_property()
LANGUAGE_CODE = settings.__class__.LANGUAGE_CODE = make_tls_property()
SITE_ID.value = _default_site_id
ROOT_SITE_ID.value = _default_root_site_id
LANGUAGE_CODE.value = _default_language_code


def generate_cache_key(domain):
  class_hash = hash(unicode(dir(Site)) + unicode(dir(SiteSettings)))
  return 'site:domain:%s:%s' % (class_hash, domain)


class DomainMiddleware(object):
  """Sets settings.SITE_ID based on request's domain"""
  def process_request(self, request):
Beispiel #7
0
from django.conf import settings
from django.core.cache import cache
from django.contrib.sites.models import Site
from django.http import HttpResponsePermanentRedirect, Http404
from django.utils.cache import patch_vary_headers
from django.utils.http import urlquote
from utils import make_tls_property

import logging
import os

SITE_ID = settings.__class__.SITE_ID = make_tls_property()
TEMPLATES_DIR = settings.__class__.TEMPLATES_DIR = make_tls_property()

class DynamicSitesMiddleware(object):
    """
    Sets settings.SITE_ID based on request's domain.
    Also handles hostname redirects, and ensures the 
    proper subdomain is requested for the site
    """
    def process_request(self, request):
        self.logger = logging.getLogger(__name__)
        self.HOSTNAME_REDIRECTS = getattr(settings, "HOSTNAME_REDIRECTS", None)
        self.ENV_HOSTNAMES = getattr(settings, "ENV_HOSTNAMES", None)
        self.request = request
        self.site = None
        self.domain, self.port = self.get_domain_and_port()
        self.domain_requested = self.domain
        self.domain_unsplit = self.domain
        self.subdomain = None
        self.env_domain_requested = None