Skip to content

Commit

Permalink
Merge pull request django-import-export#409 from freelancersunion/dev…
Browse files Browse the repository at this point in the history
…elop

ImportMixin does not display the import button in admin for users w/o add permissions
  • Loading branch information
bmihelac committed Feb 25, 2016
2 parents 0fd9df7 + 49c19a9 commit 4ba3c39
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ The following is a list of much appreciated contributors:
* jnns (Jannis)
* sgarcialaguna
* carlosp420 (Carlos Peña)
* freelancersunion (Freelancers Union)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "admin/change_list.html" %}
{% extends "admin/import_export/change_list.html" %}
{% load i18n %}

{% block object-tools-items %}
Expand Down
8 changes: 6 additions & 2 deletions tests/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.contrib import admin

from import_export.admin import ImportExportMixin, ExportActionModelAdmin
from import_export.admin import ImportExportMixin, ImportMixin, ExportActionModelAdmin

from .models import Book, Category, Author

Expand All @@ -14,6 +14,10 @@ class BookAdmin(ImportExportMixin, admin.ModelAdmin):
class CategoryAdmin(ExportActionModelAdmin):
pass


class AuthorAdmin(ImportMixin, admin.ModelAdmin):
pass

admin.site.register(Book, BookAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Author)
admin.site.register(Author, AuthorAdmin)
16 changes: 14 additions & 2 deletions tests/core/tests/admin_integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin.models import LogEntry

from core.admin import BookAdmin
from core.models import Category
from core.admin import BookAdmin, AuthorAdmin
from core.models import Category, Author


class ImportExportAdminIntegrationTest(TestCase):
Expand Down Expand Up @@ -86,6 +86,18 @@ def test_import_export_buttons_visible_without_add_permission(self):
self.assertContains(response, _('Export'))
self.assertContains(response, _('Import'))

def test_import_buttons_visible_without_add_permission(self):
# When using ImportMixin, users should be able to see the import button
# without add permission (to be consistent with ImportExportMixin)

original = AuthorAdmin.has_add_permission
AuthorAdmin.has_add_permission = lambda self, request: False
response = self.client.get('/admin/core/author/')
AuthorAdmin.has_add_permission = original

self.assertContains(response, _('Import'))
self.assertTemplateUsed(response, 'admin/import_export/change_list.html')

def test_import_file_name_in_tempdir(self):
# 65 - import_file_name form field can be use to access the filesystem
import_file_name = os.path.join(
Expand Down

0 comments on commit 4ba3c39

Please sign in to comment.