Skip to content

Commit

Permalink
New 0.6 version. Now compatible with Django 1.4
Browse files Browse the repository at this point in the history
git-svn-id: http://django-smart-extends.googlecode.com/svn/trunk@30 9df5bbc6-2602-82a0-fa3b-af6e0d1beed8
  • Loading branch information
msaelices@yaco.es committed Nov 7, 2012
1 parent 664693a commit fb9cb43
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 31 deletions.
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
0.6
---

* Compatible with Django 1.4 (need Django patches when DEBUG_TEMPLATE is False)

0.5.1
-----

* Compatible with Django 1.2 and Django 1.3 (need Django patches when DEBUG_TEMPLATE is False)
10 changes: 5 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ Smart extends is a Django application that allows improve
It is distributed under the terms of the license write in the same directory,
in the file LICENCE

Depencies
=========
Dependencies
============

Django 1.2 - 1.3 (Tested for those versions)
* For trunk code you will need Django 1.4

Django 1.1 - 1.1.X (There were two branches to those versions)
* There are specific branches for Django 1.2.X, 1.3.X and 1.1.X (There were two branches to those versions)

How to install
==============
Expand Down Expand Up @@ -78,5 +78,5 @@ file:admin/change_list.html
Patches
=======

If you set TEMPLATE_DEBUG = True in settings.py you must patch django code. You can find the patch in the patches directoy. There are one patch for Django 1.1.X version, other for Django 1.2 and other for Django 1.3.
If you set TEMPLATE_DEBUG = True in settings.py you must patch django code. You can find the patch in the patches directoy. There are one patch for Django 1.1.X version, other for Django 1.2 and other for Django 1.3. and Django 1.4

52 changes: 52 additions & 0 deletions patches/patch1.4.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
diff --git a/django/template/base.py b/django/template/base.py
index e2fc66b..09f114b 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -220,6 +220,7 @@ class Lexer(object):
else:
token = Token(TOKEN_TEXT, token_string)
token.lineno = self.lineno
+ token.source = self.origin, (-1, -1)
self.lineno += token_string.count('\n')
return token

@@ -297,6 +298,7 @@ class Parser(object):
"in the template." % node)
if isinstance(nodelist, NodeList) and not isinstance(node, TextNode):
nodelist.contains_nontext = True
+ node.source = token.source
nodelist.append(node)

def enter_command(self, command, token):
diff --git a/django/template/debug.py b/django/template/debug.py
index 74aa82b..8289cc3 100644
--- a/django/template/debug.py
+++ b/django/template/debug.py
@@ -55,10 +55,6 @@ class DebugParser(Parser):
def create_variable_node(self, contents):
return DebugVariableNode(contents)

- def extend_nodelist(self, nodelist, node, token):
- node.source = token.source
- super(DebugParser, self).extend_nodelist(nodelist, node, token)
-
def unclosed_block_tag(self, parse_until):
command, source = self.command_stack.pop()
msg = "Unclosed tag '%s'. Looking for one of: %s " % (command, ', '.join(parse_until))
diff --git a/django/template/loader.py b/django/template/loader.py
index 4185017..82f2ead 100644
--- a/django/template/loader.py
+++ b/django/template/loader.py
@@ -79,10 +79,9 @@ class LoaderOrigin(Origin):
return self.loader(self.loadname, self.dirs)[0]

def make_origin(display_name, loader, name, dirs):
- if settings.TEMPLATE_DEBUG and display_name:
+ if display_name:
return LoaderOrigin(display_name, loader, name, dirs)
- else:
- return None
+ return None

def find_template_loader(loader):
if isinstance(loader, (tuple, list)):
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def parse_dependency_links(file_name):

setup(
name="django-smart-extends",
version="0.5.1",
version="0.6",
author="Yaco Sistemas S.L.",
author_email="pmartin@yaco.es",
description="This application is useful when you want to overwrite a template of a application in your project. Currently this in Django produce infinite recursion ",
long_description=(read('README')),
long_description=(read('README') + '\n\n' + read('CHANGES')),
url='http://code.google.com/p/django-smart-extends/',
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
31 changes: 7 additions & 24 deletions smartextends/templatetags/smart_extends_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,38 +80,25 @@ def find_template(name, dirs=None, skip_template=None):
class SmartExtendsNode(ExtendsNode):

def __repr__(self):
if self.parent_name_expr:
return "<SmartExtendsNode: extends %s>" % self.parent_name_expr.token
return '<SmartExtendsNode: extends "%s">' % self.parent_name
return '<ExtendsNode: extends %s>' % self.parent_name.token

def get_source(self):
source = getattr(self, 'source', None)
return get_source(source)

def get_parent(self, context):
if self.parent_name_expr:
self.parent_name = self.parent_name_expr.resolve(context)
parent = self.parent_name
parent = getattr(self, 'full_parent_name', self.parent_name.resolve(context))
if not parent:
error_msg = "Invalid template name in 'extends' tag: %r." % parent
if self.parent_name_expr:
error_msg += " Got this from the '%s' variable." % self.parent_name_expr.token
if self.parent_name.filters or\
isinstance(self.parent_name.var, Variable):
error_msg += " Got this from the '%s' variable." % self.parent_name.token
raise TemplateSyntaxError(error_msg)
if hasattr(parent, 'render'):
return parent # parent is a Template object
source = self.get_source()
return get_template(parent, skip_template=source)

def render(self, context):
source = self.get_source()
if source and source.loadname == self.parent_name:
template = find_template(self.parent_name, skip_template=source)
template_source = template[0]
extends_tags = template_source.nodelist[0]
parent_source = get_source(getattr(extends_tags, 'source', None))
self.parent_name = getattr(parent_source, 'name', None)
return super(SmartExtendsNode, self).render(context)


def do_smart_extends(parser, token):
"""
Expand All @@ -125,15 +112,11 @@ def do_smart_extends(parser, token):
bits = token.split_contents()
if len(bits) != 2:
raise TemplateSyntaxError("'%s' takes one argument" % bits[0])
parent_name, parent_name_expr = None, None
if bits[1][0] in ('"', "'") and bits[1][-1] == bits[1][0]:
parent_name = bits[1][1:-1]
else:
parent_name_expr = parser.compile_filter(bits[1])
parent_name = parser.compile_filter(bits[1])
nodelist = parser.parse()
if nodelist.get_nodes_by_type(SmartExtendsNode):
raise TemplateSyntaxError("'%s' cannot appear more than once in the same template" % bits[0])
return SmartExtendsNode(nodelist, parent_name, parent_name_expr)
return SmartExtendsNode(nodelist, parent_name)


if getattr(settings, 'OVERWRITE_EXTENDS', False):
Expand Down

0 comments on commit fb9cb43

Please sign in to comment.