Giter Club home page Giter Club logo

django-template-analyzer's People

Contributors

gannettchad avatar vdboor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

django-template-analyzer's Issues

iterating over Template misses nodes

Surprisingly calling get_node_instances(t.template, IfNode) and get_node_instances(t.template.nodelist, IfNode) are not equivalent. The latter is more complete and behaves to expectation. The former does not in that it misses all top level nodes.

It appears that treating t.template as an iterator is not guaranteed to enumerate all nodes at the top level because django apparently expects all nodes to themselves be iterable, and return itself if it has no children.

Support for dynamically included templates

Hello!

Thanks for writing and sharing this library, it's pretty handy! ๐Ÿ‘ ๐ŸŒฎ

I've bumped into an issue when using a dynamic include like {% include variable_pointing_to_a_template_path %} -- which is supported by Django, but fails with TemplateDoesNotExist when you run get_node_instances(...) on a template that contains that (see example project attached).

I believe it would be a better behavior to skip loading the template in these cases (when it's a dynamic variable instead of a hardcoded path).

This is the Traceback:

>>> from django.template.loader import get_template
>>> from django.template.base import VariableNode
>>> from template_analyzer.djangoanalyzer import get_node_instances
>>> tmpl = get_template('index.html')
>>> get_node_instances(tmpl, VariableNode)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 243, in get_node_instances
    return _scan_nodes(nodelist, context, instances)
  File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 158, in _scan_nodes
    results += _extend_nodelist(node, context, instance_types)
  File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 114, in _extend_nodelist
    results += _scan_nodes(block.nodelist, context, instance_types, block, ignore_blocks=all_block_names)
  File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 182, in _scan_nodes
    results += _scan_nodes(subnodelist, context, instance_types, current_block)
  File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/template_analyzer/djangoanalyzer.py", line 147, in _scan_nodes
    template = get_template(node.template.var)
  File "/home/elias/.virtualenvs/web/local/lib/python2.7/site-packages/django/template/loader.py", line 25, in get_template
    raise TemplateDoesNotExist(template_name, chain=chain)
TemplateDoesNotExist: template_point

Here is the content of the main templates showing the issue (attached a full project reproducing it):

$ cat myapp/templates/index.html 
{% extends "base.html" %}
{% block body %}
<h1>block index</h1>
{% with template_point="t1.html" %}
{% include template_point %}
{% endwith %}
{% endblock %}
$ cat myapp/templates/other.html 
{% extends "base.html" %}
{% block body %}
<h1>block other</h1>
{% with template_point="t2.html" %}
{% include template_point %}
{% endwith %}
{% endblock %}

testingproj.zip

'ExtendsNode' object has no attribute 'parent_name_expr'

I'm getting this error (in combination with django-fluent-pages & contents) while I try to achieve to create a page type with a predefined template:

AttributeError at /admin/fluent_pages/page/1/
'ExtendsNode' object has no attribute 'parent_name_expr'
# admin.py
class HomePageAdmin(PlaceholderEditorAdmin):
    def get_placeholder_data(self, request, obj):
      # Tell the base class which tabs to create
        template = self.get_page_template(obj)
        return get_template_placeholder_data(template)

    def get_page_template(self, obj):
        return get_template('homepage/base.html')
# homepage/base.html
{% extends "base.html" %}
{% load placeholder_tags %}

{% block content %}
<h1>{{ page.title }}</h1>
{% page_placeholder "homepage" title="Main content" %}
{% endblock %}

Exception is in:

/template_analyzer/djangoanalyzer.py in _extend_nodelist, line 52

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.