2014-01-26 04:54:25 +08:00
|
|
|
from django.apps import apps
|
|
|
|
|
2021-11-11 15:22:04 +08:00
|
|
|
from .requests import RequestSite
|
|
|
|
|
2014-01-26 04:54:25 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
2021-11-11 15:22:04 +08:00
|
|
|
# Import is inside the function because its point is to avoid importing the
|
|
|
|
# Site models when django.contrib.sites isn't installed.
|
2014-01-26 04:54:25 +08:00
|
|
|
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:
|
|
|
|
return RequestSite(request)
|