diff --git a/django/__init__.py b/django/__init__.py index b8077e17fa..5b4034bfed 100644 --- a/django/__init__.py +++ b/django/__init__.py @@ -1,5 +1,6 @@ VERSION = (1, 7, 0, 'alpha', 0) + def get_version(*args, **kwargs): # Don't litter django/__init__.py with all the get_version stuff. # Only import if it's actually called. diff --git a/django/bin/profiling/gather_profile_stats.py b/django/bin/profiling/gather_profile_stats.py index 177657ebbc..dd2733377c 100644 --- a/django/bin/profiling/gather_profile_stats.py +++ b/django/bin/profiling/gather_profile_stats.py @@ -12,6 +12,7 @@ import os import pstats import sys + def gather_stats(p): profiles = {} for f in os.listdir(p): diff --git a/django/bin/unique-messages.py b/django/bin/unique-messages.py index d89329145f..16ec0a7e06 100755 --- a/django/bin/unique-messages.py +++ b/django/bin/unique-messages.py @@ -3,6 +3,7 @@ import os import sys + def unique_messages(): basedir = None diff --git a/django/conf/urls/__init__.py b/django/conf/urls/__init__.py index 9f500ae8ba..2fe0cf5946 100644 --- a/django/conf/urls/__init__.py +++ b/django/conf/urls/__init__.py @@ -13,6 +13,7 @@ handler403 = 'django.views.defaults.permission_denied' handler404 = 'django.views.defaults.page_not_found' handler500 = 'django.views.defaults.server_error' + def include(arg, namespace=None, app_name=None): if isinstance(arg, tuple): # callable returning a namespace hint @@ -39,6 +40,7 @@ def include(arg, namespace=None, app_name=None): return (urlconf_module, app_name, namespace) + def patterns(prefix, *args): pattern_list = [] for t in args: @@ -49,6 +51,7 @@ def patterns(prefix, *args): pattern_list.append(t) return pattern_list + def url(regex, view, kwargs=None, name=None, prefix=''): if isinstance(view, (list, tuple)): # For include(...) processing. diff --git a/django/conf/urls/i18n.py b/django/conf/urls/i18n.py index 426c2b2d30..1b0a1da438 100644 --- a/django/conf/urls/i18n.py +++ b/django/conf/urls/i18n.py @@ -2,6 +2,7 @@ from django.conf import settings from django.conf.urls import patterns, url from django.core.urlresolvers import LocaleRegexURLResolver + def i18n_patterns(prefix, *args): """ Adds the language code prefix to every URL pattern within this diff --git a/django/conf/urls/static.py b/django/conf/urls/static.py index 8d305653bd..a596bbbb4b 100644 --- a/django/conf/urls/static.py +++ b/django/conf/urls/static.py @@ -1,8 +1,10 @@ import re + from django.conf import settings from django.conf.urls import patterns, url from django.core.exceptions import ImproperlyConfigured + def static(prefix, view='django.views.static.serve', **kwargs): """ Helper function to return a URL pattern for serving files in debug mode. diff --git a/django/contrib/admin/actions.py b/django/contrib/admin/actions.py index f67599a432..d215aa6259 100644 --- a/django/contrib/admin/actions.py +++ b/django/contrib/admin/actions.py @@ -11,6 +11,7 @@ from django.template.response import TemplateResponse from django.utils.encoding import force_text from django.utils.translation import ugettext_lazy, ugettext as _ + def delete_selected(modeladmin, request, queryset): """ Default action which deletes the selected objects. diff --git a/django/contrib/admin/bin/compress.py b/django/contrib/admin/bin/compress.py index e15f2d3ef6..7e5d4ea779 100644 --- a/django/contrib/admin/bin/compress.py +++ b/django/contrib/admin/bin/compress.py @@ -6,6 +6,7 @@ import sys js_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'static', 'admin', 'js') + def main(): usage = "usage: %prog [file1..fileN]" description = """With no file paths given this script will automatically diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py index 435abd0a16..4d970c2f8b 100644 --- a/django/contrib/admin/filters.py +++ b/django/contrib/admin/filters.py @@ -16,6 +16,7 @@ from django.contrib.admin.utils import (get_model_from_relation, reverse_field_path, get_limit_choices_to_from_path, prepare_lookup_value) from django.contrib.admin.options import IncorrectLookupParameters + class ListFilter(object): title = None # Human-readable title to appear in the right sidebar. template = 'admin/filter.html' diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index 5bc19872e9..ee38fdf1d5 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -19,6 +19,7 @@ from django.conf import settings ACTION_CHECKBOX_NAME = '_selected_action' + class ActionForm(forms.Form): action = forms.ChoiceField(label=_('Action:')) select_across = forms.BooleanField(label='', required=False, initial=0, @@ -26,6 +27,7 @@ class ActionForm(forms.Form): checkbox = forms.CheckboxInput({'class': 'action-select'}, lambda value: False) + class AdminForm(object): def __init__(self, form, fieldsets, prepopulated_fields, readonly_fields=None, model_admin=None): self.form, self.fieldsets = form, normalize_fieldsets(fieldsets) @@ -53,6 +55,7 @@ class AdminForm(object): return media media = property(_media) + class Fieldset(object): def __init__(self, form, name=None, readonly_fields=(), fields=(), classes=(), description=None, model_admin=None): @@ -77,6 +80,7 @@ class Fieldset(object): for field in self.fields: yield Fieldline(self.form, field, self.readonly_fields, model_admin=self.model_admin) + class Fieldline(object): def __init__(self, form, field, readonly_fields=None, model_admin=None): self.form = form # A django.forms.Form instance @@ -103,6 +107,7 @@ class Fieldline(object): def errors(self): return mark_safe('\n'.join(self.form[f].errors.as_ul() for f in self.fields if f not in self.readonly_fields).strip('\n')) + class AdminField(object): def __init__(self, form, field, is_first): self.field = form[field] # A django.forms.BoundField instance @@ -128,6 +133,7 @@ class AdminField(object): def errors(self): return mark_safe(self.field.errors.as_ul()) + class AdminReadonlyField(object): def __init__(self, form, field, is_first, model_admin=None): label = label_for_field(field, form._meta.model, model_admin) @@ -183,6 +189,7 @@ class AdminReadonlyField(object): result_repr = display_for_field(value, f) return conditional_escape(result_repr) + class InlineAdminFormSet(object): """ A wrapper around an inline formset for use in the admin system. @@ -238,6 +245,7 @@ class InlineAdminFormSet(object): return media media = property(_media) + class InlineAdminForm(AdminForm): """ A wrapper around an inline form for use in the admin system. @@ -300,6 +308,7 @@ class InlineAdminForm(AdminForm): from django.forms.formsets import ORDERING_FIELD_NAME return AdminField(self.form, ORDERING_FIELD_NAME, False) + class InlineFieldset(Fieldset): def __init__(self, formset, *args, **kwargs): self.formset = formset @@ -313,6 +322,7 @@ class InlineFieldset(Fieldset): yield Fieldline(self.form, field, self.readonly_fields, model_admin=self.model_admin) + class AdminErrorList(forms.utils.ErrorList): """ Stores all errors for the form/formsets in an add/change stage view. @@ -325,6 +335,7 @@ class AdminErrorList(forms.utils.ErrorList): for errors_in_inline_form in inline_formset.errors: self.extend(list(six.itervalues(errors_in_inline_form))) + def normalize_fieldsets(fieldsets): """ Make sure the keys in fieldset dictionaries are strings. Returns the @@ -335,6 +346,7 @@ def normalize_fieldsets(fieldsets): result.append((name, normalize_dictionary(options))) return result + def normalize_dictionary(data_dict): """ Converts all the keys in "data_dict" to strings. The keys must be diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 7d5a616cef..0b48cb0851 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -25,6 +25,7 @@ register = Library() DOT = '.' + @register.simple_tag def paginator_number(cl, i): """ @@ -40,6 +41,7 @@ def paginator_number(cl, i): mark_safe(' class="end"' if i == cl.paginator.num_pages-1 else ''), i+1) + @register.inclusion_tag('admin/pagination.html') def pagination(cl): """ @@ -86,6 +88,7 @@ def pagination(cl): '1': 1, } + def result_headers(cl): """ Generates the list column headers. @@ -167,11 +170,13 @@ def result_headers(cl): "class_attrib": format_html(' class="{0}"', ' '.join(th_classes)) if th_classes else '', } + def _boolean_icon(field_val): icon_url = static('admin/img/icon-%s.gif' % {True: 'yes', False: 'no', None: 'unknown'}[field_val]) return format_html('', icon_url, field_val) + def items_for_result(cl, result, form): """ Generates the actual list of data. @@ -266,6 +271,7 @@ def items_for_result(cl, result, form): if form and not form[cl.model._meta.pk.name].is_hidden: yield format_html('
%s
' % forms.ClearableFileInput.template_with_initial) template_with_clear = ('%s' % forms.ClearableFileInput.template_with_clear) + def url_params_from_lookup_dict(lookups): """ Converts the type of lookups specified in a ForeignKey limit_choices_to @@ -129,6 +134,7 @@ def url_params_from_lookup_dict(lookups): params.update(dict(items)) return params + class ForeignKeyRawIdWidget(forms.TextInput): """ A Widget for displaying ForeignKeys in the "raw_id" interface rather than @@ -187,6 +193,7 @@ class ForeignKeyRawIdWidget(forms.TextInput): except (ValueError, self.rel.to.DoesNotExist): return '' + class ManyToManyRawIdWidget(ForeignKeyRawIdWidget): """ A Widget for displaying ManyToMany ids in the "raw_id" interface rather than @@ -275,6 +282,7 @@ class RelatedFieldWidgetWrapper(forms.Widget): def id_for_label(self, id_): return self.widget.id_for_label(id_) + class AdminTextareaWidget(forms.Textarea): def __init__(self, attrs=None): final_attrs = {'class': 'vLargeTextField'} @@ -282,6 +290,7 @@ class AdminTextareaWidget(forms.Textarea): final_attrs.update(attrs) super(AdminTextareaWidget, self).__init__(attrs=final_attrs) + class AdminTextInputWidget(forms.TextInput): def __init__(self, attrs=None): final_attrs = {'class': 'vTextField'} @@ -289,6 +298,7 @@ class AdminTextInputWidget(forms.TextInput): final_attrs.update(attrs) super(AdminTextInputWidget, self).__init__(attrs=final_attrs) + class AdminEmailInputWidget(forms.EmailInput): def __init__(self, attrs=None): final_attrs = {'class': 'vTextField'} @@ -296,6 +306,7 @@ class AdminEmailInputWidget(forms.EmailInput): final_attrs.update(attrs) super(AdminEmailInputWidget, self).__init__(attrs=final_attrs) + class AdminURLFieldWidget(forms.URLInput): def __init__(self, attrs=None): final_attrs = {'class': 'vURLField'} @@ -325,9 +336,11 @@ class AdminIntegerFieldWidget(forms.TextInput): final_attrs.update(attrs) super(AdminIntegerFieldWidget, self).__init__(attrs=final_attrs) + class AdminBigIntegerFieldWidget(AdminIntegerFieldWidget): class_name = 'vBigIntegerField' + class AdminCommaSeparatedIntegerFieldWidget(forms.TextInput): def __init__(self, attrs=None): final_attrs = {'class': 'vCommaSeparatedIntegerField'} diff --git a/django/contrib/admindocs/middleware.py b/django/contrib/admindocs/middleware.py index ee3fe2cb2f..330b76423b 100644 --- a/django/contrib/admindocs/middleware.py +++ b/django/contrib/admindocs/middleware.py @@ -1,6 +1,7 @@ from django.conf import settings from django import http + class XViewMiddleware(object): """ Adds an X-View header to internal HEAD requests -- used by the documentation system. diff --git a/django/contrib/admindocs/tests/test_fields.py b/django/contrib/admindocs/tests/test_fields.py index e8fe0b0caa..dd465111a1 100644 --- a/django/contrib/admindocs/tests/test_fields.py +++ b/django/contrib/admindocs/tests/test_fields.py @@ -11,6 +11,7 @@ from django.utils.translation import ugettext as _ class CustomField(models.Field): description = "A custom field type" + class DescriptionLackingField(models.Field): pass diff --git a/django/contrib/admindocs/utils.py b/django/contrib/admindocs/utils.py index f75bf499df..ec2e291c3d 100644 --- a/django/contrib/admindocs/utils.py +++ b/django/contrib/admindocs/utils.py @@ -16,6 +16,7 @@ except ImportError: else: docutils_is_available = True + def trim_docstring(docstring): """ Uniformly trims leading/trailing whitespace from docstrings. @@ -30,6 +31,7 @@ def trim_docstring(docstring): trimmed = [lines[0].lstrip()] + [line[indent:].rstrip() for line in lines[1:]] return "\n".join(trimmed).strip() + def parse_docstring(docstring): """ Parse out the parts of a docstring. Returns (title, body, metadata). @@ -55,6 +57,7 @@ def parse_docstring(docstring): body = "\n\n".join(parts[1:]) return title, body, metadata + def parse_rst(text, default_reference_context, thing_being_parsed=None): """ Convert the string from reST to an XHTML fragment. @@ -92,6 +95,7 @@ ROLES = { 'tag': '%s/tags/#%s', } + def create_reference_role(rolename, urlbase): def _role(name, rawtext, text, lineno, inliner, options=None, content=None): if options is None: @@ -102,6 +106,7 @@ def create_reference_role(rolename, urlbase): return [node], [] docutils.parsers.rst.roles.register_canonical_role(rolename, _role) + def default_reference_role(name, rawtext, text, lineno, inliner, options=None, content=None): if options is None: options = {} diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index 405f6b2a74..d8f00d5df0 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -21,10 +21,12 @@ from django.utils.translation import ugettext as _ # Exclude methods starting with these strings from documentation MODEL_METHODS_EXCLUDE = ('_', 'add_', 'delete', 'save', 'set_') + class GenericSite(object): domain = 'example.com' name = 'my site' + @staff_member_required def doc_index(request): if not utils.docutils_is_available: @@ -33,6 +35,7 @@ def doc_index(request): 'root_path': urlresolvers.reverse('admin:index'), }, context_instance=RequestContext(request)) + @staff_member_required def bookmarklets(request): admin_root = urlresolvers.reverse('admin:index') @@ -41,6 +44,7 @@ def bookmarklets(request): 'admin_url': "%s://%s%s" % (request.scheme, request.get_host(), admin_root), }, context_instance=RequestContext(request)) + @staff_member_required def template_tag_index(request): if not utils.docutils_is_available: @@ -76,6 +80,7 @@ def template_tag_index(request): 'tags': tags }, context_instance=RequestContext(request)) + @staff_member_required def template_filter_index(request): if not utils.docutils_is_available: @@ -111,6 +116,7 @@ def template_filter_index(request): 'filters': filters }, context_instance=RequestContext(request)) + @staff_member_required def view_index(request): if not utils.docutils_is_available: @@ -141,6 +147,7 @@ def view_index(request): 'views': views }, context_instance=RequestContext(request)) + @staff_member_required def view_detail(request, view): if not utils.docutils_is_available: @@ -166,6 +173,7 @@ def view_detail(request, view): 'meta': metadata, }, context_instance=RequestContext(request)) + @staff_member_required def model_index(request): if not utils.docutils_is_available: @@ -176,6 +184,7 @@ def model_index(request): 'models': m_list }, context_instance=RequestContext(request)) + @staff_member_required def model_detail(request, app_label, model_name): if not utils.docutils_is_available: @@ -278,6 +287,7 @@ def model_detail(request, app_label, model_name): 'fields': fields, }, context_instance=RequestContext(request)) + @staff_member_required def template_detail(request, template): templates = [] @@ -307,10 +317,12 @@ def template_detail(request, template): # Helper functions # #################### + def missing_docutils_page(request): """Display an error message for people without docutils""" return render_to_response('admin_doc/missing_docutils.html') + def load_all_installed_template_libraries(): # Load/register all template tag libraries from installed apps. for module_name in template.get_templatetags_modules(): @@ -329,6 +341,7 @@ def load_all_installed_template_libraries(): except template.InvalidTemplateLibrary: pass + def get_return_data_type(func_name): """Return a somewhat-helpful data type given a function name""" if func_name.startswith('get_'): @@ -338,6 +351,7 @@ def get_return_data_type(func_name): return 'Integer' return '' + def get_readable_field_data_type(field): """Returns the description for a given field type, if it exists, Fields' descriptions can contain format strings, which will be interpolated @@ -345,6 +359,7 @@ def get_readable_field_data_type(field): return field.description % field.__dict__ + def extract_views_from_urlpatterns(urlpatterns, base=''): """ Return a list of views from a list of urlpatterns. @@ -371,6 +386,7 @@ def extract_views_from_urlpatterns(urlpatterns, base=''): named_group_matcher = re.compile(r'\(\?P(<\w+>).+?\)') non_named_group_matcher = re.compile(r'\(.*?\)') + def simplify_regex(pattern): """ Clean up urlpattern regexes into something somewhat readable by Mere Humans: diff --git a/django/contrib/auth/context_processors.py b/django/contrib/auth/context_processors.py index b8ead73eb4..474002e550 100644 --- a/django/contrib/auth/context_processors.py +++ b/django/contrib/auth/context_processors.py @@ -1,6 +1,7 @@ # PermWrapper and PermLookupDict proxy the permissions system into objects that # the template system can understand. + class PermLookupDict(object): def __init__(self, user, app_label): self.user, self.app_label = user, app_label diff --git a/django/contrib/auth/handlers/modwsgi.py b/django/contrib/auth/handlers/modwsgi.py index f14afcf290..8ada9750f1 100644 --- a/django/contrib/auth/handlers/modwsgi.py +++ b/django/contrib/auth/handlers/modwsgi.py @@ -27,6 +27,7 @@ def check_password(environ, username, password): finally: db.close_old_connections() + def groups_for_user(environ, username): """ Authorizes a user based on groups diff --git a/django/contrib/auth/tests/test_views.py b/django/contrib/auth/tests/test_views.py index d1268862cf..e2c0d38152 100644 --- a/django/contrib/auth/tests/test_views.py +++ b/django/contrib/auth/tests/test_views.py @@ -711,6 +711,7 @@ class LogoutTest(AuthViewsTestCase): "%s should be allowed" % good_url) self.confirm_logged_out() + @skipIfCustomUser @override_settings( PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',), diff --git a/django/contrib/auth/tests/urls.py b/django/contrib/auth/tests/urls.py index c6349a57d1..da504b85fa 100644 --- a/django/contrib/auth/tests/urls.py +++ b/django/contrib/auth/tests/urls.py @@ -10,11 +10,13 @@ from django.shortcuts import render_to_response from django.template import Template, RequestContext from django.views.decorators.cache import never_cache + class CustomRequestAuthenticationForm(AuthenticationForm): def __init__(self, request, *args, **kwargs): assert isinstance(request, HttpRequest) super(CustomRequestAuthenticationForm, self).__init__(request, *args, **kwargs) + @never_cache def remote_user_auth_view(request): "Dummy view for remote user tests" @@ -22,6 +24,7 @@ def remote_user_auth_view(request): c = RequestContext(request, {}) return HttpResponse(t.render(c)) + def auth_processor_no_attr_access(request): render_to_response('context_processors/auth_attrs_no_access.html', RequestContext(request, {}, processors=[context_processors.auth])) @@ -29,32 +32,39 @@ def auth_processor_no_attr_access(request): return render_to_response('context_processors/auth_attrs_test_access.html', {'session_accessed': request.session.accessed}) + def auth_processor_attr_access(request): render_to_response('context_processors/auth_attrs_access.html', RequestContext(request, {}, processors=[context_processors.auth])) return render_to_response('context_processors/auth_attrs_test_access.html', {'session_accessed': request.session.accessed}) + def auth_processor_user(request): return render_to_response('context_processors/auth_attrs_user.html', RequestContext(request, {}, processors=[context_processors.auth])) + def auth_processor_perms(request): return render_to_response('context_processors/auth_attrs_perms.html', RequestContext(request, {}, processors=[context_processors.auth])) + def auth_processor_perm_in_perms(request): return render_to_response('context_processors/auth_attrs_perm_in_perms.html', RequestContext(request, {}, processors=[context_processors.auth])) + def auth_processor_messages(request): info(request, "Message 1") return render_to_response('context_processors/auth_attrs_messages.html', RequestContext(request, {}, processors=[context_processors.auth])) + def userpage(request): pass + def custom_request_auth_login(request): return login(request, authentication_form=CustomRequestAuthenticationForm) diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index 891beaa642..5e11030f03 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -234,6 +234,7 @@ def password_reset_confirm(request, uidb64=None, token=None, return TemplateResponse(request, template_name, context, current_app=current_app) + def password_reset_complete(request, template_name='registration/password_reset_complete.html', current_app=None, extra_context=None): diff --git a/django/contrib/contenttypes/generic.py b/django/contrib/contenttypes/generic.py index 950211f6c4..10d3f7d4a5 100644 --- a/django/contrib/contenttypes/generic.py +++ b/django/contrib/contenttypes/generic.py @@ -154,6 +154,7 @@ class GenericForeignKey(six.with_metaclass(RenameGenericForeignKeyMethods)): setattr(instance, self.fk_field, fk) setattr(instance, self.cache_attr, value) + class GenericRelation(ForeignObject): """Provides an accessor to generic related objects (e.g. comments)""" @@ -293,6 +294,7 @@ class ReverseGenericRelatedObjectsDescriptor(object): for obj in value: manager.add(obj) + def create_generic_related_manager(superclass): """ Factory function for a manager that subclasses 'superclass' (which is a @@ -390,11 +392,12 @@ def create_generic_related_manager(superclass): return GenericRelatedObjectManager -class GenericRel(ForeignObjectRel): +class GenericRel(ForeignObjectRel): def __init__(self, field, to, related_name=None, limit_choices_to=None): super(GenericRel, self).__init__(field, to, related_name, limit_choices_to) + class BaseGenericInlineFormSet(BaseModelFormSet): """ A formset for generic inline objects to a parent. @@ -475,6 +478,7 @@ def generic_inlineformset_factory(model, form=ModelForm, FormSet.for_concrete_model = for_concrete_model return FormSet + class GenericInlineModelAdmin(InlineModelAdmin): ct_field = "content_type" ct_fk_field = "object_id" @@ -516,8 +520,10 @@ class GenericInlineModelAdmin(InlineModelAdmin): return generic_inlineformset_factory(self.model, **defaults) + class GenericStackedInline(GenericInlineModelAdmin): template = 'admin/edit_inline/stacked.html' + class GenericTabularInline(GenericInlineModelAdmin): template = 'admin/edit_inline/tabular.html' diff --git a/django/contrib/contenttypes/models.py b/django/contrib/contenttypes/models.py index 34d54441fe..75859bfa16 100644 --- a/django/contrib/contenttypes/models.py +++ b/django/contrib/contenttypes/models.py @@ -3,6 +3,7 @@ from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import smart_text, force_text from django.utils.encoding import python_2_unicode_compatible + class ContentTypeManager(models.Manager): # Cache to avoid re-looking up ContentType objects all over the place. diff --git a/django/contrib/contenttypes/tests.py b/django/contrib/contenttypes/tests.py index 3f648bd456..b73307d85f 100644 --- a/django/contrib/contenttypes/tests.py +++ b/django/contrib/contenttypes/tests.py @@ -15,10 +15,12 @@ from django.utils.encoding import python_2_unicode_compatible class ConcreteModel(models.Model): name = models.CharField(max_length=10) + class ProxyModel(ConcreteModel): class Meta: proxy = True + @python_2_unicode_compatible class FooWithoutUrl(models.Model): """ @@ -39,6 +41,7 @@ class FooWithUrl(FooWithoutUrl): def get_absolute_url(self): return "/users/%s/" % urlquote(self.name) + class FooWithBrokenAbsoluteUrl(FooWithoutUrl): """ Fake model defining a ``get_absolute_url`` method containing an error @@ -47,8 +50,8 @@ class FooWithBrokenAbsoluteUrl(FooWithoutUrl): def get_absolute_url(self): return "/users/%s/" % self.unknown_field -class ContentTypesTests(TestCase): +class ContentTypesTests(TestCase): def setUp(self): self.old_Site_meta_installed = Site._meta.installed ContentType.objects.clear_cache() diff --git a/django/contrib/contenttypes/views.py b/django/contrib/contenttypes/views.py index d2dc48ea08..7318cf4203 100644 --- a/django/contrib/contenttypes/views.py +++ b/django/contrib/contenttypes/views.py @@ -6,6 +6,7 @@ from django.contrib.sites.models import Site, get_current_site from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import ugettext as _ + def shortcut(request, content_type_id, object_id): """ Redirect to an object's page based on a content-type ID and an object ID. diff --git a/django/contrib/flatpages/admin.py b/django/contrib/flatpages/admin.py index 13294262f1..0d424cad37 100644 --- a/django/contrib/flatpages/admin.py +++ b/django/contrib/flatpages/admin.py @@ -3,6 +3,7 @@ from django.contrib.flatpages.models import FlatPage from django.utils.translation import ugettext_lazy as _ from django.contrib.flatpages.forms import FlatpageForm + class FlatPageAdmin(admin.ModelAdmin): form = FlatpageForm fieldsets = ( diff --git a/django/contrib/flatpages/forms.py b/django/contrib/flatpages/forms.py index a93a494096..883ec37f44 100644 --- a/django/contrib/flatpages/forms.py +++ b/django/contrib/flatpages/forms.py @@ -3,6 +3,7 @@ from django.conf import settings from django.contrib.flatpages.models import FlatPage from django.utils.translation import ugettext, ugettext_lazy as _ + class FlatpageForm(forms.ModelForm): url = forms.RegexField(label=_("URL"), max_length=100, regex=r'^[-\w/\.~]+$', help_text = _("Example: '/about/contact/'. Make sure to have leading" diff --git a/django/contrib/flatpages/middleware.py b/django/contrib/flatpages/middleware.py index 955f856ea4..2f494064f3 100644 --- a/django/contrib/flatpages/middleware.py +++ b/django/contrib/flatpages/middleware.py @@ -2,6 +2,7 @@ from django.contrib.flatpages.views import flatpage from django.http import Http404 from django.conf import settings + class FlatpageFallbackMiddleware(object): def process_response(self, request, response): if response.status_code != 404: diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py index 42bb3adf23..a33c090c3d 100644 --- a/django/contrib/flatpages/models.py +++ b/django/contrib/flatpages/models.py @@ -6,6 +6,7 @@ from django.core.urlresolvers import get_script_prefix from django.utils.translation import ugettext_lazy as _ from django.utils.encoding import iri_to_uri, python_2_unicode_compatible + @python_2_unicode_compatible class FlatPage(models.Model): url = models.CharField(_('URL'), max_length=100, db_index=True) diff --git a/django/contrib/flatpages/tests/test_forms.py b/django/contrib/flatpages/tests/test_forms.py index e60daead03..a216b37c67 100644 --- a/django/contrib/flatpages/tests/test_forms.py +++ b/django/contrib/flatpages/tests/test_forms.py @@ -7,6 +7,7 @@ from django.test import TestCase from django.test.utils import override_settings from django.utils import translation + @override_settings(SITE_ID=1) class FlatpageAdminFormTests(TestCase): fixtures = ['example_site'] diff --git a/django/contrib/flatpages/views.py b/django/contrib/flatpages/views.py index 20e930f343..0f87c90bfe 100644 --- a/django/contrib/flatpages/views.py +++ b/django/contrib/flatpages/views.py @@ -17,6 +17,8 @@ DEFAULT_TEMPLATE = 'flatpages/default.html' # or a redirect is required for authentication, the 404 needs to be returned # without any CSRF checks. Therefore, we only # CSRF protect the internal implementation. + + def flatpage(request, url): """ Public interface to the flat page view. @@ -44,6 +46,7 @@ def flatpage(request, url): raise return render_flatpage(request, f) + @csrf_protect def render_flatpage(request, f): """ diff --git a/django/contrib/formtools/preview.py b/django/contrib/formtools/preview.py index 2ef7b6d146..e7de911a8d 100644 --- a/django/contrib/formtools/preview.py +++ b/django/contrib/formtools/preview.py @@ -10,6 +10,7 @@ from django.contrib.formtools.utils import form_hmac AUTO_ID = 'formtools_%s' # Each form here uses this as its auto_id parameter. + class FormPreview(object): preview_template = 'formtools/preview.html' form_template = 'formtools/form.html' diff --git a/django/contrib/formtools/tests/forms.py b/django/contrib/formtools/tests/forms.py index 6f3ce4b0bd..354297870a 100644 --- a/django/contrib/formtools/tests/forms.py +++ b/django/contrib/formtools/tests/forms.py @@ -1,15 +1,18 @@ from django import forms + class TestForm(forms.Form): field1 = forms.CharField() field1_ = forms.CharField() bool1 = forms.BooleanField(required=False) date1 = forms.DateField(required=False) + class HashTestForm(forms.Form): name = forms.CharField() bio = forms.CharField() + class HashTestBlankForm(forms.Form): name = forms.CharField(required=False) bio = forms.CharField(required=False) diff --git a/django/contrib/formtools/tests/tests.py b/django/contrib/formtools/tests/tests.py index e15a310629..84b0c7e2d0 100644 --- a/django/contrib/formtools/tests/tests.py +++ b/django/contrib/formtools/tests/tests.py @@ -19,6 +19,7 @@ from django.contrib.formtools.tests.forms import ( success_string = "Done was called!" success_string_encoded = success_string.encode() + class TestFormPreview(preview.FormPreview): def get_context(self, request, form): context = super(TestFormPreview, self).get_context(request, form) @@ -31,6 +32,7 @@ class TestFormPreview(preview.FormPreview): def done(self, request, cleaned_data): return http.HttpResponse(success_string) + @override_settings( TEMPLATE_DIRS=( os.path.join(os.path.dirname(upath(__file__)), 'templates'),