Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding release notes export #1515

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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