2014-01-26 04:54:25 +08:00
|
|
|
from django.apps import apps
|
|
|
|
|
|
|
|
|
|
|
|
def get_current_site(request):
|
|
|
|
"""
|
|
|
|
Checks if contrib.sites is installed and returns either the current
|
|
|
|
``Site`` object or a ``RequestSite`` object based on the request.
|
|
|
|
"""
|
|
|
|
# Imports are inside the function because its point is to avoid importing
|
|
|
|
# the Site models when django.contrib.sites isn't installed.
|
|
|
|
if apps.is_installed('django.contrib.sites'):
|
|
|
|
from .models import Site
|
2014-10-01 01:15:59 +08:00
|
|
|
return Site.objects.get_current(request)
|
2014-01-26 04:54:25 +08:00
|
|
|
else:
|
|
|
|
from .requests import RequestSite
|
|
|
|
return RequestSite(request)
|