Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed TemplateResponse bits to use Django 1.3

This commit now requires Django 1.3 and correctly works on Django 1.3.1.
Future versions of this app will only use Django 1.3, but older versions can
still work on Django pre-1.3.
  • Loading branch information...
commit 806413c504770e3f33d1354233f1ddf91daa2360 1 parent f86a7fe
@brosner authored
View
2  django_openid/consumer.py
@@ -12,13 +12,13 @@
"""
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response
+from django.template.response import TemplateResponse
from openid.consumer import consumer
from openid.consumer.discover import DiscoveryFailure
from openid.yadis import xri
from django_openid.models import DjangoOpenIDStore
from django_openid.utils import OpenID, Router
from django_openid import signed
-from django_openid.response import TemplateResponse
class SessionPersist(object):
def get_user_session(self, request):
View
2  django_openid/provider.py
@@ -1,11 +1,11 @@
from django.conf import settings
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response
+from django.template.response import TemplateResponse
from openid.server.server import Server
from openid.extensions import sreg
from django_openid.models import DjangoOpenIDStore
from django_openid import signed
-from django_openid.response import TemplateResponse
class Provider(object):
"""
View
85 django_openid/response.py
@@ -1,85 +0,0 @@
-from django.http import HttpResponse
-from django.template import loader, Context, RequestContext
-
-class SimpleTemplateResponse(HttpResponse):
-
- def __init__(self, template, context, *args, **kwargs):
- # These two properties were originally called 'template' and 'context'
- # but django.test.client.Client was clobbering those leading to really
- # tricky-to-debug problems
- self.template_name = template
- self.template_context = context
- self.baked = False
- super(SimpleTemplateResponse, self).__init__(*args, **kwargs)
-
- def resolve_template(self, template):
- "Accepts a template object, path-to-template or list of paths"
- if isinstance(template, (list, tuple)):
- return loader.select_template(template)
- elif isinstance(template, basestring):
- return loader.get_template(template)
- else:
- return template
-
- def resolve_context(self, context):
- "context can be a dictionary or a context object"
- if isinstance(context, Context):
- return context
- else:
- return Context(context)
-
- def render(self):
- template = self.resolve_template(self.template_name)
- context = self.resolve_context(self.template_context)
- content = template.render(context)
- return content
-
- def bake(self):
- """
- The template is baked the first time you try to access
- response.content or iterate over it. This is a bit ugly, but is
- necessary because Django middleware sometimes expects to be able to
- over-write the content of a response.
- """
- if not self.baked:
- self.force_bake()
-
- def force_bake(self):
- "Call this if you have modified the template or context but are "
- "unsure if the template has already been baked."
- self._set_content(self.render())
- self.baked = True
-
- def __iter__(self):
- self.bake()
- return super(SimpleTemplateResponse, self).__iter__()
-
- def _get_content(self):
- self.bake()
- return super(SimpleTemplateResponse, self)._get_content()
-
- def _set_content(self, value):
- "Overrides rendered content, unless you later call force_bake()"
- return super(SimpleTemplateResponse, self)._set_content(value)
-
- content = property(_get_content, _set_content)
-
-class TemplateResponse(SimpleTemplateResponse):
-
- def __init__(self, request, template, context, *args, **kwargs):
- # self.request gets over-written by django.test.client.Client - and
- # unlike template_context and template_name the _request should not
- # be considered part of the public API.
- self._request = request
- super(TemplateResponse, self).__init__(
- template, context, *args, **kwargs
- )
-
- def resolve_context(self, context):
- if isinstance(context, Context):
- return context
- else:
- return RequestContext(self._request, context)
-
-# Even less verbose alias:
-render = TemplateResponse
Please sign in to comment.
Something went wrong with that request. Please try again.