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

analysis deletion dates improvements #50

Merged
merged 5 commits into from
Jul 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
2 changes: 1 addition & 1 deletion bmds_ui/analysis/fixtures/initial_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"content_type": 1,
"subject": "Homepage",
"content": {
"template": "<div class=\"row\">\n <div class=\"col-sm-12\">\n <h1>Welcome to BMDS online.</h1>\n </div>\n</div>\n<div class=\"row\">\n <div class=\"col-md-8\">\n <div class=\"col-lg\">\n <p>\n This web-application executes the US EPA's benchmark dose modeling software (<a href=\"https://www.epa.gov/bmds\">BMDS</a>).\n </p>\n <ul>\n <li>Load example datasets below to view example input files; for more information, see the <a href=\"http://bmds-ui.readthedocs.io/en/latest/\">documentation</a>\n </li>\n <li>Software is designed for automated BMDS execution using a\n programming language such as Python, R, or Java. To take\n advantage of automation, use the <a href=\"/api/v1/\">API</a>,\n and see the <a href=\"http://bmds-ui.readthedocs.io/en/latest/quickstart.html\">quickstart</a> section.\n </li>\n </ul>\n </div>\n </div>\n <div class=\"col-md-4\">\n <form action=\"{% url 'analysis_create' %}\" method=\"post\">\n {% csrf_token %}\n <label for=\"id_id\">Create a new analysis:</label>\n <button type=\"submit\" class=\"btn btn-primary btn-block mb-1\">Create a new BMDS analysis</button>\n <p class=\"text-muted\">Analyses are deleted after {{days_to_keep_analyses}} days.</p>\n </form>\n </div>\n</div>\n"
"template": "<div class=\"row\">\n <div class=\"col-sm-12\">\n <h1>Welcome to BMDS online.</h1>\n </div>\n</div>\n<div class=\"row\">\n <div class=\"col-md-8\">\n <div class=\"col-lg\">\n <p>\n This web-application executes the US EPA's benchmark dose modeling software (<a href=\"https://www.epa.gov/bmds\">BMDS</a>).\n </p>\n <ul>\n <li>Load example datasets below to view example input files; for more information, see the <a href=\"http://bmds-ui.readthedocs.io/en/latest/\">documentation</a>\n </li>\n <li>Software is designed for automated BMDS execution using a\n programming language such as Python, R, or Java. To take\n advantage of automation, use the <a href=\"/api/v1/\">API</a>,\n and see the <a href=\"http://bmds-ui.readthedocs.io/en/latest/quickstart.html\">quickstart</a> section.\n </li>\n </ul>\n </div>\n </div>\n <div class=\"col-md-4\">\n <form action=\"{% url 'analysis_create' %}\" method=\"post\">\n {% csrf_token %}\n <label for=\"id_id\">Create a new analysis:</label>\n <button type=\"submit\" class=\"btn btn-primary btn-block mb-1\">Create a new BMDS analysis</button>\n <p class=\"text-muted\">Analyses are deleted after {{days_to_keep_analyses}}.</p>\n </form>\n </div>\n</div>\n"
},
"created": "2021-01-31 08:00:00.123456+00:00",
"last_updated": "2021-01-31 08:00:00.123456+00:00"
Expand Down
Empty file.
18 changes: 0 additions & 18 deletions bmds_ui/analysis/management/commands/delete_old_jobs.py

This file was deleted.

2 changes: 1 addition & 1 deletion bmds_ui/analysis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def has_errors(self):

@classmethod
def delete_old_analyses(cls):
qs = cls.objects.filter(deletion_date=now())
qs = cls.objects.filter(deletion_date__lt=now())
logger.info(f"Removing {qs.count()} old BMDS analysis")
qs.delete()

Expand Down
9 changes: 8 additions & 1 deletion bmds_ui/analysis/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ def _render_template(self, extra):
content = models.Content.get_cached_content(models.ContentType.HOMEPAGE)
return Template(content["template"]).render(context)

def days_to_keep(self, days: int) -> str:
if days == 365:
return "1 year"
elif days < 365 or days % 365 > 0:
return f"{days} days"
return f"{days // 365} years"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update(
days_to_keep_analyses=settings.DAYS_TO_KEEP_ANALYSES,
days_to_keep_analyses=self.days_to_keep(settings.DAYS_TO_KEEP_ANALYSES),
citation=get_citation(),
)
context["page"] = self._render_template(context)
Expand Down
2 changes: 1 addition & 1 deletion bmds_ui/main/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
}
}

DAYS_TO_KEEP_ANALYSES = 180
DAYS_TO_KEEP_ANALYSES = int(os.environ.get("ANALYSIS_RETENTION_DAYS", "365"))


# commit information
Expand Down
19 changes: 18 additions & 1 deletion tests/analysis/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from bmds_ui.analysis.models import Analysis, Collection
from bmds_ui.analysis.validators.session import BmdsVersion
from bmds_ui.analysis.views import Analytics, DesktopHome, get_analysis_or_404
from bmds_ui.analysis.views import Analytics, DesktopHome, Home, get_analysis_or_404


@pytest.mark.django_db
Expand Down Expand Up @@ -132,6 +132,23 @@ def test_view(self):
assertTemplateUsed(resp, template)


@pytest.mark.django_db
class TestHome:
def test_views(self):
request = RequestFactory().get(reverse("home"))
response = Home.as_view()(request)
assert response.status_code == 200

def test_get_days_to_keep(self):
view = Home()
assert view.days_to_keep(180) == "180 days"
assert view.days_to_keep(365) == "1 year"
assert view.days_to_keep(366) == "366 days"
assert view.days_to_keep(730) == "2 years"
assert view.days_to_keep(1095) == "3 years"
assert view.days_to_keep(1096) == "1096 days"


@pytest.mark.django_db
class TestDesktopHome:
def test_views(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5171,7 +5171,7 @@
csrf_token %}\n <label for=\"id_id\">Create a new analysis:</label>\n
\ <button type=\"submit\" class=\"btn btn-primary btn-block mb-1\">Create
a new BMDS analysis</button>\n <p class=\"text-muted\">Analyses
are deleted after {{days_to_keep_analyses}} days.</p>\n </form>\n </div>\n</div>\n"
are deleted after {{days_to_keep_analyses}}.</p>\n </form>\n </div>\n</div>\n"
created: 2021-03-01 22:39:06.328990+00:00
last_updated: 2021-03-01 22:39:06.329015+00:00
- model: reversion.revision
Expand Down