Commit Graph

587 Commits

Author SHA1 Message Date
Preston Timmons 7ae7600d2b [1.8.x] Updated docstring for firstof tag to reflect new auto-escaping behavior.
Backport of a1842e3299 from master
2015-04-03 07:29:09 -04:00
Tim Graham 5c63c45512 [1.8.x] Fixed #23441, #24555 -- Improved the behavior of InclusionNode.
This change:

* Makes the InclusionNode cache-safe by removing render-time side effects
  to its nodelist.
* Ensures the render_context stack is properly scoped and reset by updating
  the render call to use Template.render rather than Nodelist.render.

Backport of 0808ccce38 from master
2015-04-01 13:12:18 -04:00
Tim Heap ff8eabc5cc [1.8.x] Fixed #24538 -- Allowed self in Jinja context
Rendering a Jinja template with self in the context threw an error.
While self is a reserved variable in Jinja, including self in the
context is not an error, so Django should respect that.

Backport of 4ea1909d3c from master
2015-04-01 12:27:52 -04:00
Jon Walsh 2b267a70a1 [1.8.x] Fixed typo in escape_filter() docstring.
Backport of 8d90489fe0 from master
2015-03-19 07:22:21 -04:00
Erik Romijn d16e4e1d6f [1.8.x] Fixed #24464 -- Made built-in HTML template filter functions escape their input by default.
This may cause some backwards compatibility issues, but may also
resolve security issues in third party projects that fail to heed warnings
in our documentation.

Thanks Markus Holtermann for help with tests and docs.

Backport of fa350e2f30 from master
2015-03-09 09:31:07 -04:00
Aymeric Augustin e4e140c49b [1.8.x] Removed a non-obvious side-effect of assigning Context.template.
Explicit is better than implicit.

Backport of 51b606f from master
2015-02-20 22:28:24 +01:00
Aymeric Augustin cc4effba0b [1.8.x] Set context.template instead of context.engine while rendering.
This opens more possibilities, like accessing context.template.origin.

It also follows the chain of objects instead of following a shortcut.

Backport of 1bfcc95 from master
2015-02-19 22:10:56 +01:00
Tim Graham 1153bccc1b [1.8.x] Refs #24324 -- Fixed crash in {% debug %} tag on Python 2.
If Django is installed in a path that contains non-ASCII characters,
the tag failed with UnicodeDecodeError.

Backport of 098fa12dd3 from master
2015-02-18 07:35:56 -05:00
Tim Graham a1fa0135ec [1.8.x] Refs #24324 -- Fixed get_app_template_dirs() UnicodeDecodeError on Python 2.
The function implemented most of upath(), but skipped the check for
strings that are already unicode.

Backport of bad6280c4e from master
2015-02-17 08:24:36 -05:00
Preston Timmons 2b79a35a83 [1.8.x] Removed unnecessary __init__ definition from DebugLexer.
Backport of ad9ecc2c20 from master
2015-02-16 18:06:53 -05:00
Aymeric Augustin e8950668ca [1.8.x] Deprecated TEMPLATE_DEBUG setting.
Backport of 15b711b from master.
2015-02-15 20:48:48 +01:00
Aymeric Augustin 0f3eb8260b [1.8.x] Fixed #24338 -- Accepted Template wrapper in {% extends %}.
Explicitly checking for django.template.Template subclasses is
preferrable to duck-typing because both the django.template.Template and
django.template.backends.django.Template have a render() method.

Thanks spectras for the report.

Backport of 47ee7b48 from master
2015-02-14 10:36:44 +01:00
Aymeric Augustin 9b7b37382c [1.8.x] Split DTL context creation into its own function.
This reduces the length of rope RequestContext gives users to hang
themselves with.

Thanks Alex Hill for the report and Tim Graham for the review.

Backport of f2c104a from master.
2015-02-10 14:35:05 +01:00
Tim Graham a8b70d251d [1.8.x] Sorted imports with isort; refs #23860.
Backport of 0ed7d15563 from master
2015-02-09 14:24:06 -05:00
Alex Gaynor d54638727a [1.8.x] Simplified the lazy CSRF token implementation in csrf context processor.
This significantly improves performance on PyPy. The previous
implementation would generate a new class on every single request,
which is relatively slow.

Backport of 8099d33b65 from master
2015-02-08 15:03:29 -05:00
Collin Anderson fc8e1e0c10 [1.8.x] Fixed E265 comment style
Backport of db77915c9f from master
2015-02-06 09:35:08 -05:00
Aymeric Augustin aed1b1f6e5 [1.8.x] Fixed #24265 -- Preserved template backend loading exceptions.
If importing or initializing a template backend fails, attempting to
access this template backend again must raise the same exception.

Backport of 44ad6915 from master
2015-02-05 20:09:22 +01:00
Aymeric Augustin 5fbec369aa [1.8.x] Fixed #24273 -- Allowed copying RequestContext more than once.
Thanks Collin Anderson for the report.

Backport of 31d3a355 from master
2015-02-05 14:07:18 +01:00
Aymeric Augustin f87457a460 [1.8.x] Fixed #24168 -- Allowed selecting a template engine in a few APIs.
Specifically in rendering shortcuts, template responses, and class-based
views that return template responses.

Also added a test for render_to_response(status=...) which was missing
from fdbfc980.

Thanks Tim and Carl for the review.

Backport of 2133f31 from master.

Conflicts:
	docs/topics/http/shortcuts.txt
	tests/generic_views/test_base.py
2015-02-03 08:32:14 +01:00
David Robles eb6a07e069 [1.8.x] Fixed typo in 'Django Template Language'
Backport of d60b96d988 from master
2015-01-17 03:06:26 +01:00
Aymeric Augustin 79deb6a071 Accounted for multiple template engines in template responses. 2015-01-12 21:01:34 +01:00
Aymeric Augustin a3e783fe11 Deprecated passing a Context to a generic Template.render.
A deprecation path is required because the return type of
django.template.loader.get_template changed during the
multiple template engines refactor.

test_csrf_token_in_404 was incorrect: it tested the case when the
hardcoded template was rendered, and that template doesn't depend on the
CSRF token. This commit makes it test the case when a custom template is
rendered.
2015-01-12 21:01:34 +01:00
Aymeric Augustin 71b7668b75 Rewrapped TemplateSyntaxError in Jinja2 backend.
Changed import style to avoid confusion between Django's and Jinja2's
APIs.
2015-01-12 21:01:34 +01:00
Ola Sitarska d563e3be68 Fixed #23913 -- Deprecated the `=` comparison in `if` template tag. 2015-01-11 15:21:01 -05:00
Aymeric Augustin eaa1a22341 Added a request argument to render_to_string.
This is for consistency with Template.render.

It adds a little bit of knowledge about HTTP requests in
django.template.loader but I think consistency trumps purity.
2015-01-07 21:54:22 +01:00
Aymeric Augustin 118592663d Exposed Engine in the django.template namespace.
It's the main entrypoint to the refactored template system.
2015-01-07 21:54:22 +01:00
Aymeric Augustin 0cdb09d489 Made context take priority over context processors.
This is the expected behavior, but given RequestContext's tortuous
implementation, a straightforward use of its API results in the
opposite.

This commits fixes a regression that must have happened at different
points in the multiple templates engine refactor for different features.
2015-01-06 22:02:27 +01:00
Aymeric Augustin ed220c4cbe Added comments to remove Engine.render_to_string in Django 2.0.
Since this is a private API introduced in Django 1.8, no documentation
is required.
2015-01-06 22:02:26 +01:00
Preston Timmons de9ebdd39c Fixed #24022 -- Deprecated the ssi tag. 2015-01-05 19:35:02 -05:00
Aymeric Augustin 932d449f00 Explained the structure of django.template. 2014-12-28 17:02:31 +01:00
Aymeric Augustin b7282db833 Raised a warning when using the legacy TEMPLATE_* settings.
All tests now rely on TEMPLATES.
2014-12-28 17:02:31 +01:00
Aymeric Augustin 9eb4f28e89 Deprecated TEMPLATE_CONTEXT_PROCESSORS. 2014-12-28 17:02:31 +01:00
Aymeric Augustin 84d7c93feb Raised an error when allowed_include_roots is a string.
This avoids leaving projects silently vulnerable when this option is set
to a string instead of a one-item tuple containing that string, a very
common misconfiguration.
2014-12-28 17:02:29 +01:00
Aymeric Augustin cf1f36bb6e Deprecated current_app in TemplateResponse and render(_to_response). 2014-12-28 17:02:29 +01:00
Aymeric Augustin e53495ba33 Preserved context class in inclusion_tag.
Previously, when a template was rendered with RequestContext, inclusion
tags were rendered with a plain context, losing additional information
available in the RequestContext.

The (admittedly bizarre) implementation of RequestContext.new() has the
side-effect of not running template context processors, making this
change backwards-compatible.
2014-12-28 17:02:29 +01:00
Aymeric Augustin a0141f9eac Simplified implementation of django.shortcuts.render(_to_response).
*args, **kwargs brought more confusion than concision.
2014-12-28 17:00:07 +01:00
Aymeric Augustin 92e8f1f302 Moved context_processors from django.core to django.template. 2014-12-28 17:00:07 +01:00
Aymeric Augustin c599f233b1 Added a comment about the last use of Engine.get_default(). 2014-12-28 17:00:07 +01:00
Aymeric Augustin 90805b240f Supported multiple template engines in render_to_string.
Adjusted its API through a deprecation path according to the DEP.
2014-12-28 16:23:02 +01:00
Aymeric Augustin f9a6ebf6f5 Removed extraneous arguments in Engine.from_string.
This aligns the Django Template Engine API with the common template
backend API.
2014-12-28 16:23:02 +01:00
Aymeric Augustin f50a09f2cd Removed private API get_template_from_string.
It wasn't documented and it wasn't used anywhere.
2014-12-28 16:23:01 +01:00
Aymeric Augustin 5523e4cdbb Removed private API find_template.
It wasn't documented and it wasn't used anywhere, except in a few tests
that don't test it specifically and can be rewritten with get_template.
2014-12-28 16:23:01 +01:00
Aymeric Augustin 4ea43ac915 Supported multiple template engines in get_template and select_template.
This commit changes the return type of these two functions. Instead of
returning a django.template.Template they return a backend-specific
Template class that must implement render(self, context).
2014-12-28 16:23:01 +01:00
Aymeric Augustin 6854998c8f Looked up the default template engine in the list of all engines. 2014-12-28 16:23:01 +01:00
Aymeric Augustin b34b8a12b7 Passed a reference to the current engine when instantiating Template. 2014-12-28 16:23:00 +01:00
Aymeric Augustin 24dffaf0cb Removed some uses of global APIs from django.template.loader. 2014-12-28 16:23:00 +01:00
Aymeric Augustin 1eca0e95cf Added Django template backend. 2014-12-28 16:08:35 +01:00
Aymeric Augustin 44de7218a5 Added jinja2 template backend. 2014-12-28 16:08:34 +01:00
Aymeric Augustin 86c75996f0 Added dummy template backend. 2014-12-28 16:08:34 +01:00
Aymeric Augustin 1acfd624d6 Added initial support for loading template engines. 2014-12-28 16:08:31 +01:00