Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export button not visible when no add permission #38

Closed
treyhunner opened this issue Jul 23, 2013 · 3 comments
Closed

Export button not visible when no add permission #38

treyhunner opened this issue Jul 23, 2013 · 3 comments

Comments

@treyhunner
Copy link

When add permission is disabled for a model the admin change list doesn't display an Export button.

My solution was to use this template:

{% extends "admin/import_export/change_list_export.html" %}
{% load i18n %}

{% block object-tools %}
    {% if not has_add_permission %}
        <ul class="grp-object-tools">
            {% block object-tools-items %}
                <li><a href="export/{{ cl.get_query_string }}" class="export_link">{% trans "Export" %}</a></li>
            {% endblock %}
        </ul>
    {% else %}
    {{ block.super }}
    {% endif %}
{% endblock %}

Note: I'm using django-grappelli

@bmihelac
Copy link
Member

Indeed, I see that object-tools is rendered only if has_add_permission:

https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/change_list.html#L52

Your snippet would not render Export button if there is an add_permission, right?

@treyhunner
Copy link
Author

Right but I extended from {% extends "admin/import_export/change_list_export.html" %} which implements the feature only if there is has_add_permission (I did this using another template name).

An alternative that should work as a replacement for change_list_export.html:

{% extends "admin/change_list.html" %}
{% load i18n %}

{% block object-tools %}
    {% if not has_add_permission %}
        <ul class="grp-object-tools">
            <li><a href="export/{{ cl.get_query_string }}" class="export_link">{% trans "Export" %}</a></li>
            {% block object-tools-items %}
                {{ block.super }}
            {% endblock %}
        </ul>
    {% else %}
    {{ block.super }}
    {% endif %}
{% endblock %}

@bmihelac
Copy link
Member

I restrained from including css that would be required with adding grp-object-tools. Having two lists with object-list class does not work too because of specific css.

Conditionaly including filling blocks would not work too and would probably be cumbersome, so I made additional change_list.html template.

Can you please check if this works for you (especially with django-grapelli) and reopen if there are still issues.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants