2014-01-26 04:54:25 +08:00
|
|
|
from django.apps import apps
|
|
|
|
|
|
|
|
|
|
|
|
def get_current_site(request):
|
|
|
|
"""
|
2017-01-25 04:31:57 +08:00
|
|
|
Check if contrib.sites is installed and return either the current
|
2014-01-26 04:54:25 +08:00
|
|
|
``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)
|