-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #525 from maykinmedia/feature/502-make-report-xlsx
[#502] Make destruction report xlsx file instead of csv
- Loading branch information
Showing
13 changed files
with
211 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,5 @@ celery | |
# Additional libraries | ||
zgw-consumers | ||
furl | ||
python-slugify | ||
python-slugify | ||
XlsxWriter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
backend/src/openarchiefbeheer/destruction/destruction_report.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from dataclasses import dataclass | ||
from typing import IO | ||
|
||
from django.utils.translation import gettext | ||
|
||
import xlsxwriter | ||
from glom import glom | ||
from xlsxwriter.worksheet import Worksheet | ||
|
||
from openarchiefbeheer.zaken.api.constants import ZAAK_METADATA_FIELDS_MAPPINGS | ||
|
||
from .constants import InternalStatus | ||
from .models import DestructionList | ||
|
||
|
||
@dataclass | ||
class DestructionReportGenerator: | ||
destruction_list: DestructionList | ||
|
||
def add_zaken_table(self, worksheet: Worksheet, start_row: int = 0) -> None: | ||
worksheet.write_row( | ||
start_row, 0, [field["name"] for field in ZAAK_METADATA_FIELDS_MAPPINGS] | ||
) | ||
|
||
for row_count, item in enumerate( | ||
self.destruction_list.items.filter( | ||
processing_status=InternalStatus.succeeded | ||
).iterator(chunk_size=1000) | ||
): | ||
data = [ | ||
glom(item.extra_zaak_data, field["path"], default="") | ||
for field in ZAAK_METADATA_FIELDS_MAPPINGS | ||
] | ||
worksheet.write_row(start_row + row_count + 1, 0, data) | ||
|
||
def generate_destruction_report(self, file: IO) -> None: | ||
workbook = xlsxwriter.Workbook(file.name, options={"in_memory": False}) | ||
|
||
worksheet = workbook.add_worksheet(name=gettext("Deleted zaken")) | ||
|
||
self.add_zaken_table(worksheet) | ||
|
||
workbook.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.