mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	newforms-admin: Changed list_filter implementation to use ModelAdmin instead of AdminOptions. Also removed list_filter and list_display from AdminOptions entirely.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4330 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -34,6 +34,7 @@ class ModelAdmin(object): | ||||
|     "Encapsulates all admin options and functionality for a given model." | ||||
|  | ||||
|     list_display = ('__str__',) | ||||
|     list_filter = () | ||||
|  | ||||
|     def __init__(self, model): | ||||
|         self.model = model | ||||
| @@ -269,7 +270,7 @@ class ModelAdmin(object): | ||||
|         if not self.has_change_permission(request, None): | ||||
|             raise PermissionDenied | ||||
|         try: | ||||
|             cl = ChangeList(request, self.model, self.list_display) | ||||
|             cl = ChangeList(request, self.model, self.list_display, self.list_filter) | ||||
|         except IncorrectLookupParameters: | ||||
|             # Wacky lookup parameters were given, so redirect to the main | ||||
|             # changelist page, without parameters, and pass an 'invalid=1' | ||||
|   | ||||
| @@ -292,12 +292,13 @@ def _get_deleted_objects(deleted_objects, perms_needed, user, obj, opts, current | ||||
|                 perms_needed.add(related.opts.verbose_name) | ||||
|  | ||||
| class ChangeList(object): | ||||
|     def __init__(self, request, model, list_display): | ||||
|     def __init__(self, request, model, list_display, list_filter): | ||||
|         self.model = model | ||||
|         self.opts = model._meta | ||||
|         self.lookup_opts = self.opts | ||||
|         self.manager = self.opts.admin.manager | ||||
|         self.list_display = list_display | ||||
|         self.list_filter = list_filter | ||||
|  | ||||
|         # Get search parameters from the query string. | ||||
|         try: | ||||
| @@ -322,9 +323,8 @@ class ChangeList(object): | ||||
|  | ||||
|     def get_filters(self, request): | ||||
|         filter_specs = [] | ||||
|         if self.lookup_opts.admin.list_filter and not self.opts.one_to_one_field: | ||||
|             filter_fields = [self.lookup_opts.get_field(field_name) \ | ||||
|                               for field_name in self.lookup_opts.admin.list_filter] | ||||
|         if self.list_filter and not self.opts.one_to_one_field: | ||||
|             filter_fields = [self.lookup_opts.get_field(field_name) for field_name in self.list_filter] | ||||
|             for f in filter_fields: | ||||
|                 spec = FilterSpec.create(f, request, self.params, self.model) | ||||
|                 if spec and spec.has_output(): | ||||
|   | ||||
| @@ -983,10 +983,10 @@ def get_validation_errors(outfile, app=None): | ||||
|                 e.add(opts, '"admin" attribute, if given, must be set to a models.AdminOptions() instance.') | ||||
|             else: | ||||
|                 # list_display | ||||
|                 if not isinstance(opts.admin.list_display, (list, tuple)): | ||||
|                 if not isinstance(opts.ModelAdmin.list_display, (list, tuple)): | ||||
|                     e.add(opts, '"admin.list_display", if given, must be set to a list or tuple.') | ||||
|                 else: | ||||
|                     for fn in opts.admin.list_display: | ||||
|                     for fn in opts.ModelAdmin.list_display: | ||||
|                         try: | ||||
|                             f = opts.get_field(fn) | ||||
|                         except models.FieldDoesNotExist: | ||||
| @@ -1010,10 +1010,10 @@ def get_validation_errors(outfile, app=None): | ||||
|                         if fn not in opts.admin.list_display: | ||||
|                             e.add(opts, '"admin.list_display_links" refers to %r, which is not defined in "admin.list_display".' % fn) | ||||
|                 # list_filter | ||||
|                 if not isinstance(opts.admin.list_filter, (list, tuple)): | ||||
|                 if not isinstance(opts.ModelAdmin.list_filter, (list, tuple)): | ||||
|                     e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.') | ||||
|                 else: | ||||
|                     for fn in opts.admin.list_filter: | ||||
|                     for fn in opts.ModelAdmin.list_filter: | ||||
|                         try: | ||||
|                             f = opts.get_field(fn) | ||||
|                         except models.FieldDoesNotExist: | ||||
|   | ||||
| @@ -137,7 +137,7 @@ class Model(object): | ||||
|             # of ModelAdmin. | ||||
|             cls._meta.ModelAdmin = type('ModelAdmin', (value, ModelAdmin), {}) | ||||
|             # This AdminOptions stuff is legacy and will eventually be removed. | ||||
|             value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_')])) | ||||
|             value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_') and k not in ('list_display', 'list_filter')])) | ||||
|             value.contribute_to_class(cls, name) | ||||
|         elif hasattr(value, 'contribute_to_class'): | ||||
|             value.contribute_to_class(cls, name) | ||||
|   | ||||
| @@ -199,14 +199,12 @@ class Options(object): | ||||
|         return self._field_types[field_type] | ||||
|  | ||||
| class AdminOptions(object): | ||||
|     def __init__(self, fields=None, js=None, list_display=None, list_display_links=None, list_filter=None, | ||||
|     def __init__(self, fields=None, js=None, list_display_links=None, | ||||
|         date_hierarchy=None, save_as=False, ordering=None, search_fields=None, | ||||
|         save_on_top=False, list_select_related=False, manager=None, list_per_page=100): | ||||
|         self.fields = fields | ||||
|         self.js = js or [] | ||||
|         self.list_display = list_display or ['__str__'] | ||||
|         self.list_display_links = list_display_links or [] | ||||
|         self.list_filter = list_filter or [] | ||||
|         self.date_hierarchy = date_hierarchy | ||||
|         self.save_as, self.ordering = save_as, ordering | ||||
|         self.search_fields = search_fields or [] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user