Skip to content

Commit

Permalink
fix bug with generate link from subdomain to root domain
Browse files Browse the repository at this point in the history
  • Loading branch information
zerc committed Jan 29, 2015
1 parent 2fb5921 commit 3dffb0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 6 additions & 3 deletions django_js_reverse/templates/django_js_reverse/urls_js.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ this.{{ js_var_name }} = (function () {
'use_subdomains': {{ JS_USE_SUBDOMAIN }},
'urls': {{ urls|safe }},
'domains': {{ domains|safe }},
'url_prefix': '{{ url_prefix|escapejs }}'},
'url_prefix': '{{ url_prefix|escapejs }}',
'root_domain': '{{ root_domain }}'},
Urls = {};

Urls.get = function (name, subdomain) {
var domain;
var domain = config.root_domain;
if (config.use_subdomains && subdomain) {
domain = subdomain + '.' + location.host;
if (subdomain !== -1) {
domain = subdomain + '.' + domain;
}
} else {
domain = location.host
}
Expand Down
13 changes: 7 additions & 6 deletions django_js_reverse/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ def urls_js(request=None):

if JS_USE_SUBDOMAIN:
url_confs = settings.SUBDOMAIN_URLCONFS
_domain = get_domain()
root_domain = get_domain()
else:
url_confs = {None: getattr(request, 'urlconf', None)}
_domain = None
root_domain = None

urls = {}

for subdomain, urlconf in url_confs.items():
if subdomain is not None and _domain:
domain = '%s.%s' % (subdomain, _domain)
if subdomain is not None and root_domain:
domain = '%s.%s' % (subdomain, root_domain)
else:
domain = _domain
domain = root_domain

default_urlresolver = urlresolvers.get_resolver(urlconf)
row = urls.setdefault(domain, {})
Expand All @@ -98,7 +98,8 @@ def urls_js(request=None):
'url_prefix': urlresolvers.get_script_prefix(),
'js_var_name': js_var_name,
'JS_USE_SUBDOMAIN': json.dumps(JS_USE_SUBDOMAIN),
'domains': json.dumps(url_confs.keys())
'domains': json.dumps(url_confs.keys()),
'root_domain': root_domain
},
{})

Expand Down

0 comments on commit 3dffb0f

Please sign in to comment.