Ticket #6004: 00-admin-useless-code.4.diff

File 00-admin-useless-code.4.diff, 10.6 KB (added by Jeff Anderson, 16 years ago)
  • deleted file django/contrib/admin/templates/widget/default.html

    diff --git a/django/contrib/admin/templates/widget/default.html b/django/contrib/admin/templates/widget/default.html
    deleted file mode 100644
    index 0af231d..0000000
    + -  
    1 {% load admin_modify %}{% output_all bound_field.form_fields %}
  • deleted file django/contrib/admin/templates/widget/file.html

    diff --git a/django/contrib/admin/templates/widget/file.html b/django/contrib/admin/templates/widget/file.html
    deleted file mode 100644
    index e584abf..0000000
    + -  
    1 {% load admin_modify i18n %}{% if bound_field.original_value %}
    2 {% trans "Currently:" %} <a href="{{ bound_field.original_url }}" > {{ bound_field.original_value|escape }} </a><br />
    3 {% trans "Change:" %}{% output_all bound_field.form_fields %}
    4 {% else %} {% output_all bound_field.form_fields %} {% endif %}
  • deleted file django/contrib/admin/templates/widget/foreign.html

    diff --git a/django/contrib/admin/templates/widget/foreign.html b/django/contrib/admin/templates/widget/foreign.html
    deleted file mode 100644
    index 476fdb9..0000000
    + -  
    1 {% load admin_modify adminmedia %}
    2 {% output_all bound_field.form_fields %}
    3 {% if change %}
    4     {% if bound_field.field.primary_key %}
    5         {{ bound_field.original_value }}
    6     {% endif %}
    7     {% if bound_field.raw_id_admin %}
    8         {% if bound_field.existing_display %}&nbsp;<strong>{{ bound_field.existing_display|truncatewords:"14"|escape }}</strong>{% endif %}
    9     {% endif %}
    10 {% endif %}
  • django/contrib/admin/templatetags/admin_modify.py

    diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py
    index 3264e89..25d2d67 100644
    a b  
    11from django import template
    2 from django.contrib.admin.views.main import AdminBoundField
    3 from django.template import loader
    4 from django.utils.text import capfirst
    5 from django.utils.encoding import force_unicode
    6 from django.db import models
    7 from django.db.models.fields import Field
    8 from django.db.models.related import BoundRelatedObject
    9 from django.conf import settings
    10 import re
    112
    123register = template.Library()
    134
    14 word_re = re.compile('[A-Z][a-z]+')
    15 
    16 def class_name_to_underscored(name):
    17     return u'_'.join([s.lower() for s in word_re.findall(name)[:-1]])
    18 
    195def submit_row(context):
    206    opts = context['opts']
    217    change = context['change']
    def submit_row(context):  
    3319        'show_save': True
    3420    }
    3521submit_row = register.inclusion_tag('admin/submit_line.html', takes_context=True)(submit_row)
    36 
    37 class FieldWidgetNode(template.Node):
    38     nodelists = {}
    39     default = None
    40 
    41     def __init__(self, bound_field_var):
    42         self.bound_field_var = template.Variable(bound_field_var)
    43 
    44     def get_nodelist(cls, klass):
    45         if klass not in cls.nodelists:
    46             try:
    47                 field_class_name = klass.__name__
    48                 template_name = u"widget/%s.html" % class_name_to_underscored(field_class_name)
    49                 nodelist = loader.get_template(template_name).nodelist
    50             except template.TemplateDoesNotExist:
    51                 super_klass = bool(klass.__bases__) and klass.__bases__[0] or None
    52                 if super_klass and super_klass != Field:
    53                     nodelist = cls.get_nodelist(super_klass)
    54                 else:
    55                     if not cls.default:
    56                         cls.default = loader.get_template("widget/default.html").nodelist
    57                     nodelist = cls.default
    58 
    59             cls.nodelists[klass] = nodelist
    60             return nodelist
    61         else:
    62             return cls.nodelists[klass]
    63     get_nodelist = classmethod(get_nodelist)
    64 
    65     def render(self, context):
    66         bound_field = self.bound_field_var.resolve(context)
    67 
    68         context.push()
    69         context['bound_field'] = bound_field
    70 
    71         output = self.get_nodelist(bound_field.field.__class__).render(context)
    72         context.pop()
    73         return output
    74 
    75 class FieldWrapper(object):
    76     def __init__(self, field ):
    77         self.field = field
    78 
    79     def needs_header(self):
    80         return not isinstance(self.field, models.AutoField)
    81 
    82     def header_class_attribute(self):
    83         return self.field.blank and mark_safe(' class="optional"') or ''
    84 
    85     def use_raw_id_admin(self):
    86         return isinstance(self.field.rel, (models.ManyToOneRel, models.ManyToManyRel)) \
    87             and self.field.rel.raw_id_admin
    88 
    89 class FormFieldCollectionWrapper(object):
    90     def __init__(self, field_mapping, fields, index):
    91         self.field_mapping = field_mapping
    92         self.fields = fields
    93         self.bound_fields = [AdminBoundField(field, self.field_mapping, field_mapping['original'])
    94                              for field in self.fields]
    95         self.index = index
    96 
    97 def output_all(form_fields):
    98     return u''.join([force_unicode(f) for f in form_fields])
    99 output_all = register.simple_tag(output_all)
    100 
    101 def field_widget(parser, token):
    102     bits = token.contents.split()
    103     if len(bits) != 2:
    104         raise template.TemplateSyntaxError, "%s takes 1 argument" % bits[0]
    105     return FieldWidgetNode(bits[1])
    106 field_widget = register.tag(field_widget)
  • deleted file django/contrib/admin/urls.py

    diff --git a/django/contrib/admin/urls.py b/django/contrib/admin/urls.py
    deleted file mode 100644
    index db0285f..0000000
    + -  
    1 from django.conf.urls.defaults import *
    2 
    3 # This file is NO LONGER USED in newforms-admin. See AdminSite.root() and
    4 # django.contrib.auth.admin instead.
    5 
    6 urlpatterns = patterns('',
    7     #('^$', 'django.contrib.admin.views.main.index'),
    8     ('^r/', include('django.conf.urls.shortcut')),
    9     #('^jsi18n/$', i18n_view, {'packages': 'django.conf'}),
    10     #('^logout/$', 'django.contrib.auth.views.logout'),
    11     #('^password_change/$', 'django.contrib.auth.views.password_change'),
    12     #('^password_change/done/$', 'django.contrib.auth.views.password_change_done'),
    13     ('^template_validator/$', 'django.contrib.admin.views.template.template_validator'),
    14 
    15     # "Add user" -- a special-case view
    16     ('^auth/user/add/$', 'django.contrib.admin.views.auth.user_add_stage'),
    17     # "Change user password" -- another special-case view
    18     ('^auth/user/(\d+)/password/$', 'django.contrib.admin.views.auth.user_change_password'),
    19 
    20     # Model-specific admin pages.
    21     ('^([^/]+)/([^/]+)/(?:(.+)/)?$', 'django.contrib.admin.views.main.model_admin_view'),
    22 )
  • django/contrib/admin/views/main.py

    diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
    index 254f202..d24a862 100644
    a b  
    1 from django import template
    21from django.contrib.admin.filterspecs import FilterSpec
    32from django.contrib.admin.options import IncorrectLookupParameters
    4 from django.contrib.admin.views.decorators import staff_member_required
    5 from django.views.decorators.cache import never_cache
    63from django.core.paginator import QuerySetPaginator, InvalidPage
    7 from django.shortcuts import render_to_response
    84from django.db import models
    95from django.db.models.query import QuerySet
    10 from django.http import Http404
    116from django.utils.encoding import force_unicode, smart_str
    127from django.utils.translation import ugettext
    138from django.utils.safestring import mark_safe
    ERROR_FLAG = 'e'  
    3429# Text to display within change-list table cells if the value is blank.
    3530EMPTY_CHANGELIST_VALUE = '(None)'
    3631
    37 use_raw_id_admin = lambda field: isinstance(field.rel, (models.ManyToOneRel, models.ManyToManyRel)) and field.rel.raw_id_admin
    38 
    3932def quote(s):
    4033    """
    4134    Ensure that primary key values do not confuse the admin URLs by escaping
    def quote(s):  
    5245            res[i] = '_%02X' % ord(c)
    5346    return ''.join(res)
    5447
    55 def model_admin_view(request, app_label, model_name, rest_of_url):
    56     model = models.get_model(app_label, model_name)
    57     if model is None:
    58         raise Http404("App %r, model %r, not found" % (app_label, model_name))
    59     if not model._meta.admin:
    60         raise Http404("This object has no admin interface.")
    61     mav = model._meta.admin(model)
    62     return mav(request, rest_of_url)
    63 model_admin_view = staff_member_required(never_cache(model_admin_view))
    64 
    65 class AdminBoundField(object):
    66     def __init__(self, field, field_mapping, original):
    67         self.field = field
    68         self.original = original
    69         self.form_fields = [field_mapping[name] for name in self.field.get_manipulator_field_names('')]
    70         self.has_label_first = not isinstance(self.field, models.BooleanField)
    71         self.raw_id_admin = use_raw_id_admin(field)
    72         self.is_date_time = isinstance(field, models.DateTimeField)
    73         self.is_file_field = isinstance(field, models.FileField)
    74         self.hidden = isinstance(self.field, models.AutoField)
    75         self.first = False
    76 
    77         classes = []
    78         if self.raw_id_admin:
    79             classes.append(u'nowrap')
    80         if max([bool(f.errors()) for f in self.form_fields]):
    81             classes.append(u'error')
    82         if classes:
    83             self.cell_class_attribute = u' class="%s" ' % ' '.join(classes)
    84         self._repr_filled = False
    85 
    86     def original_value(self):
    87         if self.original:
    88             return self.original.__dict__[self.field.attname]
    89 
    90     def existing_display(self):
    91         try:
    92             return self._display
    93         except AttributeError:
    94             if isinstance(self.field.rel, models.ManyToOneRel):
    95                 self._display = force_unicode(getattr(self.original, self.field.name), strings_only=True)
    96             elif isinstance(self.field.rel, models.ManyToManyRel):
    97                 self._display = u", ".join([force_unicode(obj) for obj in getattr(self.original, self.field.name).all()])
    98             return self._display
    99 
    100     def __repr__(self):
    101         return repr(self.__dict__)
    102 
    103     def html_error_list(self):
    104         return mark_safe(" ".join([form_field.html_error_list() for form_field in self.form_fields if form_field.errors]))
    105 
    106     def original_url(self):
    107         if self.is_file_field and self.original and self.field.attname:
    108             url_method = getattr(self.original, 'get_%s_url' % self.field.attname)
    109             if callable(url_method):
    110                 return url_method()
    111         return ''
    112 
    113 def index(request):
    114     return render_to_response('admin/index.html', {'title': ugettext('Site administration')}, context_instance=template.RequestContext(request))
    115 index = staff_member_required(never_cache(index))
    116 
    117 
    11848class ChangeList(object):
    11949    def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, model_admin):
    12050        self.model = model
Back to Top