TemplateContent content type patch for Django 1.8

26 views
Skip to first unread message

Janos Bekesi

unread,
Mar 22, 2016, 4:11:11 AM3/22/16
to Django FeinCMS
Hi all, 

while updating a feincms project to Django 1.8 (LTS), all stuff using TemplateContent content type broke. Django 1.8 uses a new template code to allow for various templating engines, which is not compatible with latest feincms (1.11.4).

I tried to fix it, and got a working solution, albeit somewhat patchy and not very thoroughly tested. If anyone has this problem, feel free to use the patch as a starting point. One could insert a django version detection to choose code variants, but I did not need this (it is a quick patch after all).

BTW, I think future versions of FeinCMS will use Djangos new templating code, so this patch will become obsolete for newer installations. The file to patch is feincms/content/template/models.py; see the code changes and the complete file (as attachment): 



try:
   
# the old version:
   
from django.template.loader import (
               
Context, Template, TemplateDoesNotExist, find_template_loader)
except ImportError:
   
from django.template import Context, Template
   
from django.template.loader import  TemplateDoesNotExist
   
from django.template.engine import Engine


# ...


@classmethod
   
def initialize_type(cls, TEMPLATE_LOADERS=DEFAULT_TEMPLATE_LOADERS,
                        TEMPLATE_PATH
='content/template'):
        cls
.template_path = TEMPLATE_PATH
        engine
= Engine() # account for the new template engine in Django 1.8
       
for loader in TEMPLATE_LOADERS:
           
if loader:
               
# With Django 1.6 find_template_loader blows up during
               
# syncdb, probably because component initialization order
               
# has changed. Work around by ignoring exceptions here,
               
# but of course, this will also swallow legitimate
               
# exceptions. Tough luck :-(
               
try:
                   
# was: cls.template_loaders.append(find_template_loader(loader))
                    cls
.template_loaders.append(engine.find_template_loader(loader))
               
except Exception:
                   
pass

Have fun,

   Janos


models.py

Martin J. Laubach

unread,
Apr 13, 2016, 6:49:33 AM4/13/16
to Django FeinCMS
Oh, great, thanks. I think Matthias has removed the template content for post 1.11.4 because of exactly that problem, but if that works well most of the time (ie. everybody who doesn't use a different templating engine), we can bring it back.

Reply all
Reply to author
Forward
0 new messages