Skip to content

Commit

Permalink
adding release notes export (#1515)
Browse files Browse the repository at this point in the history
* adding release notes export

* Update models.py

* Update models.py

---------

Co-authored-by: Staxly <[email protected]>
  • Loading branch information
yblock and staxly authored Oct 26, 2023
1 parent e1695b2 commit 31b231b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions errata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ def __str__(self):
return self.book.book_title

class Meta:
verbose_name = "erratum"
verbose_name_plural = "erratum"
verbose_name = "erratum list"
verbose_name_plural = "errata list"


class EmailText(models.Model):
Expand Down

0 comments on commit 31b231b

Please sign in to comment.