Add ability to export data

This commit is contained in:
Gabriel Augendre 2018-05-22 11:10:09 +02:00
parent 4499ee8c6b
commit 4abc66d675
4 changed files with 116 additions and 4 deletions

View file

@ -16,6 +16,7 @@ django-dotenv = "*"
uuid = "*"
django-anymail = {extras = ["mailgun"]}
whitenoise = "*"
django-import-export = "*"
[dev-packages]

87
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "f5fa95f68ed1841f7039a0f916d4471f308751c2bd80d8aa5758f1a5ac4f819f"
"sha256": "84c82ea544617a654420f88f0121bd55a61f6aa48bf9e0da6e74670dad53743c"
},
"pipfile-spec": 6,
"requires": {
@ -30,6 +30,12 @@
],
"version": "==3.0.4"
},
"diff-match-patch": {
"hashes": [
"sha256:9dba5611fbf27893347349fd51cc1911cb403682a7163373adacc565d11e2e4c"
],
"version": "==20121119"
},
"dj-database-url": {
"hashes": [
"sha256:4aeaeb1f573c74835b0686a2b46b85990571159ffc21aa57ecd4d1e1cb334163",
@ -69,6 +75,20 @@
"index": "pypi",
"version": "==1.4.2"
},
"django-import-export": {
"hashes": [
"sha256:15d076086ec0af8ba4e70772b99cdf99b52ca1863328c6aaa91185010a1bb907",
"sha256:7e049a44d65747db1a4eea4053d1f4cc9a1f137b256f932b144ddf5e617c08bd"
],
"index": "pypi",
"version": "==1.0.1"
},
"et-xmlfile": {
"hashes": [
"sha256:614d9722d572f6246302c4491846d2c393c199cfa4edc9af593437691683335b"
],
"version": "==1.0.1"
},
"gunicorn": {
"hashes": [
"sha256:7ef2b828b335ed58e3b64ffa84caceb0a7dd7c5ca12f217241350dec36a1d5dc",
@ -84,6 +104,26 @@
],
"version": "==2.6"
},
"jdcal": {
"hashes": [
"sha256:948fb8d079e63b4be7a69dd5f0cd618a0a57e80753de8248fd786a8a20658a07",
"sha256:ea0a5067c5f0f50ad4c7bdc80abad3d976604f6fb026b0b3a17a9d84bb9046c9"
],
"version": "==1.4"
},
"odfpy": {
"hashes": [
"sha256:6bcaf3b23aa9e49ed8c8c177266539b211add4e02402748a994451482a10cb1b",
"sha256:ab1d67311b3c42dfad1063692c419c137fd6d5a6f0c6380d13758c2593a2b8c9"
],
"version": "==1.3.6"
},
"openpyxl": {
"hashes": [
"sha256:0046fca88d6731875a385bf7edd689d7c4133f829203ea615a81291de3fa48b6"
],
"version": "==2.5.3"
},
"psycopg2-binary": {
"hashes": [
"sha256:02eb674e3d5810e19b4d5d00720b17130e182da1ba259dda608aaf33d787347d",
@ -124,6 +164,25 @@
],
"version": "==2018.4"
},
"pyyaml": {
"hashes": [
"sha256:0c507b7f74b3d2dd4d1322ec8a94794927305ab4cebbe89cc47fe5e81541e6e8",
"sha256:16b20e970597e051997d90dc2cddc713a2876c47e3d92d59ee198700c5427736",
"sha256:3262c96a1ca437e7e4763e2843746588a965426550f3797a79fca9c6199c431f",
"sha256:326420cbb492172dec84b0f65c80942de6cedb5233c413dd824483989c000608",
"sha256:4474f8ea030b5127225b8894d626bb66c01cda098d47a2b0d3429b6700af9fd8",
"sha256:592766c6303207a20efc445587778322d7f73b161bd994f227adaa341ba212ab",
"sha256:5ac82e411044fb129bae5cfbeb3ba626acb2af31a8d17d175004b70862a741a7",
"sha256:5f84523c076ad14ff5e6c037fe1c89a7f73a3e04cf0377cb4d017014976433f3",
"sha256:827dc04b8fa7d07c44de11fabbc888e627fa8293b695e0f99cb544fdfa1bf0d1",
"sha256:b4c423ab23291d3945ac61346feeb9a0dc4184999ede5e7c43e1ffb975130ae6",
"sha256:bc6bced57f826ca7cb5125a10b23fd0f2fff3b7c4701d64c439a300ce665fff8",
"sha256:c01b880ec30b5a6e6aa67b09a2fe3fb30473008c85cd6a67359a1b15ed6d83a4",
"sha256:ca233c64c6e40eaa6c66ef97058cdc80e8d0157a443655baa1b2966e812807ca",
"sha256:e863072cdf4c72eebf179342c94e6989c67185842d9997960b3e69290b2fa269"
],
"version": "==3.12"
},
"requests": {
"hashes": [
"sha256:6a1b267aa90cac58ac3a765d067950e7dbbf75b1da07e895d1f594193a40a38b",
@ -138,6 +197,18 @@
],
"version": "==1.11.0"
},
"tablib": {
"hashes": [
"sha256:b8cf50a61d66655229993f2ee29220553fb2c80403479f8e6de77c0c24649d87"
],
"version": "==0.12.1"
},
"unicodecsv": {
"hashes": [
"sha256:018c08037d48649a0412063ff4eda26eaa81eff1546dbffa51fa5293276ff7fc"
],
"version": "==0.14.1"
},
"urllib3": {
"hashes": [
"sha256:06330f386d6e4b195fbfc736b297f58c5a892e4440e54d294d7004e3a9bbea1b",
@ -159,6 +230,20 @@
],
"index": "pypi",
"version": "==3.3.1"
},
"xlrd": {
"hashes": [
"sha256:83a1d2f1091078fb3f65876753b5302c5cfb6a41de64b9587b74cefa75157148",
"sha256:8a21885513e6d915fe33a8ee5fdfa675433b61405ba13e2a69e62ee36828d7e2"
],
"version": "==1.1.0"
},
"xlwt": {
"hashes": [
"sha256:a082260524678ba48a297d922cc385f58278b8aa68741596a87de01a9c628b2e",
"sha256:c59912717a9b28f1a3c2a98fd60741014b06b043936dcecbc113eaaada156c88"
],
"version": "==1.3.0"
}
},
"develop": {

View file

@ -1,10 +1,19 @@
from django.contrib import admin
from import_export import resources
from import_export.admin import ExportMixin
from manuels.models import Teacher, Book, Level, Editor, SuppliesRequirement
class TeacherResource(resources.ModelResource):
class Meta:
model = Teacher
fields = ('first_name', 'last_name', 'email', 'phone_number')
@admin.register(Teacher)
class TeacherAdmin(admin.ModelAdmin):
class TeacherAdmin(ExportMixin, admin.ModelAdmin):
resource_class = TeacherResource
list_display = ['full_name', 'email', 'phone_number']
def send_link(modeladmin, request, queryset):
@ -21,8 +30,16 @@ class LevelAdmin(admin.ModelAdmin):
pass
class BookResource(resources.ModelResource):
class Meta:
model = Book
fields = ('title', 'authors', 'editor', 'collection', 'publication_year', 'isbn',
'price', 'previously_acquired', 'teacher__first_name', 'teacher__last_name', 'level__name', 'field')
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
class BookAdmin(ExportMixin, admin.ModelAdmin):
resource_class = BookResource
list_display = ['title', 'authors', 'editor', 'collection', 'publication_year', 'isbn',
'price', 'previously_acquired', 'teacher', 'level', 'field']
list_filter = ['editor', 'previously_acquired', 'teacher', 'level']
@ -45,7 +62,15 @@ class EditorAdmin(admin.ModelAdmin):
pass
class SuppliesResource(resources.ModelResource):
class Meta:
model = SuppliesRequirement
fields = ('supplies', 'level__name', 'teacher__first_name', 'teacher__last_name')
@admin.register(SuppliesRequirement)
class SuppliesRequirementAdmin(admin.ModelAdmin):
class SuppliesRequirementAdmin(ExportMixin, admin.ModelAdmin):
resource_class = SuppliesResource
list_display = ['teacher', 'level', 'supplies']
readonly_fields = ['created_at', 'updated_at']
list_filter = ['teacher', 'level']

View file

@ -53,6 +53,7 @@ INSTALLED_APPS = [
'anymail',
'bootstrap4',
'manuels',
'import_export',
]
MIDDLEWARE = [