diff options
| author | Chris Beaven <smileychris@gmail.com> | 2011-04-17 04:52:31 +0000 |
|---|---|---|
| committer | Chris Beaven <smileychris@gmail.com> | 2011-04-17 04:52:31 +0000 |
| commit | d59baa07f056b60942052b4809d71eecd323837a (patch) | |
| tree | 9ea84e3047ce31a35f76401f1cfc7b696b2c4f59 /django | |
| parent | 89e25403ae9dfcdc3eabd66469226d3036c6cc06 (diff) | |
Fixes #15721 -- Make {% include %} and RequestContext work together again.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16031 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/template/context.py | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/django/template/context.py b/django/template/context.py index bcfaa3bf9e..acc5758f75 100644 --- a/django/template/context.py +++ b/django/template/context.py @@ -14,21 +14,16 @@ class ContextPopException(Exception): "pop() has been called more times than push()" pass -class EmptyClass(object): - # No-op class which takes no args to its __init__ method, to help implement - # __copy__ - pass - class BaseContext(object): def __init__(self, dict_=None): - dict_ = dict_ or {} - self.dicts = [dict_] + self._reset_dicts(dict_) + + def _reset_dicts(self, value=None): + self.dicts = [value or {}] def __copy__(self): - duplicate = EmptyClass() - duplicate.__class__ = self.__class__ - duplicate.__dict__ = self.__dict__.copy() - duplicate.dicts = duplicate.dicts[:] + duplicate = copy(super(BaseContext, self)) + duplicate.dicts = self.dicts[:] return duplicate def __repr__(self): @@ -78,6 +73,15 @@ class BaseContext(object): return d[key] return otherwise + def new(self, values=None): + """ + Returns a new context with the same properties, but with only the + values given in 'values' stored. + """ + new_context = copy(self) + new_context._reset_dicts(values) + return new_context + class Context(BaseContext): "A stack container for variable context" def __init__(self, dict_=None, autoescape=True, current_app=None, use_l10n=None): @@ -88,7 +92,7 @@ class Context(BaseContext): super(Context, self).__init__(dict_) def __copy__(self): - duplicate = super(Context, self).__copy__() + duplicate = copy(super(Context, self)) duplicate.render_context = copy(self.render_context) return duplicate @@ -99,14 +103,6 @@ class Context(BaseContext): self.dicts.append(other_dict) return other_dict - def new(self, values=None): - """ - Returns a new Context with the same 'autoescape' value etc, but with - only the values given in 'values' stored. - """ - return self.__class__(dict_=values, autoescape=self.autoescape, - current_app=self.current_app, use_l10n=self.use_l10n) - class RenderContext(BaseContext): """ A stack container for storing Template state. |
