On 1 December 2010 14:37, Ivan Sagalaev <man...@softwaremaniacs.org> wrote: > On 12/01/2010 04:26 PM, Łukasz Rekucki wrote: >> >> What about view decorators? >> >> I don't want to invent use cases here, but if I right now have a view >> decorator that on it's way out changes something that could alter how >> a template is rendered (like current language, some settings or the >> database contents), then changing to TemplateResponse will break this >> view. > > If you're talking about "right now" and "alter how a template is rendered" > then this view either doesn't return an HttpResponse instance or returns its > custom descendant. Hence such view won't be affected by introduction of a > new shortcut or TemplateResponse. > > What I'm talking about is that currently a middleware or a decorator that > expects a normal HttpResponse instance can only access its headers or > completely rendered content. The laziness of TemplateResponse can't break > it. > > May be I don't understand what you're trying to show here. Can you provide a > small example?
Sure. Maybe I'm just missing something (note: this doesn't have to be a setting - any side effect that can affect rendering, which includes the database). from django.conf import settings def without_localization(view): @wraps(view): def decorated(*args, **kwargs): # NOTE: I'm assuming this will actually have any effect - settings caching is a different issue old_value, settings.USE_L10N = settings.USE_L10N, False try: # If view uses HttpResponse, the template will be rendered with USE_L10N = False # If it uses TemplateResponse, nothing will be rendered (yet!) return view(*args, **kwargs) finally: # USE_L10N will be back to it's original value # and that value will be used at the time of baking settings.USE_L10N = old_value return decorated -- Łukasz Rekucki -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.