Permalink
Browse files

Started attackign the next flake8 violation

  • Loading branch information...
1 parent a023a84 commit 726ded5708e4e8767e69a6f6f6a039e75667ce03 @alex alex committed Oct 31, 2013
Showing with 128 additions and 4 deletions.
  1. +1 −0 django/__init__.py
  2. +1 −0 django/bin/profiling/gather_profile_stats.py
  3. +1 −0 django/bin/unique-messages.py
  4. +3 −0 django/conf/urls/__init__.py
  5. +1 −0 django/conf/urls/i18n.py
  6. +2 −0 django/conf/urls/static.py
  7. +1 −0 django/contrib/admin/actions.py
  8. +1 −0 django/contrib/admin/bin/compress.py
  9. +1 −0 django/contrib/admin/filters.py
  10. +12 −0 django/contrib/admin/helpers.py
  11. +13 −0 django/contrib/admin/templatetags/admin_list.py
  12. +3 −0 django/contrib/admin/templatetags/admin_modify.py
  13. +2 −0 django/contrib/admin/templatetags/log.py
  14. +3 −0 django/contrib/admin/utils.py
  15. +4 −0 django/contrib/admin/validation.py
  16. +15 −2 django/contrib/admin/widgets.py
  17. +1 −0 django/contrib/admindocs/middleware.py
  18. +1 −0 django/contrib/admindocs/tests/test_fields.py
  19. +5 −0 django/contrib/admindocs/utils.py
  20. +16 −0 django/contrib/admindocs/views.py
  21. +1 −0 django/contrib/auth/context_processors.py
  22. +1 −0 django/contrib/auth/handlers/modwsgi.py
  23. +1 −0 django/contrib/auth/tests/test_views.py
  24. +10 −0 django/contrib/auth/tests/urls.py
  25. +1 −0 django/contrib/auth/views.py
  26. +7 −1 django/contrib/contenttypes/generic.py
  27. +1 −0 django/contrib/contenttypes/models.py
  28. +4 −1 django/contrib/contenttypes/tests.py
  29. +1 −0 django/contrib/contenttypes/views.py
  30. +1 −0 django/contrib/flatpages/admin.py
  31. +1 −0 django/contrib/flatpages/forms.py
  32. +1 −0 django/contrib/flatpages/middleware.py
  33. +1 −0 django/contrib/flatpages/models.py
  34. +1 −0 django/contrib/flatpages/tests/test_forms.py
  35. +3 −0 django/contrib/flatpages/views.py
  36. +1 −0 django/contrib/formtools/preview.py
  37. +3 −0 django/contrib/formtools/tests/forms.py
  38. +2 −0 django/contrib/formtools/tests/tests.py
View
@@ -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.
@@ -12,6 +12,7 @@
import pstats
import sys
+
def gather_stats(p):
profiles = {}
for f in os.listdir(p):
@@ -3,6 +3,7 @@
import os
import sys
+
def unique_messages():
basedir = None
@@ -13,6 +13,7 @@
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.
@@ -2,6 +2,7 @@
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
@@ -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.
@@ -11,6 +11,7 @@
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.
@@ -6,6 +6,7 @@
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
@@ -16,6 +16,7 @@
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'
@@ -19,13 +19,15 @@
ACTION_CHECKBOX_NAME = '_selected_action'
+
class ActionForm(forms.Form):
action = forms.ChoiceField(label=_('Action:'))
select_across = forms.BooleanField(label='', required=False, initial=0,
widget=forms.HiddenInput({'class': 'select-across'}))
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 @@ def _media(self):
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 @@ def __iter__(self):
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 @@ def __iter__(self):
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 @@ def label_tag(self):
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 @@ def contents(self):
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 @@ def _media(self):
return media
media = property(_media)
+
class InlineAdminForm(AdminForm):
"""
A wrapper around an inline form for use in the admin system.
@@ -300,6 +308,7 @@ def ordering_field(self):
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 @@ def __iter__(self):
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 @@ def __init__(self, form, inline_formsets):
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
@@ -25,6 +25,7 @@
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('<img src="{0}" alt="{1}" />', icon_url, field_val)
+
def items_for_result(cl, result, form):
"""
Generates the actual list of data.
@@ -266,6 +271,7 @@ def link_in_col(is_first, field_name, cl):
if form and not form[cl.model._meta.pk.name].is_hidden:
yield format_html('<td>{0}</td>', 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 @@ def __init__(self, form, *items):
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):
"""
@@ -2,6 +2,7 @@
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"""
@@ -3,6 +3,7 @@
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 @@ def render(self, context):
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):
"""
@@ -18,6 +18,7 @@
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
@@ -410,21 +410,25 @@ 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)
except models.FieldDoesNotExist:
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)
Oops, something went wrong. Retry.

0 comments on commit 726ded5

Please sign in to comment.