Ticket #10595: patch_django_10595.20090324-2.diff

File patch_django_10595.20090324-2.diff, 5.4 KB (added by David Larlet, 15 years ago)

Now with documentation and tests

  • django/contrib/admin/options.py

     
    207207        for inline_class in self.inlines:
    208208            inline_instance = inline_class(self.model, self.admin_site)
    209209            self.inline_instances.append(inline_instance)
    210         if 'action_checkbox' not in self.list_display:
     210        if 'action_checkbox' not in self.list_display and self.actions is not None:
    211211            self.list_display = ['action_checkbox'] +  list(self.list_display)
    212212        if not self.list_display_links:
    213213            for name in self.list_display:
     
    421421        """
    422422        actions = {}
    423423        for klass in [self.admin_site] + self.__class__.mro()[::-1]:
    424             for action in getattr(klass, 'actions', []):
     424            class_actions = getattr(klass, 'actions', [])
     425            if not class_actions:
     426                continue # avoid iteration over None value
     427            for action in class_actions:
    425428                func, name, description = self.get_action(action)
    426429                actions[name] = (func, name, description)
    427430        return actions
     
    948951            media = self.media
    949952           
    950953        # Build the action form and populate it with available actions.
    951         action_form = self.action_form(auto_id=None)
    952         action_form.fields['action'].choices = self.get_action_choices(request)       
     954        if self.actions is None:
     955            action_form = False
     956            actions_on_top = False
     957            actions_on_bottom = False
     958        else:
     959            action_form = self.action_form(auto_id=None)
     960            action_form.fields['action'].choices = self.get_action_choices(request)
     961            actions_on_top = self.actions_on_top
     962            actions_on_bottom = self.actions_on_bottom
    953963
    954964        context = {
    955965            'title': cl.title,
     
    960970            'root_path': self.admin_site.root_path,
    961971            'app_label': app_label,
    962972            'action_form': action_form,
    963             'actions_on_top': self.actions_on_top,
    964             'actions_on_bottom': self.actions_on_bottom,
     973            'actions_on_top': actions_on_top,
     974            'actions_on_bottom': actions_on_bottom,
    965975        }
    966976        context.update(extra_context or {})
    967977        return render_to_response(self.change_list_template or [
  • django/contrib/admin/templates/admin/change_list.html

     
    99    <script type="text/javascript" src="../../jsi18n/"></script>
    1010  {% endif %}
    1111  {{ media }}
     12  {% if not actions_on_top and not actions_on_bottom %}
     13    <style>
     14      #changelist table thead th:first-child {width: inherit}
     15    </style>
     16  {% endif %}
    1217{% endblock %}
    1318
    1419{% block bodyclass %}change-list{% endblock %}
  • tests/regressiontests/admin_views/tests.py

     
    939939        }
    940940        response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
    941941        self.failUnlessEqual(response.status_code, 302)
     942
     943    def test_model_without_action(self):
     944        "Tests a ModelAdmin without any action"
     945        response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')
     946        self.assertEquals(response.context["action_form"], False)
     947        self.assertEquals(response.context["actions_on_top"], False)
     948        self.assertEquals(response.context["actions_on_bottom"], False)
  • tests/regressiontests/admin_views/models.py

     
    221221class ExternalSubscriber(Subscriber):
    222222    pass
    223223
     224class OldSubscriber(Subscriber):
     225    pass
     226
    224227def external_mail(request, selected):
    225228    EmailMessage(
    226229        'Greetings from a function action',
     
    236239class ExternalSubscriberAdmin(admin.ModelAdmin):
    237240    actions = [external_mail, redirect_to]
    238241
     242class OldSubscriberAdmin(admin.ModelAdmin):
     243    actions = None
     244
    239245admin.site.register(Article, ArticleAdmin)
    240246admin.site.register(CustomArticle, CustomArticleAdmin)
    241247admin.site.register(Section, inlines=[ArticleInline])
     
    246252admin.site.register(Persona, PersonaAdmin)
    247253admin.site.register(Subscriber, SubscriberAdmin)
    248254admin.site.register(ExternalSubscriber, ExternalSubscriberAdmin)
     255admin.site.register(OldSubscriber, OldSubscriberAdmin)
    249256
    250257# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    251258# That way we cover all four cases:
  • docs/ref/contrib/admin/actions.txt

     
    237237       
    238238    admin.site.add_action(export_selected_objects)
    239239   
     240Removing actions
     241----------------
     242
     243If you set ``None`` in ``actions``, this tells the :class:`ModelAdmin` to do
     244not display any dropdown menu nor checkboxes related to admin actions.
     245
Back to Top