Skip to content

Commit

Permalink
Allow overriding get_domain to remove Site dependency.
Browse files Browse the repository at this point in the history
Refs #11
  • Loading branch information
tkaemming committed Sep 16, 2012
1 parent 9d6927a commit 2a5ea16
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions subdomains/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@


class SubdomainMiddleware(object):
def get_domain(self):
return Site.objects.get_current().domain

def process_request(self, request):
"""
Adds a `subdomain` attribute to the request object, which corresponds
to the portion of the URL before the current Site object's `domain`
attribute.
"""
site = Site.objects.get_current()
domain = site.domain
domain = self.get_domain()

# To allow for case-insensitive comparison, force the site.domain and
# the HTTP Host to lowercase.
Expand All @@ -39,8 +41,8 @@ def process_request(self, request):
if matches:
request.subdomain = matches.group('subdomain')
else:
error = 'The current host, %s, does not match the Site instance ' \
'specified by SITE_ID.' % request.get_host()
error = 'The current host %s does not belong to the current ' \
'domain.' % request.get_host()

if getattr(settings, 'USE_SUBDOMAIN_EXCEPTION', False):
raise IncorrectSiteException(error)
Expand Down

0 comments on commit 2a5ea16

Please sign in to comment.