Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable get_domain added. #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion subdomains/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from django.conf import settings
from django.contrib.sites.models import Site
from django.utils.importlib import import_module
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import reverse as simple_reverse


Expand All @@ -16,7 +18,31 @@ def current_site_domain():

return domain

get_domain = current_site_domain

def get_domain():
global get_domain

fn_path = getattr(settings, 'SUBDOMAIN_GET_DOMAIN')

if fn_path is None:
get_domain = current_site_domain

else:
module_name, fn_name = fn_path.rsplit('.', 1)

try:
module = import_module(module_name)
fn = getattr(module, fn_name)
assert callable(fn)

except (ImportError, AttributeError, AssertionError):
raise ImproperlyConfigured('SUBDOMAIN_GET_DOMAIN doesn\'t exist or'
' isn\'t a callable.')

else:
get_domain = fn

return get_domain()


def urljoin(domain, path=None, scheme=None):
Expand Down