models: Add support for using the root subdomain.

Previously, realm.uri and realm.host didn't support using a subdomain
of the empty string (""), aka using the root domain.

Also, since we're already accessing self.subdomain, we don't need to
check REALMS_HAVE_SUBDOMAINS again.
This commit is contained in:
Tim Abbott 2017-08-23 20:13:36 -07:00
parent f46f3871b4
commit 93fb6a1688
1 changed files with 2 additions and 2 deletions

View File

@ -248,7 +248,7 @@ class Realm(ModelReprMixin, models.Model):
@property
def uri(self):
# type: () -> str
if settings.REALMS_HAVE_SUBDOMAINS and self.subdomain is not None:
if self.subdomain not in [None, ""]:
return '%s%s.%s' % (settings.EXTERNAL_URI_SCHEME,
self.subdomain, settings.EXTERNAL_HOST)
return settings.SERVER_URI
@ -256,7 +256,7 @@ class Realm(ModelReprMixin, models.Model):
@property
def host(self):
# type: () -> str
if settings.REALMS_HAVE_SUBDOMAINS and self.subdomain is not None:
if self.subdomain not in [None, ""]:
return "%s.%s" % (self.subdomain, settings.EXTERNAL_HOST)
return settings.EXTERNAL_HOST