Exemplo n.º 1
0
def get_template(template_name, context_instance):
    """
    Create a list of template names, prefixed with the device specific 
    template directory names and ordered based on matching the user agent 
    string in the request context. Pass the list to Django's original 
    ``select_template``.
    """
    from mezzanine.conf import settings
    template_name_list = [template_name]
    if DEFAULT_DEVICE:
        default = "%s/%s" % (settings.DEFAULT_DEVICE, template_name)
        template_name_list.insert(0, default)
    try:
        user_agent = context_instance["request"].META["HTTP_USER_AGENT"]
    except KeyError:
        pass
    else:
        for (device, ua_strings) in DEVICE_USER_AGENTS:
            if device != DEFAULT_DEVICE:
                for ua_string in ua_strings:
                    if ua_string in user_agent:
                        path = "%s/%s" % (device, template_name)
                        template_name_list.insert(0, path)
                        break
    return _select_template(template_name_list)
Exemplo n.º 2
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)