Flexible template folder schema#28
Conversation
|
Hi @alanjds, what's the reason that you don't use the suggested template structure like: |
|
The designer feels that having both templates on the same folder helps him know what templates exist and what ones needs to be created |
|
I'm not very inclined to include your suggest change. Do you think it's ok for you to subclass the template |
|
Hum... I dont really think that one should subclass the Loader to have non-standard schemes. This is the reason why FLAVOURS_TEMPLATE_PREFIX exists IMHO. If I subclass the Loader in my project and do not call super(), and the logic changes on upstream, then I will have to keep attention to its code, like I would need in a monkey-patch. If I subclass and do call super(), I will have to process/split/match some templatename that django-mobile maybe had already changed. All this seems to be a lot harder then attaching a function that hooks the template name getter logic. Is there some caveat on accepting this change? Is there some "cleaning" that I could provide to ease the maintenance in the future? |
from django_mobile.loader import Loader as BaseLoader
class Loader(BaseLoader):
def prepare_template_name(self, template_name):
template_name = list(template_name.rpartition('/'))
name = list(template_name[-1].rpartition('.'))
name.insert(1, '-%s' % get_flavour())
del(template_name[-1])
template_name += name
return ''.join(template_name)When used this def __init__(self, *args, **kwargs):
loaders = []
templates_loader = list(settings.FLAVOURS_TEMPLATE_LOADERS)
templates_loader.pop(templates_loader.index('some_app.loader.Loader'))
for loader_name in templates_loader:
loader = find_template_loader(loader_name)
if loader is not None:
loaders.append(loader)
self.template_source_loaders = tuple(loaders)
super(BaseLoader, self).__init__(*args, **kwargs) |
|
@ToxicWar Looks like a lot more code than I need to do with this PR merged. But thanks for pointing me an example. |
e7c2eef to
1edf2f8
Compare
I needed a template directory schema where the flavor prefix cames after the last slash, like in:
/appname/{flavor}-template_name.htmlThen created the
FLAVOURS_TEMPLATE_NAMEGETTER, to be able to have such schema. Example:What you think?