Django

Code

Changeset 1430

Show
Ignore:
Timestamp:
11/24/05 22:37:46 (3 years ago)
Author:
adrian
Message:

new-admin: Negligible formatting changes to admin.templatetags.admin_list and admin.views.main -- and removed multi-line import in templatetags/admin_list, for Python 2.3 compatibility

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/new-admin/django/contrib/admin/templatetags/admin_list.py

    r1367 r1430  
     1from django.contrib.admin.views.main import MAX_SHOW_ALL_ALLOWED, DEFAULT_RESULTS_PER_PAGE, ALL_VAR 
     2from django.contrib.admin.views.main import ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR, SEARCH_VAR 
     3from django.contrib.admin.views.main import IS_POPUP_VAR, EMPTY_CHANGELIST_VALUE, MONTHS 
     4from django.core import meta, template 
     5from django.core.exceptions import ObjectDoesNotExist 
    16from django.core.template.decorators import simple_tag, inclusion_tag 
    2  
    3 from django.contrib.admin.views.main import MAX_SHOW_ALL_ALLOWED, DEFAULT_RESULTS_PER_PAGE, ALL_VAR, \ 
    4  ORDER_VAR, ORDER_TYPE_VAR, PAGE_VAR , SEARCH_VAR , IS_POPUP_VAR, EMPTY_CHANGELIST_VALUE, \ 
    5  MONTHS 
    6 from django.utils.translation import get_date_formats  
    7  
    8  
    9 from django.core import meta 
     7from django.utils import dateformat 
     8from django.utils.html import strip_tags, escape 
    109from django.utils.text import capfirst 
    11 from django.utils.html import strip_tags, escape 
    12 from django.core.exceptions import ObjectDoesNotExist 
     10from django.utils.translation import get_date_formats 
    1311from django.conf.settings import ADMIN_MEDIA_PREFIX 
    14 from django.core import template 
    15 from django.utils import dateformat 
     12 
    1613DOT = '.' 
    1714 
     
    2118       return '... ' 
    2219    elif i == cl.page_num: 
    23        return '<span class="this-page">%d</span> ' % (i+1)  
     20       return '<span class="this-page">%d</span> ' % (i+1) 
    2421    else: 
    25        return '<a href="%s"%s>%d</a> ' % (cl.get_query_string( {PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1)  
     22       return '<a href="%s"%s>%d</a> ' % (cl.get_query_string({PAGE_VAR: i}), (i == cl.paginator.pages-1 and ' class="end"' or ''), i+1) 
    2623paginator_number = simple_tag(paginator_number) 
    2724 
    2825#@inclusion_tag('admin/pagination') 
    2926def pagination(cl): 
    30     paginator, page_num = cl.paginator, cl.page_num  
    31      
     27    paginator, page_num = cl.paginator, cl.page_num 
     28 
    3229    pagination_required = (not cl.show_all or not cl.can_show_all) and cl.multi_page 
    3330    if not pagination_required: 
     
    3633        ON_EACH_SIDE = 3 
    3734        ON_ENDS = 2 
    38          
     35 
    3936        # If there are 10 or fewer pages, display links to every page. 
    4037        # Otherwise, do some fancy 
     
    6057 
    6158    need_show_all_link = cl.can_show_all and not cl.show_all and cl.multi_page 
    62  
    63     return {'cl': cl, 
    64              'pagination_required': pagination_required, 
    65              'show_all_url': need_show_all_link and cl.get_query_string({ALL_VAR:''}), 
    66              'page_range': page_range,  
    67              'ALL_VAR': ALL_VAR, 
    68              '1': 1 
    69            
     59    return { 
     60        'cl': cl, 
     61        'pagination_required': pagination_required, 
     62        'show_all_url': need_show_all_link and cl.get_query_string({ALL_VAR: ''}), 
     63        'page_range': page_range, 
     64        'ALL_VAR': ALL_VAR, 
     65        '1': 1, 
     66   
    7067pagination = inclusion_tag('admin/pagination')(pagination) 
    71  
    7268 
    7369def result_headers(cl): 
    7470    lookup_opts = cl.lookup_opts 
    75      
     71 
    7672    for i, field_name in enumerate(lookup_opts.admin.list_display): 
    77             try: 
    78                 f = lookup_opts.get_field(field_name) 
    79             except meta.FieldDoesNotExist: 
    80                 # For non-field list_display values, check for the function 
    81                 # attribute "short_description". If that doesn't exist, fall 
    82                 # back to the method name. And __repr__ is a special-case. 
    83                 if field_name == '__repr__': 
    84                     header = lookup_opts.verbose_name 
    85                 else: 
    86                     func = getattr(cl.mod.Klass, field_name) # Let AttributeErrors propogate. 
    87                     try: 
    88                         header = func.short_description 
    89                     except AttributeError: 
    90                         header = func.__name__.replace('_', ' ') 
    91                 # Non-field list_display values don't get ordering capability. 
    92                 yield {"text": header} 
    93             else: 
    94                 if isinstance(f.rel, meta.ManyToOne) and f.null: 
    95                     yield {"text": f.verbose_name} 
    96                 else: 
    97                     th_classes = [] 
    98                     new_order_type = 'asc' 
    99                     if field_name == cl.order_field: 
    100                         th_classes.append('sorted %sending' % cl.order_type.lower()) 
    101                         new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()] 
    102                      
    103                     yield {"text" : f.verbose_name,  
    104                            "sortable": True, 
    105                            "url" : cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}), 
    106                            "class_attrib" : (th_classes and ' class="%s"' % ' '.join(th_classes) or '')
    107      
     73        try: 
     74            f = lookup_opts.get_field(field_name) 
     75        except meta.FieldDoesNotExist: 
     76            # For non-field list_display values, check for the function 
     77            # attribute "short_description". If that doesn't exist, fall 
     78            # back to the method name. And __repr__ is a special-case. 
     79            if field_name == '__repr__': 
     80                header = lookup_opts.verbose_name 
     81            else: 
     82                func = getattr(cl.mod.Klass, field_name) # Let AttributeErrors propogate. 
     83                try: 
     84                    header = func.short_description 
     85                except AttributeError: 
     86                    header = func.__name__.replace('_', ' ') 
     87            # Non-field list_display values don't get ordering capability. 
     88            yield {"text": header} 
     89        else: 
     90            if isinstance(f.rel, meta.ManyToOne) and f.null: 
     91                yield {"text": f.verbose_name} 
     92            else: 
     93                th_classes = [] 
     94                new_order_type = 'asc' 
     95                if field_name == cl.order_field: 
     96                    th_classes.append('sorted %sending' % cl.order_type.lower()) 
     97                    new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()] 
     98 
     99                yield {"text": f.verbose_name, 
     100                       "sortable": True, 
     101                       "url": cl.get_query_string({ORDER_VAR: i, ORDER_TYPE_VAR: new_order_type}), 
     102                       "class_attrib": (th_classes and ' class="%s"' % ' '.join(th_classes) or '')
     103 
    108104def items_for_result(cl, result): 
    109105    first = True 
     
    122118                result_repr = EMPTY_CHANGELIST_VALUE 
    123119            else: 
    124                 # Strip HTML tags in the resulting text, except if the  
    125                 # function has an "allow_tags" attribute set to True.  
    126                 if not getattr(func, 'allow_tags', False):  
     120                # Strip HTML tags in the resulting text, except if the 
     121                # function has an "allow_tags" attribute set to True. 
     122                if not getattr(func, 'allow_tags', False): 
    127123                    result_repr = strip_tags(result_repr) 
    128124        else: 
    129125            field_val = getattr(result, f.attname) 
    130          
     126 
    131127            if isinstance(f.rel, meta.ManyToOne): 
    132128                if field_val is not None: 
     
    137133            elif isinstance(f, meta.DateField) or isinstance(f, meta.TimeField): 
    138134                if field_val: 
    139                     (date_format, datetime_format, time_format) = get_date_formats()  
     135                    (date_format, datetime_format, time_format) = get_date_formats() 
    140136                    if isinstance(f, meta.DateTimeField): 
    141137                        result_repr = capfirst(dateformat.format(field_val, datetime_format)) 
     
    177173        else: 
    178174            yield ('<td%s>%s</td>' % (row_class, result_repr)) 
    179          
     175 
    180176def results(cl): 
    181177    for res in cl.result_list: 
     
    185181def result_list(cl): 
    186182    res = list(results(cl)) 
    187     return {'cl': cl,  
    188             'result_headers': list(result_headers(cl)),  
    189             'results': list(results(cl)),
     183    return {'cl': cl, 
     184            'result_headers': list(result_headers(cl)), 
     185            'results': list(results(cl))
    190186result_list = inclusion_tag("admin/change_list_results")(result_list) 
    191  
    192187 
    193188#@inclusion_tag("admin/date_hierarchy") 
     
    195190    lookup_opts, params, lookup_params, lookup_mod = \ 
    196191      cl.lookup_opts, cl.params, cl.lookup_params, cl.lookup_mod 
    197      
     192 
    198193    if lookup_opts.admin.date_hierarchy: 
    199194        field_name = lookup_opts.admin.date_hierarchy 
    200      
     195 
    201196        year_field = '%s__year' % field_name 
    202197        month_field = '%s__month' % field_name 
     
    206201        month_lookup = params.get(month_field) 
    207202        day_lookup = params.get(day_field) 
    208       
    209         def link(d):  
     203 
     204        def link(d): 
    210205            return cl.get_query_string(d, [field_generic]) 
    211       
     206 
    212207        def get_dates(unit, params): 
    213208            return getattr(lookup_mod, 'get_%s_list' % field_name)(unit, **params) 
    214       
     209 
    215210        if year_lookup and month_lookup and day_lookup: 
    216211            month_name = MONTHS[int(month_lookup)] 
    217             return {  'show': True, 
    218                       'back':  
    219                         { 'link' : link({year_field: year_lookup, month_field: month_lookup}),  
    220                           'title': "%s %s" % ( month_name, year_lookup), 
    221                         }, 
    222                       'choices': [ {'title': "%s %s" % ( month_name, day_lookup)} ] 
    223                   } 
     212            return { 
     213                'show': True, 
     214                'back': { 
     215                    'link': link({year_field: year_lookup, month_field: month_lookup}), 
     216                    'title': "%s %s" % (month_name, year_lookup) 
     217                }, 
     218                'choices': [{'title': "%s %s" % (month_name, day_lookup)}] 
     219            } 
    224220        elif year_lookup and month_lookup: 
    225221            date_lookup_params = lookup_params.copy() 
    226222            date_lookup_params.update({year_field: year_lookup, month_field: month_lookup}) 
    227223            days = get_dates('day', date_lookup_params) 
    228             return { 'show': True, 
    229                      'back':  
    230                         { 'link' : link({year_field: year_lookup}),  
    231                           'title' : year_lookup  
    232                         }, 
    233                     'choices':  
    234                         [ { 'link' : link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}),  
    235                             'title': day.strftime('%B %d') } for day in days ] 
    236                     } 
     224            return { 
     225                'show': True, 
     226                'back': { 
     227                    'link': link({year_field: year_lookup}), 
     228                    'title': year_lookup 
     229                }, 
     230                'choices': [{ 
     231                    'link': link({year_field: year_lookup, month_field: month_lookup, day_field: day.day}), 
     232                    'title': day.strftime('%B %d') 
     233                } for day in days] 
     234            } 
    237235        elif year_lookup: 
    238236            date_lookup_params = lookup_params.copy() 
    239237            date_lookup_params.update({year_field: year_lookup}) 
    240238            months = get_dates('month', date_lookup_params) 
    241             return {  'show' : True, 
    242                       'back': 
    243                        { 'link' : link({}), 
    244                          'title': _('All dates') 
    245                        }, 
    246                       'choices': 
    247                       [ { 'link': link( {year_field: year_lookup, month_field: month.month}),  
    248                           'title': "%s %s" % (month.strftime('%B') ,  month.year) } for month in months ] 
    249                   } 
     239            return { 
     240                'show' : True, 
     241                'back': { 
     242                    'link' : link({}), 
     243                    'title': _('All dates') 
     244                }, 
     245                'choices': [{ 
     246                    'link': link( {year_field: year_lookup, month_field: month.month}), 
     247                    'title': "%s %s" % (month.strftime('%B') ,  month.year) 
     248                } for month in months] 
     249            } 
    250250        else: 
    251251            years = get_dates('year', lookup_params) 
    252             return { 'show': True, 
    253                      'choices': 
    254                         [ { 'link': link( {year_field: year.year}), 
    255                             'title': year.year  } for year in years ] 
    256                    } 
     252            return { 
     253                'show': True, 
     254                'choices': [{ 
     255                    'link': link({year_field: year.year}), 
     256                    'title': year.year 
     257                } for year in years ] 
     258            } 
    257259date_hierarchy = inclusion_tag('admin/date_hierarchy')(date_hierarchy) 
    258260 
    259261#@inclusion_tag('admin/search_form') 
    260262def search_form(cl): 
    261     return { 'cl': cl, 
    262              'show_result_count': cl.result_count != cl.full_result_count and not cl.opts.one_to_one_field,  
    263              'search_var': SEARCH_VAR } 
     263    return { 
     264        'cl': cl, 
     265        'show_result_count': cl.result_count != cl.full_result_count and not cl.opts.one_to_one_field, 
     266        'search_var': SEARCH_VAR 
     267    } 
    264268search_form = inclusion_tag('admin/search_form')(search_form) 
    265269 
    266270#@inclusion_tag('admin/filter') 
    267271def filter(cl, spec): 
    268     return {'title': spec.title(),  
    269              'choices' : list(spec.choices(cl))} 
     272    return {'title': spec.title(), 'choices' : list(spec.choices(cl))} 
    270273filter = inclusion_tag('admin/filter')(filter) 
    271274 
  • django/branches/new-admin/django/contrib/admin/views/main.py

    r1361 r1430  
    4646    return mod, opts 
    4747 
    48  
    4948def index(request): 
    5049    return render_to_response('admin/index', {'title': _('Site administration')}, context_instance=Context(request)) 
     
    6261        self.get_lookup_params() 
    6362        self.get_results(request) 
    64         self.title = (self.is_popup  
    65                       and _('Select %s') % self.opts.verbose_name  
     63        self.title = (self.is_popup 
     64                      and _('Select %s') % self.opts.verbose_name 
    6665                      or _('Select %s to change') % self.opts.verbose_name) 
    6766        self.get_filters(request) 
    6867        self.pk_attname = self.lookup_opts.pk.attname 
    69      
     68 
    7069    def get_filters(self, request): 
    7170        self.filter_specs = [] 
    72     
    7371        if self.lookup_opts.admin.list_filter and not self.opts.one_to_one_field: 
    7472            filter_fields = [self.lookup_opts.get_field(field_name) \ 
     
    7876                if spec.has_output(): 
    7977                    self.filter_specs.append(spec) 
    80          
    8178        self.has_filters = bool(self.filter_specs) 
    82      
     79 
    8380    def get_query_string(self, new_params={}, remove=[]): 
    8481        p = self.params.copy() 
     
    9390                p[k] = v 
    9491        return '?' + '&amp;'.join(['%s=%s' % (k, v) for k, v in p.items()]).replace(' ', '%20') 
    95      
    96      
     92 
    9793    def get_modules_and_options(self, app_label, module_name, request): 
    9894        self.mod, self.opts = _get_mod_opts(app_label, module_name) 
    9995        if not request.user.has_perm(app_label + '.' + self.opts.get_change_permission()): 
    10096            raise PermissionDenied 
    101          
     97 
    10298        self.lookup_mod, self.lookup_opts = self.mod, self.opts 
    10399 
     
    114110        if self.params.has_key(PAGE_VAR): 
    115111            del self.params[PAGE_VAR] 
    116              
     112 
    117113    def get_results(self, request): 
    118114        lookup_mod, lookup_params, show_all, page_num = \ 
     
    127123        except: 
    128124            raise IncorrectLookupParameters() 
    129              
     125 
    130126        # Get the total number of objects, with no filters applied. 
    131127        real_lookup_params = lookup_params.copy() 
     
    139135        can_show_all = result_count <= MAX_SHOW_ALL_ALLOWED 
    140136        multi_page = result_count > DEFAULT_RESULTS_PER_PAGE 
    141          
     137 
    142138        # Get the list of objects to display on this page. 
    143139        if (show_all and can_show_all) or not multi_page: 
     
    148144            except InvalidPage: 
    149145                result_list = [] 
    150         (self.result_count, self.full_result_count, self.result_list,  
    151             self.can_show_all, self.multi_page, self.paginator) = (result_count,  
     146        (self.result_count, self.full_result_count, self.result_list, 
     147            self.can_show_all, self.multi_page, self.paginator) = (result_count, 
    152148                  full_result_count, result_list, can_show_all, multi_page, paginator ) 
    153      
     149 
    154150    def url_for_result(self, result): 
    155151        return "%s/" % getattr(result, self.pk_attname) 
    156          
     152 
    157153    def get_ordering(self): 
    158154        lookup_opts, params = self.lookup_opts, self.params 
     
    162158        # ordering from the query string. 
    163159        ordering = lookup_opts.admin.ordering or lookup_opts.ordering or ['-' + lookup_opts.pk.name] 
    164          
     160 
    165161        # Normalize it to new-style ordering. 
    166162        ordering = meta.handle_legacy_orderlist(ordering) 
    167          
     163 
    168164        if ordering[0].startswith('-'): 
    169165            order_field, order_type = ordering[0][1:], 'desc' 
     
    184180            order_type = params[ORDER_TYPE_VAR] 
    185181        self.order_field, self.order_type = order_field, order_type 
    186      
     182 
    187183    def get_lookup_params(self): 
    188184        # Prepare the lookup parameters for the API lookup. 
    189185        (params, order_field, lookup_opts, order_type, opts, query) = \ 
    190186           (self.params, self.order_field, self.lookup_opts, self.order_type, self.opts, self.query) 
    191             
     187 
    192188        lookup_params = params.copy() 
    193189        for i in (ALL_VAR, ORDER_VAR, ORDER_TYPE_VAR, SEARCH_VAR, IS_POPUP_VAR): 
     
    197193        # in the related table. 
    198194        lookup_order_field = order_field 
    199         try:  
     195        try: 
    200196            f = lookup_opts.get_field(order_field) 
    201197        except meta.FieldDoesNotExist: 
     
    229225                or_queries.append(or_query) 
    230226            lookup_params['_or'] = or_queries 
    231          
     227 
    232228        if opts.one_to_one_field: 
    233229            lookup_params.update(opts.one_to_one_field.rel.limit_choices_to) 
    234230        self.lookup_params = lookup_params 
    235      
     231 
    236232 
    237233def change_list(request, app_label, module_name): 
     
    240236    except IncorrectLookupParameters: 
    241237        return HttpResponseRedirect(request.path) 
    242      
     238 
    243239    c = Context(request, { 
    244240        'title': cl.title, 
     
    247243    }) 
    248244    c.update( { 'has_add_permission': c['perms'][app_label][cl.opts.get_add_permission()]}), 
    249     return render_to_response('admin/change_list',  
     245    return render_to_response('admin/change_list', 
    250246                               context_instance = c) 
    251247change_list = staff_member_required(change_list) 
     
    271267            seen_collapse = True 
    272268            js.append('js/admin/CollapsedFieldsets.js' ) 
    273          
     269 
    274270        for field_line in field_set: 
    275271            try: 
     
    285281class AdminBoundField(BoundField): 
    286282    def __init__(self, field, field_mapping, original): 
    287         super(AdminBoundField, self).__init__(field,field_mapping,original)      
    288  
    289         self.element_id = self.form_fields[0].get_id()  
     283        super(AdminBoundField, self).__init__(field,field_mapping,original) 
     284 
     285        self.element_id = self.form_fields[0].get_id() 
    290286        self.has_label_first = not isinstance(self.field, meta.BooleanField) 
    291287        self.raw_id_admin = use_raw_id_admin(field) 
     
    295291        self.hidden = isinstance(self.field, meta.AutoField) 
    296292        self.first = False 
    297          
     293 
    298294        classes = [] 
    299         if(self.raw_id_admin):  
     295        if(self.raw_id_admin): 
    300296            classes.append('nowrap') 
    301297        if max([bool(f.errors()) for f in self.form_fields]): 
     
    304300            self.cell_class_attribute = ' class="%s" ' % ' '.join(classes) 
    305301        self._repr_filled = False 
    306      
     302 
    307303    def _fetch_existing_display(self, func_name): 
    308304        class_dict = self.original.__class__.__dict__ 
    309305        func = class_dict.get(func_name) 
    310306        return func(self.original) 
    311          
     307 
    312308    def _fill_existing_display(self): 
    313         if self._display_filled:  
     309        if self._display_filled: 
    314310            return 
    315311        #HACK 
     
    318314             self._display = self._fetch_existing_display(func_name) 
    319315        elif isinstance(self.field.rel, meta.ManyToMany): 
    320             func_name = 'get_%s_list' % self.field.name  
     316            func_name = 'get_%s_list' % self.field.name 
    321317            self._display =  ",".join(self._fetch_existing_display(func_name)) 
    322318        self._display_filled = True 
    323          
     319 
    324320    def existing_display(self): 
    325321        self._fill_existing_display() 
     
    330326 
    331327    def html_error_list(self): 
    332         return " ".join([form_field.html_error_list() for form_field in self.form_fields if form_field.errors])         
    333  
     328        return " ".join([form_field.html_error_list() for form_field in self.form_fields if form_field.errors]) 
    334329 
    335330class AdminBoundFieldLine(BoundFieldLine): 
     
    343338    def __init__(self, field_set, field_mapping, original): 
    344339        super(AdminBoundFieldSet, self).__init__(field_set, field_mapping, original, AdminBoundFieldLine) 
    345          
     340 
    346341class BoundManipulator(object): 
    347342    def __init__(self, opts, manipulator, field_mapping): 
    348343        self.inline_related_objects = opts.get_followed_related_objects(manipulator.follow) 
    349344        self.original = hasattr(manipulator, 'original_object') and manipulator.original_object or None 
    350         self.bound_field_sets = [field_set.bind(field_mapping, self.original, AdminBoundFieldSet)  
     345        self.bound_field_sets = [field_set.bind(field_mapping, self.original, AdminBoundFieldSet) 
    351346                                 for field_set in opts.admin.get_field_sets(opts)] 
    352347        self.ordered_objects = opts.get_ordered_objects()[:] 
     
    356351        super(AdminBoundManipulator, self).__init__(opts, manipulator, field_mapping) 
    357352        field_sets = opts.admin.get_field_sets(opts) 
    358          
     353 
    359354        self.auto_populated_fields = [f for f in opts.fields if f.prepopulate_from] 
    360         self.javascript_imports = get_javascript_imports(opts, self.auto_populated_fields, self.ordered_objects, field_sets);                          
    361          
     355        self.javascript_imports = get_javascript_imports(opts, self.auto_populated_fields, self.ordered_objects, field_sets); 
     356 
    362357        self.coltype = self.ordered_objects and 'colMS' or 'colM' 
    363358        self.has_absolute_url = hasattr(opts.get_model_module().Klass, 'get_absolute_url') 
    364359        self.form_enc_attrib = opts.has_field_type(meta.FileField) and \ 
    365360                                'enctype="multipart/form-data" ' or '' 
    366          
    367         self.first_form_field_id = self.bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id();                 
     361 
     362        self.first_form_field_id = self.bound_field_sets[0].bound_field_lines[0].bound_fields[0].form_fields[0].get_id(); 
    368363        self.ordered_object_pk_names = [o.pk.name for o in self.ordered_objects] 
    369          
     364 
    370365        self.save_on_top = opts.admin.save_on_top 
    371366        self.save_as = opts.admin.save_as 
    372          
     367 
    373368        self.content_type_id = opts.get_content_type_id() 
    374369        self.verbose_name_plural = opts.verbose_name_plural 
    375370        self.verbose_name = opts.verbose_name 
    376371        self.object_name = opts.object_name 
    377          
     372 
    378373    def get_ordered_object_pk(self, ordered_obj): 
    379374        for name in self.ordered_object_pk_names: 
     
    381376                return str(getattr(ordered_obj, name)) 
    382377        return "" 
    383          
     378 
    384379def render_change_form(opts, manipulator, app_label, context, add=False, change=False, show_delete=False, form_url=''): 
    385      
    386380    extra_context = { 
    387381        'add': add, 
     
    392386        'app_label': app_label, 
    393387    } 
    394      
    395388    context.update(extra_context) 
    396      
    397     return render_to_response(["admin/%s/%s/change_form" % (app_label, opts.object_name.lower() ),  
    398                                "admin/%s/change_form" % app_label ,  
    399                                "admin/change_form"],  
    400                               context_instance=context) 
    401     
     389    return render_to_response(["admin/%s/%s/change_form" % (app_label, opts.object_name.lower() ), 
     390                               "admin/%s/change_form" % app_label , 
     391                               "admin/change_form"], context_instance=context) 
     392 
    402393def log_add_message(user, opts,manipulator,new_object): 
    403394    pk_value = getattr(new_object, opts.pk.attname) 
     
    415406        errors = manipulator.get_validation_errors(new_data) 
    416407        manipulator.do_html2python(new_data) 
    417          
     408 
    418409        if not errors and not request.POST.has_key("_preview"): 
    419410            new_object = manipulator.save(new_data) 
     
    440431        # Add default data. 
    441432        new_data = manipulator.flatten_data() 
    442          
     433 
    443434        # Override the defaults with request.GET, if it exists. 
    444435        new_data.update(request.GET) 
     
    447438    # Populate the FormWrapper. 
    448439    form = formfields.FormWrapper(manipulator, new_data, errors, edit_inline=True) 
    449      
     440 
    450441    c = Context(request, { 
    451442        'title': _('Add %s') % opts.verbose_name, 
     
    456447    if object_id_override is not None: 
    457448        c['object_id'] = object_id_override 
    458      
     449 
    459450    return render_change_form(opts, manipulator, app_label, c, add=True) 
    460451add_stage = staff_member_required(add_stage) 
     
    474465        change_message = _('No fields changed.') 
    475466    log.log_action(user.id, opts.get_content_type_id(), pk_value, str(new_object), log.CHANGE, change_message) 
    476      
     467 
    477468def change_stage(request, app_label, module_name, object_id): 
    478469    mod, opts = _get_mod_opts(app_label, module_name) 
     
    492483 
    493484        errors = manipulator.get_validation_errors(new_data) 
    494          
     485 
    495486        manipulator.do_html2python(new_data) 
    496487        if not errors and not request.POST.has_key("_preview"): 
     
    517508        # Populate new_data with a "flattened" version of the current data. 
    518509        new_data = manipulator.flatten_data() 
    519         
    520         # TODO: do this in flatten_data...  
     510 
     511        # TODO: do this in flatten_data... 
    521512        # If the object has ordered objects on its admin page, get the existing 
    522513        # order and flatten it into a comma-separated list of IDs. 
    523          
     514 
    524515        id_order_list = [] 
    525516        for rel_obj in opts.get_ordered_objects(): 
     
    533524    form.original = manipulator.original_object 
    534525    form.order_objects = [] 
    535      
     526 
    536527    #TODO Should be done in flatten_data  / FormWrapper construction 
    537528    for related in opts.get_followed_related_objects(): 
    538529        wrt = related.opts.order_with_respect_to 
    539         if wrt and wrt.rel and wrt.rel.to == opts:  
    540             func = getattr(manipulator.original_object, 'get_%s_list' %  
     530        if wrt and wrt.rel and wrt.rel.to == opts: 
     531            func = getattr(manipulator.original_object, 'get_%s_list' % 
    541532                    related.get_method_name_part()) 
    542533            orig_list = func() 
    543534            form.order_objects.extend(orig_list) 
    544              
     535 
    545536    c = Context(request, { 
    546537        'title': _('Change %s') % opts.verbose_name, 
     
    552543 
    553544    return render_change_form(opts,manipulator, app_label, c, change=True) 
    554      
    555      
    556545 
    557546def _nest_help(obj, depth, val):