magic-removal: Cleaned up various messiness in admin code
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2042 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7592ca69af
commit
795e6cbcf2
|
@ -1,44 +1,28 @@
|
|||
# Generic admin views.
|
||||
from django import template
|
||||
from django.conf import settings
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from django import template
|
||||
from django.template import loader
|
||||
from django.db import models
|
||||
from django.http import Http404
|
||||
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
|
||||
from django.template import RequestContext as Context
|
||||
from django.core.extensions import get_object_or_404, render_to_response
|
||||
from django.db import models
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||
from django.template import loader, RequestContext
|
||||
from django.utils import dateformat
|
||||
from django.utils.html import escape
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.utils.text import capfirst, get_text_list
|
||||
import operator
|
||||
from itertools import izip
|
||||
|
||||
ADMIN_PREFIX = "/admin/"
|
||||
|
||||
#def _get_mod_opts(app_label, module_name):
|
||||
# "Helper function that returns a tuple of (module, opts), raising Http404 if necessary."
|
||||
# try:
|
||||
# mod = models.get_app(app_label)
|
||||
# except ImportError:
|
||||
# raise Http404 # Invalid app or module name. Maybe it's not in INSTALLED_APPS.
|
||||
# opts = mod.Klass._meta
|
||||
# if not opts.admin:
|
||||
# raise Http404 # This object is valid but has no admin interface.
|
||||
# return mod, opts
|
||||
|
||||
def matches_app(mod, comps):
|
||||
modcomps = mod.__name__.split('.')[:-1] #HACK: leave off 'models'
|
||||
for c, mc in izip(comps, modcomps):
|
||||
if c != mc:
|
||||
return ([], False)
|
||||
return (comps[len(modcomps):], True)
|
||||
return [], False
|
||||
return comps[len(modcomps):], True
|
||||
|
||||
def find_model(mod, remaining):
|
||||
# print "finding ", mod, remaining
|
||||
if len(remaining) == 0:
|
||||
# print "no comps left"
|
||||
raise Http404
|
||||
if len(remaining) == 1:
|
||||
if hasattr(mod, '_MODELS'):
|
||||
|
@ -51,7 +35,6 @@ def find_model(mod, remaining):
|
|||
raise Http404
|
||||
else:
|
||||
child = getattr(mod, remaining[0], None)
|
||||
# print mod, remaining[0], child
|
||||
if child:
|
||||
return find_model(child, remaining[1:])
|
||||
else:
|
||||
|
@ -67,10 +50,7 @@ def get_model_and_app(path):
|
|||
for mod in models.get_installed_models():
|
||||
remaining, matched = matches_app(mod, comps)
|
||||
if matched and len(remaining) > 0:
|
||||
# print "matched ", mod
|
||||
# print "left", remaining
|
||||
return (find_model(mod, remaining), get_app_label(mod))
|
||||
|
||||
raise Http404 # Couldn't find app
|
||||
|
||||
_model_urls = {}
|
||||
|
@ -90,7 +70,7 @@ def url_for_model(model):
|
|||
raise ImproperlyConfigured, '%s is not a model in an installed app' % model.__name__
|
||||
|
||||
def index(request):
|
||||
return render_to_response('admin/index', {'title': _('Site administration')}, context_instance=Context(request))
|
||||
return render_to_response('admin/index', {'title': _('Site administration')}, context_instance=RequestContext(request))
|
||||
index = staff_member_required(index)
|
||||
|
||||
def history(request, app_label, module_name, object_id):
|
||||
|
@ -104,5 +84,5 @@ def history(request, app_label, module_name, object_id):
|
|||
'action_list': action_list,
|
||||
'module_name': capfirst(opts.verbose_name_plural),
|
||||
'object': obj,
|
||||
}, context_instance=Context(request))
|
||||
}, context_instance=RequestContext(request))
|
||||
history = staff_member_required(history)
|
||||
|
|
|
@ -4,11 +4,10 @@ from django.contrib.admin.views.main import get_model_and_app
|
|||
from django.contrib.admin.views.stages.modify import render_change_form
|
||||
from django import forms
|
||||
from django import template
|
||||
from django.http import Http404
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
|
||||
from django.template import RequestContext as Context
|
||||
from django.db import models
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.utils.text import capfirst, get_text_list
|
||||
try:
|
||||
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
from django.contrib.admin.views.main import get_model_and_app
|
||||
from django import forms
|
||||
from django import template
|
||||
from django.http import Http404
|
||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist, PermissionDenied
|
||||
from django.template import RequestContext as Context
|
||||
from django.contrib.admin.views.stages.modify import render_change_form
|
||||
from django.db import models
|
||||
from django.utils.text import capfirst, get_text_list
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
try:
|
||||
from django.contrib.admin.models import LogEntry, ADDITION, CHANGE, DELETION
|
||||
|
@ -32,7 +31,6 @@ def log_change_message(user, opts, manipulator, new_object):
|
|||
def change_stage(request, path, object_id):
|
||||
model, app_label = get_model_and_app(path)
|
||||
opts = model._meta
|
||||
#mod, opts = _get_mod_opts(app_label, module_name)
|
||||
if not request.user.has_perm(app_label + '.' + opts.get_change_permission()):
|
||||
raise PermissionDenied
|
||||
if request.POST and request.POST.has_key("_saveasnew"):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
from django.contrib.admin.views.main import get_model_and_app
|
||||
from django.core.extensions import get_object_or_404,render_to_response
|
||||
from django.core.extensions import get_object_or_404, render_to_response
|
||||
from django.template import RequestContext as Context
|
||||
from django.utils.text import capfirst
|
||||
from django.utils.html import escape
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from django.db.models.fields import BoundField, BoundFieldLine, BoundFieldSet
|
||||
from django.db import models
|
||||
|
||||
from django.core.extensions import render_to_response
|
||||
from django.contrib.admin.views.main import url_for_model
|
||||
|
||||
|
@ -108,7 +107,7 @@ class BoundManipulator(object):
|
|||
self.model = model
|
||||
self.opts = model._meta
|
||||
self.inline_related_objects = self.opts.get_followed_related_objects(manipulator.follow)
|
||||
self.original = hasattr(manipulator, 'original_object') and manipulator.original_object or None
|
||||
self.original = getattr(manipulator, 'original_object', None)
|
||||
self.bound_field_sets = [field_set.bind(field_mapping, self.original, AdminBoundFieldSet)
|
||||
for field_set in self.opts.admin.get_field_sets(self.opts)]
|
||||
self.ordered_objects = self.opts.get_ordered_objects()[:]
|
||||
|
@ -123,8 +122,7 @@ class AdminBoundManipulator(BoundManipulator):
|
|||
|
||||
self.coltype = self.ordered_objects and 'colMS' or 'colM'
|
||||
self.has_absolute_url = hasattr(model, 'get_absolute_url')
|
||||
self.form_enc_attrib = self.opts.has_field_type(models.FileField) and \
|
||||
'enctype="multipart/form-data" ' or ''
|
||||
self.form_enc_attrib = self.opts.has_field_type(models.FileField) and 'enctype="multipart/form-data" ' or ''
|
||||
|
||||
self.first_form_field_id = self.bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id();
|
||||
self.ordered_object_pk_names = [o.pk.name for o in self.ordered_objects]
|
||||
|
|
|
@ -294,7 +294,7 @@ class Field(object):
|
|||
for x in rel_model._default_manager.get_list(**rel_model._meta.limit_choices_to)]
|
||||
|
||||
def get_choices_default(self):
|
||||
if(self.radio_admin):
|
||||
if self.radio_admin:
|
||||
return self.get_choices(include_blank=self.blank, blank_choice=BLANK_CHOICE_NONE)
|
||||
else:
|
||||
return self.get_choices()
|
||||
|
|
Loading…
Reference in New Issue