Skip to content

Commit 31b231b

Browse files
yblockstaxly
andauthored
adding release notes export (#1515)
* adding release notes export * Update models.py * Update models.py --------- Co-authored-by: Staxly <[email protected]>
1 parent e1695b2 commit 31b231b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

errata/admin.py

+23-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from import_export import resources
33
from import_export.admin import ExportActionMixin, ImportExportActionModelAdmin
44
from import_export.formats import base_formats
5+
from import_export.fields import Field
56

67
from django.contrib import admin
78
from django.db import models
@@ -26,6 +27,27 @@ class Meta:
2627
model = Errata
2728
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',)
2829
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'
2951

3052
class InlineInternalImage(admin.TabularInline):
3153
model = InternalDocumentation
@@ -77,7 +99,7 @@ class Media:
7799
formfield_overrides = {
78100
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
79101
}
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]
81103
inlines = [InlineInternalImage, ]
82104
raw_id_fields = ('duplicate_id', )
83105

errata/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,8 @@ def __str__(self):
282282
return self.book.book_title
283283

284284
class Meta:
285-
verbose_name = "erratum"
286-
verbose_name_plural = "erratum"
285+
verbose_name = "erratum list"
286+
verbose_name_plural = "errata list"
287287

288288

289289
class EmailText(models.Model):

0 commit comments

Comments
 (0)