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

File 00-admin-useless-code.3.diff, 10.5 KB (added by Petr Marhoun <petr.marhoun@…>, 17 years ago)

new version - after autoescape merge

  • django/contrib/admin/templates/widget/default.html

    === removed directory 'django/contrib/admin/templates/widget'
    === removed file 'django/contrib/admin/templates/widget/default.html'
     
    1 {% load admin_modify %}{% output_all bound_field.form_fields %}
  • django/contrib/admin/templates/widget/file.html

    === removed file 'django/contrib/admin/templates/widget/file.html'
     
    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 %}
  • django/contrib/admin/templates/widget/foreign.html

    === removed file 'django/contrib/admin/templates/widget/foreign.html'
     
    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/urls.py

    === removed file 'django/contrib/admin/urls.py'
     
    1 from django.conf.urls.defaults import *
    2 
    3 urlpatterns = patterns('',
    4     #('^$', 'django.contrib.admin.views.main.index'),
    5     ('^r/(\d+)/(.*)/$', 'django.views.defaults.shortcut'),
    6     #('^jsi18n/$', i18n_view, {'packages': 'django.conf'}),
    7     #('^logout/$', 'django.contrib.auth.views.logout'),
    8     #('^password_change/$', 'django.contrib.auth.views.password_change'),
    9     #('^password_change/done/$', 'django.contrib.auth.views.password_change_done'),
    10     ('^template_validator/$', 'django.contrib.admin.views.template.template_validator'),
    11 
    12     # "Add user" -- a special-case view
    13     ('^auth/user/add/$', 'django.contrib.admin.views.auth.user_add_stage'),
    14     # "Change user password" -- another special-case view
    15     ('^auth/user/(\d+)/password/$', 'django.contrib.admin.views.auth.user_change_password'),
    16 
    17     # Model-specific admin pages.
    18     ('^([^/]+)/([^/]+)/(?:(.+)/)?$', 'django.contrib.admin.views.main.model_admin_view'),
    19 )
  • django/contrib/admin/templatetags/admin_modify.py

    === modified file 'django/contrib/admin/templatetags/admin_modify.py'
     
    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']
     
    3420        'show_save': True
    3521    }
    3622submit_row = register.inclusion_tag('admin/submit_line.html', takes_context=True)(submit_row)
    37 
    38 class FieldWidgetNode(template.Node):
    39     nodelists = {}
    40     default = None
    41 
    42     def __init__(self, bound_field_var):
    43         self.bound_field_var = template.Variable(bound_field_var)
    44 
    45     def get_nodelist(cls, klass):
    46         if klass not in cls.nodelists:
    47             try:
    48                 field_class_name = klass.__name__
    49                 template_name = u"widget/%s.html" % class_name_to_underscored(field_class_name)
    50                 nodelist = loader.get_template(template_name).nodelist
    51             except template.TemplateDoesNotExist:
    52                 super_klass = bool(klass.__bases__) and klass.__bases__[0] or None
    53                 if super_klass and super_klass != Field:
    54                     nodelist = cls.get_nodelist(super_klass)
    55                 else:
    56                     if not cls.default:
    57                         cls.default = loader.get_template("widget/default.html").nodelist
    58                     nodelist = cls.default
    59 
    60             cls.nodelists[klass] = nodelist
    61             return nodelist
    62         else:
    63             return cls.nodelists[klass]
    64     get_nodelist = classmethod(get_nodelist)
    65 
    66     def render(self, context):
    67         bound_field = self.bound_field_var.resolve(context)
    68 
    69         context.push()
    70         context['bound_field'] = bound_field
    71 
    72         output = self.get_nodelist(bound_field.field.__class__).render(context)
    73         context.pop()
    74         return output
    75 
    76 class FieldWrapper(object):
    77     def __init__(self, field ):
    78         self.field = field
    79 
    80     def needs_header(self):
    81         return not isinstance(self.field, models.AutoField)
    82 
    83     def header_class_attribute(self):
    84         return self.field.blank and mark_safe(' class="optional"') or ''
    85 
    86     def use_raw_id_admin(self):
    87         return isinstance(self.field.rel, (models.ManyToOneRel, models.ManyToManyRel)) \
    88             and self.field.rel.raw_id_admin
    89 
    90 class FormFieldCollectionWrapper(object):
    91     def __init__(self, field_mapping, fields, index):
    92         self.field_mapping = field_mapping
    93         self.fields = fields
    94         self.bound_fields = [AdminBoundField(field, self.field_mapping, field_mapping['original'])
    95                              for field in self.fields]
    96         self.index = index
    97 
    98 def output_all(form_fields):
    99     return u''.join([force_unicode(f) for f in form_fields])
    100 output_all = register.simple_tag(output_all)
    101 
    102 def field_widget(parser, token):
    103     bits = token.contents.split()
    104     if len(bits) != 2:
    105         raise template.TemplateSyntaxError, "%s takes 1 argument" % bits[0]
    106     return FieldWidgetNode(bits[1])
    107 field_widget = register.tag(field_widget)
  • django/contrib/admin/views/main.py

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