Django

Code

Show
Ignore:
Timestamp:
07/15/08 16:43:21 (6 months ago)
Author:
brosner
Message:

newforms-admin: Fixed #5374 -- Added validation for ModelAdmin? and InlineModelAdmin? options including tests. Thanks mrts for initial legwork.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin/django/core/management/validation.py

    r7479 r7929  
    144144                        e.add(opts, "Reverse query name for m2m field '%s' clashes with related field '%s.%s'. Add a related_name argument to the definition for '%s'." % (f.name, rel_opts.object_name, r.get_accessor_name(), f.name)) 
    145145 
    146         # Check admin attribute. 
    147         if opts.admin is not None: 
    148             # prepopulated_fields 
    149             if not isinstance(opts.admin.prepopulated_fields, dict): 
    150                 e.add(opts, '"%s": prepopulated_fields should be a dictionary.' % f.name) 
    151             else: 
    152                 for field_name, field_list in opts.admin.prepopulated_fields.items(): 
    153                     if not isinstance(field_list, (list, tuple)): 
    154                         e.add(opts, '"%s": prepopulated_fields "%s" value should be a list or tuple.' % (f.name, field_name)) 
    155  
    156             # list_display 
    157             if not isinstance(opts.admin.list_display, (list, tuple)): 
    158                 e.add(opts, '"admin.list_display", if given, must be set to a list or tuple.') 
    159             else: 
    160                 for fn in opts.admin.list_display: 
    161                     try: 
    162                         f = opts.get_field(fn) 
    163                     except models.FieldDoesNotExist: 
    164                         if not hasattr(cls, fn): 
    165                             e.add(opts, '"admin.list_display" refers to %r, which isn\'t an attribute, method or property.' % fn) 
    166                     else: 
    167                         if isinstance(f, models.ManyToManyField): 
    168                             e.add(opts, '"admin.list_display" doesn\'t support ManyToManyFields (%r).' % fn) 
    169             # list_display_links 
    170             if opts.admin.list_display_links and not opts.admin.list_display: 
    171                 e.add(opts, '"admin.list_display" must be defined for "admin.list_display_links" to be used.') 
    172             if not isinstance(opts.admin.list_display_links, (list, tuple)): 
    173                 e.add(opts, '"admin.list_display_links", if given, must be set to a list or tuple.') 
    174             else: 
    175                 for fn in opts.admin.list_display_links: 
    176                     try: 
    177                         f = opts.get_field(fn) 
    178                     except models.FieldDoesNotExist: 
    179                         if not hasattr(cls, fn): 
    180                             e.add(opts, '"admin.list_display_links" refers to %r, which isn\'t an attribute, method or property.' % fn) 
    181                     if fn not in opts.admin.list_display: 
    182                         e.add(opts, '"admin.list_display_links" refers to %r, which is not defined in "admin.list_display".' % fn) 
    183             # list_filter 
    184             if not isinstance(opts.admin.list_filter, (list, tuple)): 
    185                 e.add(opts, '"admin.list_filter", if given, must be set to a list or tuple.') 
    186             else: 
    187                 for fn in opts.admin.list_filter: 
    188                     try: 
    189                         f = opts.get_field(fn) 
    190                     except models.FieldDoesNotExist: 
    191                         e.add(opts, '"admin.list_filter" refers to %r, which isn\'t a field.' % fn) 
    192             # date_hierarchy 
    193             if opts.admin.date_hierarchy: 
    194                 try: 
    195                     f = opts.get_field(opts.admin.date_hierarchy) 
    196                 except models.FieldDoesNotExist: 
    197                     e.add(opts, '"admin.date_hierarchy" refers to %r, which isn\'t a field.' % opts.admin.date_hierarchy) 
    198  
    199146        # Check ordering attribute. 
    200147        if opts.ordering: 
     
    214161                    e.add(opts, '"ordering" refers to "%s", a field that doesn\'t exist.' % field_name) 
    215162 
    216         # Check core=True, if needed. 
    217         for related in opts.get_followed_related_objects(): 
    218             if not related.edit_inline: 
    219                 continue 
    220             try: 
    221                 for f in related.opts.fields: 
    222                     if f.core: 
    223                         raise StopIteration 
    224                 e.add(related.opts, "At least one field in %s should have core=True, because it's being edited inline by %s.%s." % (related.opts.object_name, opts.module_name, opts.object_name)) 
    225             except StopIteration: 
    226                 pass 
    227  
    228163        # Check unique_together. 
    229164        for ut in opts.unique_together: