-
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 #895 from sul-dlss/855-file-downloads
Template and View for downloading data exports MARC files
- Loading branch information
Showing
6 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
libsys_airflow/plugins/data_exports/apps/data_export_download_view.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,42 @@ | ||
import json | ||
import pathlib | ||
from flask_appbuilder import expose, BaseView as AppBuilderBaseView | ||
|
||
|
||
parent = pathlib.Path(__file__).resolve().parent | ||
vendor_file = open(parent / "vendors.json") | ||
vendors = json.load(vendor_file) | ||
|
||
|
||
def path_parent(full_path: pathlib.Path) -> str: | ||
parts = full_path.parts | ||
|
||
return parts[len(parts) - 2] | ||
|
||
|
||
class DataExportDownloadView(AppBuilderBaseView): | ||
default_view = "data_export_download_home" | ||
route_base = "/data_export_download" | ||
|
||
@expose("/") | ||
def data_export_download_home(self): | ||
content = [] | ||
for vendor in vendors['vendors']: | ||
for path in pathlib.Path(f"data-export-files/{vendor}/marc-files").glob( | ||
"*" | ||
): | ||
content.append({vendor: [path_parent(path), path.name]}) | ||
|
||
for path in pathlib.Path(f"data-export-files/{vendor}/transmitted").glob( | ||
"*" | ||
): | ||
content.append({vendor: [path_parent(path), path.name]}) | ||
|
||
return self.render_template("data-export-download/index.html", content=content) | ||
|
||
@expose("/downloads/<vendor>/<folder>/<filename>") | ||
def vendor_marc_record(self, vendor, folder, filename): | ||
file_bytes = pathlib.Path( | ||
f"data-export-files/{vendor}/{folder}/{filename}" | ||
).read_bytes() # noqa | ||
return file_bytes |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"vendors": [ | ||
"gobi", | ||
"google", | ||
"hathi", | ||
"nielsen", | ||
"oclc", | ||
"pod", | ||
"sharevde", | ||
"west" | ||
] | ||
} |
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
29 changes: 29 additions & 0 deletions
29
libsys_airflow/plugins/data_exports/templates/data-export-download/index.html
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,29 @@ | ||
{% extends "appbuilder/base.html" %} | ||
|
||
{% block content %} | ||
<div> | ||
<h2>Vendor MARC files</h2> | ||
<table class="table table-striped"> | ||
<tr> | ||
<th>Vendor</th> | ||
<th>Status</th> | ||
<th>MARC file (download)</th> | ||
</tr> | ||
{% for item in content %} | ||
{% for vendor, marcfile in item.items() %} | ||
<tr> | ||
<td> | ||
{{ vendor }} | ||
</td> | ||
<td> | ||
{{ marcfile[0] }} | ||
</td> | ||
<td> | ||
<a href="{{ url_for('DataExportDownloadView.vendor_marc_record', vendor=vendor, folder=marcfile[0], filename=marcfile[1]) }}" download>{{ marcfile[1] }}</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
{% endfor %} | ||
</table> | ||
</div> | ||
{% endblock %} |
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