2
2
from import_export import resources
3
3
from import_export .admin import ExportActionMixin , ImportExportActionModelAdmin
4
4
from import_export .formats import base_formats
5
+ from import_export .fields import Field
5
6
6
7
from django .contrib import admin
7
8
from django .db import models
@@ -26,6 +27,27 @@ class Meta:
26
27
model = Errata
27
28
fields = ('id' , 'created' , 'modified' , 'book__title' , 'number_of_errors' , 'is_assessment_errata' , 'assessment_id' , 'status' , 'resolution' , 'archived' , 'junk' , 'location' , 'additional_location_information' , 'detail' , 'internal_notes' , 'resolution_notes' , 'resolution_date' , 'error_type' , 'resource' , 'file_1' , 'file_2' ,)
28
29
export_order = ('id' , 'created' , 'modified' , 'book__title' , 'number_of_errors' , 'is_assessment_errata' , 'assessment_id' , 'status' , 'resolution' , 'archived' , 'junk' , 'location' , 'additional_location_information' , 'detail' , 'internal_notes' , 'resolution_notes' , 'resolution_date' , 'error_type' , 'resource' ,)
30
+
31
+ # custom export for release note generation
32
+ class CustomExportResource (resources .ModelResource ):
33
+ location = Field (attribute = 'location' , column_name = 'Location' )
34
+ detail = Field (attribute = 'detail' , column_name = 'Detail' )
35
+ resolution = Field (attribute = 'resolution' , column_name = 'Resolution' )
36
+ error_type = Field (attribute = 'error_type' , column_name = 'Error Type' )
37
+
38
+ class Meta :
39
+ model = Errata
40
+ fields = ('location' , 'detail' , 'resolution' , 'error_type' )
41
+ export_order = ('location' , 'detail' , 'resolution' , 'error_type' )
42
+
43
+ def custom_export_action (modeladmin , request , queryset ):
44
+ resource = CustomExportResource ()
45
+ dataset = resource .export (queryset )
46
+ response = HttpResponse (content_type = 'text/csv' )
47
+ response ['Content-Disposition' ] = 'attachment; filename="Release Notes.csv"'
48
+ response .write (dataset .csv )
49
+ return response
50
+ custom_export_action .short_description = 'Export Errata Release Notes CSV'
29
51
30
52
class InlineInternalImage (admin .TabularInline ):
31
53
model = InternalDocumentation
@@ -77,7 +99,7 @@ class Media:
77
99
formfield_overrides = {
78
100
models .ManyToManyField : {'widget' : CheckboxSelectMultiple },
79
101
}
80
- actions = ['mark_in_review' , 'mark_OpenStax_editorial_review' , 'mark_cartridge_review' , 'mark_reviewed' , 'mark_archived' , 'mark_completed' , ExportActionMixin .export_admin_action ]
102
+ actions = ['mark_in_review' , 'mark_OpenStax_editorial_review' , 'mark_cartridge_review' , 'mark_reviewed' , 'mark_archived' , 'mark_completed' , ExportActionMixin .export_admin_action , custom_export_action ]
81
103
inlines = [InlineInternalImage , ]
82
104
raw_id_fields = ('duplicate_id' , )
83
105
0 commit comments