

def current_site_id():
    '\n    Responsible for determining the current ``Site`` instance to use\n    when retrieving data for any ``SiteRelated`` models. If a request\n    is available, and the site can be determined from it, we store the\n    site against the request for subsequent retrievals. Otherwise the\n    order of checks is as follows:\n\n      - ``site_id`` in session. Used in the admin so that admin users\n        can switch sites and stay on the same domain for the admin.\n      - host for the current request matched to the domain of the site\n        instance.\n      - ``MEZZANINE_SITE_ID`` environment variable, so management\n        commands or anything else outside of a request can specify a\n        site.\n      - ``SITE_ID`` setting.\n\n    '
    from mezzanine.utils.cache import cache_installed, cache_get, cache_set
    request = current_request()
    site_id = getattr(request, 'site_id', None)
    if (request and (not site_id)):
        site_id = request.session.get('site_id', None)
        if (not site_id):
            domain = request.get_host().lower()
            if cache_installed():
                bits = (settings.CACHE_MIDDLEWARE_KEY_PREFIX, domain)
                cache_key = ('%s.site_id.%s' % bits)
                site_id = cache_get(cache_key)
            if (not site_id):
                try:
                    site = Site.objects.get(domain__iexact=domain)
                except Site.DoesNotExist:
                    pass
                else:
                    site_id = site.id
                    if cache_installed():
                        cache_set(cache_key, site_id)
            if (request and site_id):
                request.site_id = site_id
    if (not site_id):
        site_id = os.environ.get('MEZZANINE_SITE_ID', settings.SITE_ID)
    if (request and site_id and (not getattr(settings, 'TESTING', False))):
        request.site_id = site
    return site_id

dataset/ETHPy150Open stephenmcd/mezzanine/mezzanine/utils/sites.py current_site_id/VarMisuse@249/628 `site_id`->`site`