Ticket #6004: 00-admin-useless-code.diff
File 00-admin-useless-code.diff, 10.5 KB (added by , 17 years ago) |
---|
-
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 %} <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 view13 ('^auth/user/add/$', 'django.contrib.admin.views.auth.user_add_stage'),14 # "Change user password" -- another special-case view15 ('^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'
1 1 from django import template 2 from django.contrib.admin.views.main import AdminBoundField3 from django.template import loader4 from django.utils.text import capfirst5 from django.utils.encoding import force_unicode6 from django.db import models7 from django.db.models.fields import Field8 from django.db.models.related import BoundRelatedObject9 from django.conf import settings10 import re11 2 12 3 register = template.Library() 13 4 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 19 5 def submit_row(context): 20 6 opts = context['opts'] 21 7 change = context['change'] … … 34 20 'show_save': True 35 21 } 36 22 submit_row = register.inclusion_tag('admin/submit_line.html', takes_context=True)(submit_row) 37 38 class FieldWidgetNode(template.Node):39 nodelists = {}40 default = None41 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).nodelist51 except template.TemplateDoesNotExist:52 super_klass = bool(klass.__bases__) and klass.__bases__[0] or None53 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").nodelist58 nodelist = cls.default59 60 cls.nodelists[klass] = nodelist61 return nodelist62 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_field71 72 output = self.get_nodelist(bound_field.field.__class__).render(context)73 context.pop()74 return output75 76 class FieldWrapper(object):77 def __init__(self, field ):78 self.field = field79 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 ' 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_admin89 90 class FormFieldCollectionWrapper(object):91 def __init__(self, field_mapping, fields, index):92 self.field_mapping = field_mapping93 self.fields = fields94 self.bound_fields = [AdminBoundField(field, self.field_mapping, field_mapping['original'])95 for field in self.fields]96 self.index = index97 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'
(this hunk was shorter than expected) 1 from django import template2 1 from django.contrib.admin.filterspecs import FilterSpec 3 2 from django.contrib.admin.options import IncorrectLookupParameters-from django.contrib.admin.views.decorators import staff_member_required 4 from django.views.decorators.cache import never_cache5 3 from django.core.paginator import ObjectPaginator, InvalidPage 6 from django.shortcuts import render_to_response7 4 from django.db import models 8 5 from django.db.models.query import handle_legacy_orderlist, QuerySet 9 from django.http import Http40410 6 from django.utils.encoding import force_unicode, smart_str 11 7 from django.utils.translation import ugettext 12 8 import operator … … 33 28 # Text to display within change-list table cells if the value is blank. 34 29 EMPTY_CHANGELIST_VALUE = '(None)' 35 30 36 use_raw_id_admin = lambda field: isinstance(field.rel, (models.ManyToOneRel, models.ManyToManyRel)) and field.rel.raw_id_admin37 38 31 def quote(s): 39 32 """ 40 33 Ensure that primary key values do not confuse the admin URLs by escaping … … 51 44 res[i] = '_%02X' % ord(c) 52 45 return ''.join(res) 53 46 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 = field67 self.original = original68 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 = False75 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 = False84 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._display92 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._display98 99 def __repr__(self):100 return repr(self.__dict__)101 102 def html_error_list(self):103 return " ".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 117 47 class ChangeList(object): 118 48 def __init__(self, request, model, list_display, list_display_links, list_filter, date_hierarchy, search_fields, list_select_related, list_per_page, model_admin): 119 49 self.model = model