Changeset 4942
- Timestamp:
- 04/06/07 21:28:17 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/newforms-admin/django/contrib/admin/sites.py
r4643 r4942 54 54 class AdminSite(object): 55 55 def __init__(self): 56 self._registry = {} # model_class -> admin_class56 self._registry = {} # model_class class -> admin_class instance 57 57 58 58 def register(self, model_or_iterable, admin_class=None, **options): 59 59 """ 60 60 Registers the given model(s) with the given admin class. 61 62 The model(s) should be Model classes, not instances. 61 63 62 64 If an admin class isn't given, it will use ModelAdmin (the default … … 73 75 if model in self._registry: 74 76 raise AlreadyRegistered('The model %s is already registered' % model.__class__.__name__) 75 self._registry[model] = admin_class 77 self._registry[model] = admin_class(model) 76 78 77 79 def unregister(self, model_or_iterable): … … 101 103 `url` is the remainder of the URL -- e.g. 'comments/comment/'. 102 104 """ 105 url = url.rstrip('/') # Trim trailing slash, if it exists. 106 107 # The 'logout' view doesn't require that the person is logged in. 108 if url == 'logout': 109 return self.logout(request) 110 103 111 if not self.has_permission(request): 104 112 return self.login(request) 105 url = url.rstrip('/') # Trim trailing slash, if it exists. 113 106 114 if url == '': 107 115 return self.index(request) … … 110 118 elif url == 'password_change/done': 111 119 return self.password_change_done(request) 112 raise NotImplementedError('Only the admin index page is implemented.') 120 elif url == 'jsi18n': 121 return self.i18n_javascript(request) 122 elif '/' in url: 123 return self.model_page(request, *url.split('/', 2)) 124 125 raise http.Http404('The requested admin page does not exist.') 126 127 def model_page(self, request, app_label, model_name, rest_of_url=None): 128 """ 129 Handles the model-specific functionality of the admin site, delegating 130 to the appropriate ModelAdmin class. 131 """ 132 from django.db import models 133 model = models.get_model(app_label, model_name) 134 if model is None: 135 raise http.Http404("App %r, model %r, not found." % (app_label, model_name)) 136 try: 137 admin_obj = self._registry[model] 138 except KeyError: 139 raise http.Http404("This model exists but has not been registered with the admin site.") 140 return admin_obj(request, rest_of_url) 113 141 114 142 def password_change(self, request): 143 """ 144 Handles the "change password" task -- both form display and validation. 145 """ 115 146 from django.contrib.auth.views import password_change 116 147 return password_change(request) 117 148 118 149 def password_change_done(self, request): 150 """ 151 Displays the "success" page after a password change. 152 """ 119 153 from django.contrib.auth.views import password_change_done 120 154 return password_change_done(request) 155 156 def i18n_javascript(self, request): 157 """ 158 Displays the i18n JavaScript that the Django admin requires. 159 160 This takes into account the USE_I18N setting. If it's set to False, the 161 generated JavaScript will be leaner and faster. 162 """ 163 from django.conf import settings 164 if settings.USE_I18N: 165 from django.views.i18n import javascript_catalog 166 else: 167 from django.views.i18n import null_javascript_catalog as javascript_catalog 168 return javascript_catalog(request, packages='django.conf') 169 170 def logout(self, request): 171 """ 172 Logs out the user for the given HttpRequest. 173 174 This should *not* assume the user is already logged in. 175 """ 176 from django.contrib.auth.views import logout 177 return logout(request) 121 178 122 179 def login(self, request): … … 174 231 175 232 def index(self, request): 233 """ 234 Displays the main admin index page, which lists all of the installed 235 apps that have been registered in this site. 236 """ 176 237 app_list = [] 177 238 user = request.user
