Skip to content

Commit

Permalink
adding release notes export
Browse files Browse the repository at this point in the history
  • Loading branch information
staxly committed Oct 23, 2023
1 parent 80e330e commit 75b63cb
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion errata/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from import_export import resources
from import_export.admin import ExportActionMixin, ImportExportActionModelAdmin
from import_export.formats import base_formats
from import_export.fields import Field

from django.contrib import admin
from django.db import models
Expand All @@ -26,6 +27,27 @@ class Meta:
model = Errata
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',)
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',)

# custom export for release note generation
class CustomExportResource(resources.ModelResource):
location = Field(attribute='location', column_name='Location')
detail = Field(attribute='detail', column_name='Detail')
resolution = Field(attribute='resolution', column_name='Resolution')
error_type = Field(attribute='error_type', column_name='Error Type')

class Meta:
model = Errata
fields = ('location', 'detail', 'resolution', 'error_type')
export_order = ('location', 'detail', 'resolution', 'error_type')

def custom_export_action(modeladmin, request, queryset):
resource = CustomExportResource()
dataset = resource.export(queryset)
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; filename="Release Notes.csv"'
response.write(dataset.csv)
return response
custom_export_action.short_description = 'Export Errata Release Notes CSV'

class InlineInternalImage(admin.TabularInline):
model = InternalDocumentation
Expand Down Expand Up @@ -77,7 +99,7 @@ class Media:
formfield_overrides = {
models.ManyToManyField: {'widget': CheckboxSelectMultiple},
}
actions = ['mark_in_review', 'mark_OpenStax_editorial_review', 'mark_cartridge_review', 'mark_reviewed', 'mark_archived', 'mark_completed', ExportActionMixin.export_admin_action]
actions = ['mark_in_review', 'mark_OpenStax_editorial_review', 'mark_cartridge_review', 'mark_reviewed', 'mark_archived', 'mark_completed', ExportActionMixin.export_admin_action, custom_export_action]
inlines = [InlineInternalImage, ]
raw_id_fields = ('duplicate_id', )

Expand Down

0 comments on commit 75b63cb

Please sign in to comment.