Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ changed in your own ``settings.py``:

**Default:** ``'flavour'``

``FLAVOURS_TEMPLATE_NAMEGETTER``
Callable that creates the template name searched, based on **flavor** and
provided **template name**.

**Default:** callable equivalent of:

.. code-block:: python

def name_getter(flavor, template_name):
return u'%s/%s' % (flavor, template_name)

``FLAVOURS_TEMPLATE_PREFIX``
This string will be prefixed to the template names when searching for
flavoured templates. This is useful if you have many flavours and want to
Expand Down
3 changes: 2 additions & 1 deletion django_mobile/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class defaults(object):
FLAVOURS = (u'full', u'mobile',)
DEFAULT_MOBILE_FLAVOUR = u'mobile'
FLAVOURS_TEMPLATE_PREFIX = u''
FLAVOURS_TEMPLATE_NAMEGETTER = lambda _, flavour, template_name: u'%s/%s' % (flavour, template_name)
FLAVOURS_GET_PARAMETER = u'flavour'
FLAVOURS_STORAGE_BACKEND = u'cookie'
FLAVOURS_COOKIE_KEY = u'flavour'
Expand All @@ -39,4 +40,4 @@ class defaults(object):
FLAVOURS_TEMPLATE_LOADERS.append(loader)
FLAVOURS_TEMPLATE_LOADERS = tuple(FLAVOURS_TEMPLATE_LOADERS)

settings = SettingsProxy(django_settings, defaults)
settings = SettingsProxy(django_settings, defaults())
2 changes: 1 addition & 1 deletion django_mobile/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, *args, **kwargs):
super(BaseLoader, self).__init__(*args, **kwargs)

def prepare_template_name(self, template_name):
template_name = u'%s/%s' % (get_flavour(), template_name)
template_name = settings.FLAVOURS_TEMPLATE_NAMEGETTER(get_flavour(), template_name)
if settings.FLAVOURS_TEMPLATE_PREFIX:
template_name = settings.FLAVOURS_TEMPLATE_PREFIX + template_name
return template_name
Expand Down