Commit dc8814bf authored by Florian Apolloner's avatar Florian Apolloner
Browse files

Merge branch 'master' of github.com:django/django

parents acd0bb39 bd97f7d0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -505,6 +505,7 @@ answer newbie questions, and generally made Django that much better:
    Bernd Schlapsi
    schwank@gmail.com
    scott@staplefish.com
    Olivier Sels <olivier.sels@gmail.com>
    Ilya Semenov <semenov@inetss.com>
    Aleksandra Sendecka <asendecka@hauru.eu>
    serbaut@gmail.com
+0 −2
Original line number Diff line number Diff line
from django.conf import settings
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import get_current_site
from django.core.xheaders import populate_xheaders
from django.http import Http404, HttpResponse, HttpResponsePermanentRedirect
from django.shortcuts import get_object_or_404
from django.template import loader, RequestContext
@@ -70,5 +69,4 @@ def render_flatpage(request, f):
        'flatpage': f,
    })
    response = HttpResponse(t.render(c))
    populate_xheaders(request, response, FlatPage, f.id)
    return response
+2 −2
Original line number Diff line number Diff line
@@ -118,8 +118,8 @@ def get_validation_errors(outfile, app=None):
                    e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name)
                else:
                    for c in f.choices:
                        if not isinstance(c, (list, tuple)) or len(c) != 2:
                            e.add(opts, '"%s": "choices" should be a sequence of two-tuples.' % f.name)
                        if isinstance(c, six.string_types) or not is_iterable(c) or len(c) != 2:
                            e.add(opts, '"%s": "choices" should be a sequence of two-item iterables (e.g. list of 2 item tuples).' % f.name)
            if f.db_index not in (None, True, False):
                e.add(opts, '"%s": "db_index" should be either None, True or False.' % f.name)

django/core/xheaders.py

deleted100644 → 0
+0 −24
Original line number Diff line number Diff line
"""
Pages in Django can are served up with custom HTTP headers containing useful
information about those pages -- namely, the content type and object ID.

This module contains utility functions for retrieving and doing interesting
things with these special "X-Headers" (so called because the HTTP spec demands
that custom headers are prefixed with "X-").

Next time you're at slashdot.org, watch out for X-Fry and X-Bender. :)
"""

def populate_xheaders(request, response, model, object_id):
    """
    Adds the "X-Object-Type" and "X-Object-Id" headers to the given
    HttpResponse according to the given model and object_id -- but only if the
    given HttpRequest object has an IP address within the INTERNAL_IPS setting
    or if the request is from a logged in staff member.
    """
    from django.conf import settings
    if (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS
            or (hasattr(request, 'user') and request.user.is_active
                and request.user.is_staff)):
        response['X-Object-Type'] = "%s.%s" % (model._meta.app_label, model._meta.model_name)
        response['X-Object-Id'] = str(object_id)
+8 −0
Original line number Diff line number Diff line
@@ -670,6 +670,10 @@ class URLField(CharField):
            value = urlunsplit(url_fields)
        return value

    def clean(self, value):
        value = self.to_python(value).strip()
        return super(URLField, self).clean(value)


class BooleanField(Field):
    widget = CheckboxInput
@@ -1105,3 +1109,7 @@ class GenericIPAddressField(CharField):

class SlugField(CharField):
    default_validators = [validators.validate_slug]

    def clean(self, value):
        value = self.to_python(value).strip()
        return super(SlugField, self).clean(value)
Loading