Rootbuzz / shpaml

Load shpaml (haml-like html alternative) templates in django seamlessly. Should work fine extending normal HTML templates and being extended by them.
http://shpaml.com
BSD 3-Clause "New" or "Revised" License
46 stars 9 forks source link

Doesnt work with django 1.4 #2

Closed aisbaa closed 10 years ago

aisbaa commented 12 years ago

It might be that I miss configured something, but it spits out TypeError

template loader settings:

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

TEMPLATE_LOADERS = (
    ('shpaml.Loader', TEMPLATE_LOADERS),
) + TEMPLATE_LOADERS
Django Version: 1.4
Python Version: 2.7.2

  42.         return self.load_template(template_name, template_dirs)
File ".../buildout/eggs/django_shpaml-1.0.2-py2.7.egg/shpaml/loader.py" in load_template
  49.         template, origin = self.find_template(template_name, template_dirs)
File ".../buildout/eggs/django_shpaml-1.0.2-py2.7.egg/shpaml/loader.py" in find_template
  39.                 template, display_name = loader(name, dirs)
File ".../buildout/eggs/Django-1.4-py2.7.egg/django/template/loader.py" in __call__
  42.         return self.load_template(template_name, template_dirs)
File ".../buildout/eggs/Django-1.4-py2.7.egg/django/template/loader.py" in load_template
  45.         source, display_name = self.load_template_source(template_name, template_dirs)
File ".../buildout/eggs/django_shpaml-1.0.2-py2.7.egg/shpaml/loader.py" in load_template_source
  27.                         src = super(InnerLoader, self).load_template_source(*args, **kwargs)

Local vars:

self    <shpaml.loader.InnerLoader object at 0x36da590>
args  ('admin/timesheet/report/pdf.shpaml', None)
InnerLoader     <class 'shpaml.loader.InnerLoader'>
kwargs  {}
quinox commented 12 years ago

I'm could be missing something very important, but this loader seems to work just fine with Django 1.4:

import shpaml
from django.template.loaders import app_directories
from django.template.base import TemplateDoesNotExist

class Loader(app_directories.Loader):
    '''Loads Shpaml templates, see http://shpaml.com

    Note: only templates with the .shpaml suffix are procssed'''
    is_usable = True

    def load_template(self, template_name, template_dirs=None):
        if not template_name.endswith('.shpaml'):
            raise TemplateDoesNotExist(template_name)
        source, origin = self.load_template_source(template_name, template_dirs)
        return (shpaml.convert_text(source), origin)
quinox commented 12 years ago

It's not a wrapping loader, but it does work fine for filesystem access:

import shpaml
from django.template.loaders import app_directories, filesystem
from django.template.base import TemplateDoesNotExist

class ShpamlLoaderMixin(object):
    def load_template(self, template_name, template_dirs=None):
        if not template_name.endswith('.shpaml'):
            raise TemplateDoesNotExist(template_name)
        source, origin = self.load_template_source(template_name, template_dirs)
        return (shpaml.convert_text(source), origin)

class AppDirLoader(ShpamlLoaderMixin, app_directories.Loader):
    '''Loads Shpaml templates, see http://shpaml.com/

    Note: only templates with the .shpaml suffix are processed'''
    is_usable = True

class FilesystemLoader(ShpamlLoaderMixin, filesystem.Loader):
    '''Loads Shpaml templates, see http://shpaml.com/

    Note: only templates with the .shpaml suffix are processed'''
    is_usable = True
jiaaro commented 10 years ago

I'm pretty confident that the most recent releases with django 1.4 (since I currently have v1.2.x in production with django 1.4, recently upgraded from v1.1.x)