From 75b63cbda50fbddb7fcfb53283bb850da9b6c1c2 Mon Sep 17 00:00:00 2001 From: Staxly Date: Mon, 23 Oct 2023 10:43:08 -0500 Subject: [PATCH 1/3] adding release notes export --- errata/admin.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/errata/admin.py b/errata/admin.py index 7325ff46a..3f24e0ac7 100644 --- a/errata/admin.py +++ b/errata/admin.py @@ -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 @@ -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 @@ -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', ) From 0033e3c6f84a81386ac70a0e89da7a6a34d26268 Mon Sep 17 00:00:00 2001 From: Staxly Date: Mon, 23 Oct 2023 11:04:09 -0500 Subject: [PATCH 2/3] Update models.py --- errata/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errata/models.py b/errata/models.py index 5303f047a..e56724164 100644 --- a/errata/models.py +++ b/errata/models.py @@ -283,7 +283,7 @@ def __str__(self): class Meta: verbose_name = "erratum" - verbose_name_plural = "erratum" + verbose_name_plural = "errata" class EmailText(models.Model): From c7b3f702886fe9634fd6d8f4f1d829811514ade9 Mon Sep 17 00:00:00 2001 From: Staxly Date: Mon, 23 Oct 2023 11:06:29 -0500 Subject: [PATCH 3/3] Update models.py --- errata/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/errata/models.py b/errata/models.py index e56724164..c1f12cf09 100644 --- a/errata/models.py +++ b/errata/models.py @@ -282,8 +282,8 @@ def __str__(self): return self.book.book_title class Meta: - verbose_name = "erratum" - verbose_name_plural = "errata" + verbose_name = "erratum list" + verbose_name_plural = "errata list" class EmailText(models.Model):