Exemple #1
0
def cache_key_prefix(request):
    """
    Cache key for Mezzanine's cache middleware. Adds the current
    device and site ID.
    """
    return "%s.%s.%s." % (
        settings.CACHE_MIDDLEWARE_KEY_PREFIX,
        current_site_id(),
        device_from_request(request) or "default",
    )
Exemple #2
0
def cache_key_prefix(request):
    """
    Cache key for Mezzanine's cache middleware. Adds the current
    device and site ID.
    """
    cache_key = "%s.%s.%s." % (
        settings.CACHE_MIDDLEWARE_KEY_PREFIX,
        current_site_id(),
        device_from_request(request) or "default",
    )
    return _i18n_cache_key_suffix(request, cache_key)
Exemple #3
0
def cache_key_prefix(request, ignore_device=False):
    """
    Cache key for Mezzanine's cache middleware. Adds the current
    device and site ID, unless ignore_device is True in which case
    it will only add the current site ID.
    """
    cache_key = "%s.%s." % (
        settings.CACHE_MIDDLEWARE_KEY_PREFIX,
        current_site_id(),
    )

    if not ignore_device:
        cache_key += (device_from_request(request) or "default") + "."

    return _i18n_cache_key_suffix(request, cache_key)
Exemple #4
0
def get_template(template_name, context_instance):
    """
    Create a list of template paths for the given template name,
    prefixed with the device determined from the request, a default device 
    if set, and finally the original template name, all in this order.
    """
    from mezzanine.conf import settings
    template_name_list = []
    try:
        device = device_from_request(context_instance["request"])
    except KeyError:
        pass
    else:
        if device:
            template_name_list.append("%s/%s" % (device, template_name))
    if settings.DEFAULT_DEVICE:
        default = "%s/%s" % (settings.DEFAULT_DEVICE, template_name)
        if default not in template_name_list:
            template_name_list.append(default)
    template_name_list.append(template_name)
    return _select_template(template_name_list)
Exemple #5
0
 def set_key_prefix_for_device(self, request):
     device = device_from_request(request)
     self.key_prefix = "%s-%s" % (device,
                                  settings.CACHE_MIDDLEWARE_KEY_PREFIX)
Exemple #6
0
 def set_key_prefix_for_device(self, request):
     device = device_from_request(request)
     self.key_prefix = "%s-%s" % (device,
                                  settings.CACHE_MIDDLEWARE_KEY_PREFIX)
Exemple #7
0
def is_mobile(request):
    return device.device_from_request(request) == 'mobile'