Skip to content

Commit

Permalink
Use get_current_site to get domain name
Browse files Browse the repository at this point in the history
This makes it compatible with Django >= 1.9.
  • Loading branch information
bfirsh committed Dec 15, 2016
1 parent 0f8e148 commit a0fe6a6
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/shorturls/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import urlparse
from django.conf import settings
from django.contrib.sites.models import Site, RequestSite
from django.contrib.sites.shortcuts import get_current_site
from django.db import models
from django.http import HttpResponsePermanentRedirect, Http404
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -48,13 +48,9 @@ def redirect(request, prefix, tiny, converter=default_converter):
# First, look for an explicit setting.
if hasattr(settings, 'SHORTEN_FULL_BASE_URL') and settings.SHORTEN_FULL_BASE_URL:
base = settings.SHORTEN_FULL_BASE_URL

# Next, if the sites app is enabled, redirect to the current site.
elif Site._meta.installed:
base = 'http://{0!s}/'.format(Site.objects.get_current().domain)

# Finally, fall back on the current request.

# Finally, fall back on the current request or site.
else:
base = 'http://{0!s}/'.format(RequestSite(request).domain)
base = 'http://{0!s}/'.format(get_current_site(request).domain)

return HttpResponsePermanentRedirect(urlparse.urljoin(base, url))

0 comments on commit a0fe6a6

Please sign in to comment.