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('{1}', 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('{0}', force_text(form[cl.model._meta.pk.name])) + class ResultList(list): # Wrapper class used to return items in a list_editable # changelist, annotated with the form object for error @@ -275,6 +281,7 @@ class ResultList(list): self.form = form super(ResultList, self).__init__(*items) + def results(cl): if cl.formset: for res, form in zip(cl.result_list, cl.formset.forms): @@ -283,12 +290,14 @@ def results(cl): for res in cl.result_list: yield ResultList(None, items_for_result(cl, res, None)) + def result_hidden_fields(cl): if cl.formset: for res, form in zip(cl.result_list, cl.formset.forms): if form[cl.model._meta.pk.name].is_hidden: yield mark_safe(force_text(form[cl.model._meta.pk.name])) + @register.inclusion_tag("admin/change_list_results.html") def result_list(cl): """ @@ -305,6 +314,7 @@ def result_list(cl): 'num_sorted_fields': num_sorted_fields, 'results': list(results(cl))} + @register.inclusion_tag('admin/date_hierarchy.html') def date_hierarchy(cl): """ @@ -382,6 +392,7 @@ def date_hierarchy(cl): } for year in years] } + @register.inclusion_tag('admin/search_form.html') def search_form(cl): """ @@ -393,6 +404,7 @@ def search_form(cl): 'search_var': SEARCH_VAR } + @register.simple_tag def admin_list_filter(cl, spec): tpl = get_template(spec.template) @@ -402,6 +414,7 @@ def admin_list_filter(cl, spec): 'spec': spec, })) + @register.inclusion_tag('admin/actions.html', takes_context=True) def admin_actions(context): """ diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py index f30a142746..7665176228 100644 --- a/django/contrib/admin/templatetags/admin_modify.py +++ b/django/contrib/admin/templatetags/admin_modify.py @@ -2,6 +2,7 @@ from django import template register = template.Library() + @register.inclusion_tag('admin/prepopulated_fields_js.html', takes_context=True) def prepopulated_fields_js(context): """ @@ -19,6 +20,7 @@ def prepopulated_fields_js(context): context.update({'prepopulated_fields': prepopulated_fields}) return context + @register.inclusion_tag('admin/submit_line.html', takes_context=True) def submit_row(context): """ @@ -43,6 +45,7 @@ def submit_row(context): ctx['original'] = context['original'] return ctx + @register.filter def cell_count(inline_admin_form): """Returns the number of cells used in a tabular inline""" diff --git a/django/contrib/admin/templatetags/log.py b/django/contrib/admin/templatetags/log.py index 1b9e6aa7ef..7605d7f7fe 100644 --- a/django/contrib/admin/templatetags/log.py +++ b/django/contrib/admin/templatetags/log.py @@ -3,6 +3,7 @@ from django.contrib.admin.models import LogEntry register = template.Library() + class AdminLogNode(template.Node): def __init__(self, limit, varname, user): self.limit, self.varname, self.user = limit, varname, user @@ -20,6 +21,7 @@ class AdminLogNode(template.Node): context[self.varname] = LogEntry.objects.filter(user__pk__exact=user_id).select_related('content_type', 'user')[:int(self.limit)] return '' + @register.tag def get_admin_log(parser, token): """ diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index f9b17ad186..2242f7de58 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -18,6 +18,7 @@ from django.utils import six from django.utils.translation import ungettext from django.core.urlresolvers import reverse, NoReverseMatch + def lookup_needs_distinct(opts, lookup_path): """ Returns True if 'distinct()' should be used to query the given lookup path. @@ -31,6 +32,7 @@ def lookup_needs_distinct(opts, lookup_path): return True return False + def prepare_lookup_value(key, value): """ Returns a lookup value prepared to be used in queryset filtering. @@ -46,6 +48,7 @@ def prepare_lookup_value(key, value): value = True return value + def quote(s): """ Ensure that primary key values do not confuse the admin URLs by escaping diff --git a/django/contrib/admin/validation.py b/django/contrib/admin/validation.py index 0023d13f3b..12b3bdb211 100644 --- a/django/contrib/admin/validation.py +++ b/django/contrib/admin/validation.py @@ -410,14 +410,17 @@ def check_type(cls, attr, type_): raise ImproperlyConfigured("'%s.%s' should be a %s." % (cls.__name__, attr, type_.__name__)) + def check_isseq(cls, label, obj): if not isinstance(obj, (list, tuple)): raise ImproperlyConfigured("'%s.%s' must be a list or tuple." % (cls.__name__, label)) + def check_isdict(cls, label, obj): if not isinstance(obj, dict): raise ImproperlyConfigured("'%s.%s' must be a dictionary." % (cls.__name__, label)) + def get_field(cls, model, label, field): try: return model._meta.get_field(field) @@ -425,6 +428,7 @@ def get_field(cls, model, label, field): raise ImproperlyConfigured("'%s.%s' refers to field '%s' that is missing from model '%s.%s'." % (cls.__name__, label, field, model._meta.app_label, model.__name__)) + def fetch_attr(cls, model, label, field): try: return model._meta.get_field(field) diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index 2d50f47396..0066f86b52 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -49,8 +49,8 @@ class FilteredSelectMultiple(forms.SelectMultiple): % (name, self.verbose_name.replace('"', '\\"'), int(self.is_stacked), static('admin/'))) return mark_safe(''.join(output)) -class AdminDateWidget(forms.DateInput): +class AdminDateWidget(forms.DateInput): @property def media(self): js = ["calendar.js", "admin/DateTimeShortcuts.js"] @@ -62,8 +62,8 @@ class AdminDateWidget(forms.DateInput): final_attrs.update(attrs) super(AdminDateWidget, self).__init__(attrs=final_attrs, format=format) -class AdminTimeWidget(forms.TimeInput): +class AdminTimeWidget(forms.TimeInput): @property def media(self): js = ["calendar.js", "admin/DateTimeShortcuts.js"] @@ -75,6 +75,7 @@ class AdminTimeWidget(forms.TimeInput): final_attrs.update(attrs) super(AdminTimeWidget, self).__init__(attrs=final_attrs, format=format) + class AdminSplitDateTime(forms.SplitDateTimeWidget): """ A SplitDateTime Widget that has some admin-specific styling. @@ -90,6 +91,7 @@ class AdminSplitDateTime(forms.SplitDateTimeWidget): _('Date:'), rendered_widgets[0], _('Time:'), rendered_widgets[1]) + class AdminRadioFieldRenderer(RadioFieldRenderer): def render(self): """Outputs a