def render_to_kmz(*args, **kwargs): """ Compress the KML content and return as KMZ (using the correct MIME type). """ return HttpResponse( compress_kml(loader.render_to_string(*args, **kwargs)), content_type='application/vnd.google-earth.kmz', )
def _precondition_failed(request): response = HttpResponse(status=412) log_response( 'Precondition Failed: %s', request.path, response=response, request=request, ) return response
def __call__(self, request, *args, **kwargs): try: obj = self.get_object(request, *args, **kwargs) except ObjectDoesNotExist: raise Http404('Feed object does not exist.') feedgen = self.get_feed(obj, request) response = HttpResponse(content_type=feedgen.content_type) if hasattr(self, 'item_pubdate') or hasattr(self, 'item_updateddate'): # if item_pubdate or item_updateddate is defined for the feed, set # header so as ConditionalGetMiddleware is able to send 304 NOT MODIFIED response['Last-Modified'] = http_date( timegm(feedgen.latest_post_date().utctimetuple())) feedgen.write(response, 'utf-8') return response
def test_serialize_to_stream(self): obj = ComplexModel(field1='first', field2='second', field3='third') obj.save_base(raw=True) # Serialize the test database to a stream for stream in (StringIO(), HttpResponse()): serializers.serialize(self.serializer_name, [obj], indent=2, stream=stream) # Serialize normally for a comparison string_data = serializers.serialize(self.serializer_name, [obj], indent=2) # The two are the same if isinstance(stream, StringIO): self.assertEqual(string_data, stream.getvalue()) else: self.assertEqual(string_data, stream.content.decode())
def render_flatpage(request, f): """ Internal interface to the flat page view. """ # If registration is required for accessing this page, and the user isn't # logged in, redirect to the login page. if f.registration_required and not request.user.is_authenticated: from djmodels.contrib.auth.views import redirect_to_login return redirect_to_login(request.path) if f.template_name: template = loader.select_template((f.template_name, DEFAULT_TEMPLATE)) else: template = loader.get_template(DEFAULT_TEMPLATE) # To avoid having to always use the "|safe" filter in flatpage templates, # mark the title and content as already safe (since they are raw HTML # content in the first place). f.title = mark_safe(f.title) f.content = mark_safe(f.content) response = HttpResponse(template.render({'flatpage': f}, request)) return response
def __call__(self, request): return HttpResponse()
def process_view(request): return HttpResponse()
def get_response(request): return HttpResponse(str(request.site.id))
def a_view(request): return HttpResponse()
def etag_view_unquoted(request): """ Use an etag_func() that returns an unquoted ETag. """ return HttpResponse(FULL_RESPONSE)
from djmodels.conf.urls import url from djmodels.conf.urls.i18n import i18n_patterns from djmodels.http import HttpResponse, StreamingHttpResponse from djmodels.utils.translation import gettext_lazy as _ urlpatterns = i18n_patterns( url(r'^simple/$', lambda r: HttpResponse()), url(r'^streaming/$', lambda r: StreamingHttpResponse([_("Yes"), "/", _("No")])), )
def last_modified_view2(request): return HttpResponse(FULL_RESPONSE)
from djmodels.conf.urls import url from djmodels.conf.urls.i18n import i18n_patterns from djmodels.http import HttpResponse from djmodels.utils.translation import gettext_lazy as _ urlpatterns = i18n_patterns( url(r'^(?P<arg>[\w-]+)-page', lambda request, **arg: HttpResponse(_("Yes"))), url(r'^simple/$', lambda r: HttpResponse(_("Yes"))), url(r'^(.+)/(.+)/$', lambda *args: HttpResponse()), prefix_default_language=False, )
from djmodels.conf.urls import url from djmodels.conf.urls.i18n import i18n_patterns from djmodels.http import HttpResponse urlpatterns = i18n_patterns(url(r'^exists/$', lambda r: HttpResponse()), )
def index(request): return HttpResponse(FULL_RESPONSE)
def etag_view_none(request): """ Use an etag_func() that returns None, as opposed to setting etag_func=None. """ return HttpResponse(FULL_RESPONSE)
def etag_view_weak(request): """ Use an etag_func() that returns a weak ETag. """ return HttpResponse(FULL_RESPONSE)
def normal_view(request): template = engines['djmodels'].from_string("Hello world") return HttpResponse(template.render())
def my_view(request): return HttpResponse("OK")
def helloworld(request): return HttpResponse("Hello World!")
def fully_decorated(request): """Expected __doc__""" return HttpResponse('<html><body>dummy</body></html>')
def render_to_kml(*args, **kwargs): "Render the response as KML (using the correct MIME type)." return HttpResponse( loader.render_to_string(*args, **kwargs), content_type='application/vnd.google-earth.kml+xml', )
def etag_view2(request): return HttpResponse(FULL_RESPONSE)