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

revise citation configuration #67

Merged
merged 4 commits into from
Sep 23, 2024
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
6 changes: 5 additions & 1 deletion bmds_ui/analysis/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ def word(self, request, *args, **kwargs):
if response.status is ReportStatus.COMPLETE:
cache.delete() # destroy from cache; request is now complete
edit = instance.password == request.query_params.get("editKey", "")
data = add_update_url(instance, response.content, uri) if edit else response.content
data = (
add_update_url(instance, response.content, uri)
if edit and not settings.IS_DESKTOP
else response.content
)
return Response(renderers.BinaryFile(data=data, filename=instance.slug))

return Response(response.model_dump(), content_type="application/json")
Expand Down
17 changes: 10 additions & 7 deletions bmds_ui/analysis/reporting/docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ def build_docx(

write_setting_p(report, "Report Generated: ", to_timestamp(now()))

p = report.document.add_paragraph()
p.add_run(ANALYSIS_URL).bold = True
uri += analysis.get_absolute_url()
add_url_hyperlink(p, uri, "View")
if not settings.IS_DESKTOP:
p = report.document.add_paragraph()
p.add_run(ANALYSIS_URL).bold = True
uri += analysis.get_absolute_url()
add_url_hyperlink(p, uri, "View")

version_label = "BMDS Desktop Version: " if settings.IS_DESKTOP else "BMDS Online Version: "
write_setting_p(report, version_label, bmds_ui_version)

bmds_version = analysis.get_bmds_version()
write_setting_p(report, "BMDS Version: ", f"{bmds_version.python} ({bmds_version.dll})")
write_setting_p(
report,
version_label,
f"{bmds_ui_version} (pybmds {bmds_version.python}; bmdscore {bmds_version.dll})",
)

if not analysis.is_finished:
report.document.add_paragraph("Execution is incomplete; no report could be generated")
Expand Down
11 changes: 4 additions & 7 deletions bmds_ui/analysis/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import re
from textwrap import dedent

from django.conf import settings
from django.utils.timezone import now
Expand All @@ -13,14 +12,12 @@ def get_citation() -> str:
"""
Return a citation for the software.
"""
year = now().strftime("%Y")
year = "20" + __version__[:2]
accessed = now().strftime("%B %d, %Y")
version = get_version()
uri = settings.WEBSITE_URI
return dedent(
f"""\
United States Environmental Protection Agency. ({year}). BMDS Online ({__version__}; pybmds {version.python}; bmdscore {version.dll}) [Web App]. Available from {uri}. Accessed {accessed}."""
)
application = "BMDS Desktop" if settings.IS_DESKTOP else "BMDS Online"
uri = "https://pypi.org/project/bmds-ui/" if settings.IS_DESKTOP else settings.WEBSITE_URI
return f"U.S. Environmental Protection Agency. ({year}). {application} ({__version__}; pybmds {version.python}; bmdscore {version.dll}) [Software]. Available from {uri}. Accessed {accessed}."


re_hex_color = re.compile("^#(?:[0-9a-fA-F]{3}){1,2}$")
13 changes: 13 additions & 0 deletions tests/analysis/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from bmds_ui.analysis import utils


def test_get_citation(settings):
initial = settings.IS_DESKTOP

settings.IS_DESKTOP = False
assert "BMDS Online" in utils.get_citation()

settings.IS_DESKTOP = True
assert "BMDS Desktop" in utils.get_citation()

settings.IS_DESKTOP = initial