Пример #1
0
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',
    )
Пример #2
0
def _precondition_failed(request):
    response = HttpResponse(status=412)
    log_response(
        'Precondition Failed: %s',
        request.path,
        response=response,
        request=request,
    )
    return response
Пример #3
0
 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
Пример #4
0
    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())
Пример #5
0
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
Пример #6
0
 def __call__(self, request):
     return HttpResponse()
Пример #7
0
def process_view(request):
    return HttpResponse()
Пример #8
0
 def get_response(request):
     return HttpResponse(str(request.site.id))
Пример #9
0
 def a_view(request):
     return HttpResponse()
Пример #10
0
def etag_view_unquoted(request):
    """
    Use an etag_func() that returns an unquoted ETag.
    """
    return HttpResponse(FULL_RESPONSE)
Пример #11
0
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")])),
)
Пример #12
0
def last_modified_view2(request):
    return HttpResponse(FULL_RESPONSE)
Пример #13
0
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,
)
Пример #14
0
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()), )
Пример #15
0
def index(request):
    return HttpResponse(FULL_RESPONSE)
Пример #16
0
def etag_view_none(request):
    """
    Use an etag_func() that returns None, as opposed to setting etag_func=None.
    """
    return HttpResponse(FULL_RESPONSE)
Пример #17
0
def etag_view_weak(request):
    """
    Use an etag_func() that returns a weak ETag.
    """
    return HttpResponse(FULL_RESPONSE)
Пример #18
0
 def normal_view(request):
     template = engines['djmodels'].from_string("Hello world")
     return HttpResponse(template.render())
Пример #19
0
 def my_view(request):
     return HttpResponse("OK")
Пример #20
0
def helloworld(request):
    return HttpResponse("Hello World!")
Пример #21
0
def fully_decorated(request):
    """Expected __doc__"""
    return HttpResponse('<html><body>dummy</body></html>')
Пример #22
0
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',
    )
Пример #23
0
def etag_view2(request):
    return HttpResponse(FULL_RESPONSE)