Exemplo n.º 1
0
    def get(self, _, templates):
        templates = templates.split(",")
        response = {}

        for template in templates:
            try:
                view_name, view_method = template.split(".")
            except ValueError:
                if not template in self.allowed_templates:
                    raise NotAcceptable("Template: {}".format(template))

                loader = Loader()
                name = "{}.html".format(template)
                template_body = loader.load_template_source(name)[0]

                response[template] = self.reformat_template(template_body)
            else:
                if view_name not in self.allowed_views.keys():
                    raise NotAcceptable("View: {}".format(view_name))

                view = self.allowed_views[view_name]

                if view_name in self.allowed_methods.keys() and \
                  view_method not in self.allowed_methods[view_name]:
                    raise NotAcceptable("Method: {}.{}".format(
                        view_name, view_method))

                views = getattr(view, view_method)()

                response[view_name] = views
                # response.update({"{}.{}".format(view_name, name): template_body\
                # 	for name, template_body in views.items()})

        return Response(response)
Exemplo n.º 2
0
def get_template(templatefile, failmsg="no template filename supplied"):
    """
    Retrieve template source from the supplied filename
    """
    assert templatefile, "get_template: %s" % failmsg
    # Instantiate a template loader
    loader = Loader()
    # Source: actual source code read from template file
    # File path: absolute file path of template file
    source, file_path = loader.load_template_source(templatefile)
    return source
Exemplo n.º 3
0
def do_include_raw(parser, token):
    """ 
    Performs a template include without parsing the context, just dumps the template in.
    """
    bits = token.split_contents()
    if len(bits) != 2:
        raise TemplateSyntaxError, "%r tag takes one argument: the name of the template to be included" % bits[
            0]

    template_name = bits[1]
    if template_name[0] in ('"',
                            "'") and template_name[-1] == template_name[0]:
        template_name = template_name[1:-1]

    #source, path = load_template_source(template_name)
    source, path = Loader().load_template_source(template_name)

    return template.TextNode(source)
Exemplo n.º 4
0
Arquivo: std.py Projeto: vaad2/vest
def template_to_source():
    import codecs
    from django.conf import settings
    from django.template.loaders.app_directories import Loader
    from common.models import SiteTemplate

    loader = Loader()

    apps_root = os.path.realpath('%s/../' % settings.PROJECT_ROOT)

    for st in SiteTemplate.objects.all():
        for filepath in loader.get_template_sources(st.name):
            try:
                if file_exists(filepath) and filepath.startswith(apps_root):
                    with codecs.open(filepath, 'w', 'utf8') as f:
                        f.write(st.content)
                        print st.name, filepath, '-ok'
            except IOError as e:
                pass
Exemplo n.º 5
0
 def get_extra_context(self, request):
     include = request.view_params.get('include')
     html, _ = Loader().load_template_source(include)
     html_snippet = highlight(html, HtmlDjangoLexer(),
                              HtmlFormatter(full=False, noclasses=True))
     return {'html': html_snippet, 'path': include}
Exemplo n.º 6
0
from django.template.loaders.app_directories import Loader

from .base import ConditionalJinja2LoaderMixin


class Loader(ConditionalJinja2LoaderMixin, Loader):
    pass


_loader = Loader()