Fantomas42 / django-app-namespace-template-loader

Template loader allowing you to both extend and override a template at the same time.
BSD 3-Clause "New" or "Revised" License
59 stars 18 forks source link

TEMPLATE_LOADERS deprecated in 1.8 #4

Closed lachlansimpson closed 9 years ago

lachlansimpson commented 9 years ago

https://docs.djangoproject.com/en/1.8/ref/settings/#template-loaders

"Set the 'loaders' option in the OPTIONS of a DjangoTemplates backend instead."

lachlansimpson commented 9 years ago

I'm not a good enough programmer to know how to update this app properly, especially being able to provide support for Django 1.7 but in the mean time:

As per the 1.8 release notes, app_namespace/loader.py needs to have two lines fixed:

8 -from django.template.loader import BaseLoader 9 +from django.template.loaders.base import Loader

18 -class Loader(BaseLoader): 19 +class Loader(Loader):

Also, the installation notes need to reflect the new Template system and explicitly add the loaders in the new TEMPLATES setting.

These are the only changes I could see that need doing.

lachlansimpson commented 9 years ago

Actually this documentation is insufficient as in Django 1.7:

class BaseLoader(base.Loader):
    _accepts_engine_in_init = False

    def __init__(self, *args, **kwargs):

Whereas the replacement from Django 1.8:

class Loader(object):
    is_usable = False
    # Only used to raise a deprecation warning. Remove in Django 2.0.
    _accepts_engine_in_init = True

    def __init__(self, engine):
        self.engine = engine

Discovered via the error:

Exception Type:     TypeError
Exception Value:    __init__() takes exactly 2 arguments (3 given)
lachlansimpson commented 9 years ago

Ok, I've worked this one out and it works.

First, we need to adjust my first change, given the name clash:

from django.template.loaders.base import Loader as L

Then we need to change the call to init, because it has a new shape:

class Loader(L):
    """
    App namespace loader for allowing you to both extend and override
    a template provided by an app at the same time.
    """
    is_usable = True

    def __init__(self, engine):
        super(Loader, self).__init__(engine)
        self._already_used = []

FWIW, I've also updated jquery.js to 2.1.3 and bootstrap to 3.3.4 and it still works fine.

Fantomas42 commented 9 years ago

@datakid I have just made a new release (v0.3) enabling the support for Django 1.8.

Note: support for Python 2.6 has been dropped.

Thanks for your participation.

lachlansimpson commented 9 years ago

No problems - thanks for your code!