diff --git a/src/lgr_idn_table_review/idn_tool/views.py b/src/lgr_idn_table_review/idn_tool/views.py index cd8bcbaa..2a70ab0f 100644 --- a/src/lgr_idn_table_review/idn_tool/views.py +++ b/src/lgr_idn_table_review/idn_tool/views.py @@ -115,6 +115,7 @@ class IdnTableReviewListReport(IdnTableReviewViewMixin, TemplateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + context['display_exp'] = True zipname = f"{self.kwargs.get('report_id')}.zip" context['reports'] = self.api.list_storage(report_id=self.kwargs.get('report_id'), exclude={'file__endswith': zipname}) diff --git a/src/lgr_idn_table_review/templates/lgr_idn_table_review/list_report_files.html b/src/lgr_idn_table_review/templates/lgr_idn_table_review/list_report_files.html index 37035685..e037fd2b 100644 --- a/src/lgr_idn_table_review/templates/lgr_idn_table_review/list_report_files.html +++ b/src/lgr_idn_table_review/templates/lgr_idn_table_review/list_report_files.html @@ -14,7 +14,9 @@ {% block content %}

{% trans 'The following files contains your IDN review reports.' %}

- {% include 'lgr_models/_report_warning.html' %} + {% if display_exp %} + {% include 'lgr_models/_report_warning.html' %} + {% endif %} @@ -30,7 +32,9 @@ target="_blank" rel="noopener noreferrer"> {{ report.filename }} -

{{ report|display_expiration }}

+ {% if display_exp %} +

{{ report|display_expiration }}

+ {% endif %}
diff --git a/src/lgr_tasks/tasks.py b/src/lgr_tasks/tasks.py index 6e85bdef..532d3411 100644 --- a/src/lgr_tasks/tasks.py +++ b/src/lgr_tasks/tasks.py @@ -40,8 +40,9 @@ def clean_reports(): lgr_settings.report_expiration_last_run = timezone.now() lgr_settings.save() nbr, __ = LGRReport.objects.filter( - created_at__lt=datetime.datetime.now() - datetime.timedelta(days=lgr_settings.report_expiration_delay) - ).delete() + created_at__lt=datetime.datetime.now() - datetime.timedelta(days=lgr_settings.report_expiration_delay)).filter( + # do not clean ICANN reports + idnreviewicannreport__isnull=True).delete() logger.info('%d reports removed' % nbr) diff --git a/src/lgr_tasks/tests/test_tasks.py b/src/lgr_tasks/tests/test_tasks.py index e7993df3..6098a9bc 100644 --- a/src/lgr_tasks/tests/test_tasks.py +++ b/src/lgr_tasks/tests/test_tasks.py @@ -1,17 +1,17 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -import codecs import csv import datetime import os from io import StringIO -from time import sleep from django.core.cache import cache from django.core.files import File from django.test import override_settings from lgr_advanced.api import LGRToolReportStorage +from lgr_idn_table_review.icann_tools.api import LGRIcannReportStorage +from lgr_idn_table_review.idn_tool.api import LGRIdnReviewApi from lgr_manage.api import LGRAdminReportStorage from lgr_manage.models import AdminReport from lgr_models.models.lgr import RzLgr @@ -69,20 +69,31 @@ def test_calculate_index_variant_labels_tlds(self): def test_clean_reports(self): # save fake user generated report + user = self.login_user() last_month = datetime.datetime.now() - datetime.timedelta(days=31) lgr_settings.report_expiration_delay = 30 storage = LGRAdminReportStorage(self.login_admin()) report1 = storage.storage_save_report_file('test1.csv', StringIO()) - storage = LGRToolReportStorage(self.login_user()) + storage = LGRToolReportStorage(user) report2 = storage.storage_save_report_file('test2.csv', StringIO()) report3 = storage.storage_save_report_file('test3.csv', StringIO()) + storage = LGRIdnReviewApi(user) + report4 = storage.storage_save_report_file('test4.csv', StringIO()) + storage = LGRIcannReportStorage(self.login_icann()) + report5 = storage.storage_save_report_file('test5.csv', StringIO()) report1.created_at = last_month report1.save() report2.created_at = last_month report2.save() + report4.created_at = last_month + report4.save() + report5.created_at = last_month + report5.save() # sanity check - self.assertListEqual(list(LGRReport.objects.values_list('pk', flat=True)), [report1.pk, report2.pk, report3.pk]) + self.assertListEqual(sorted(list(LGRReport.objects.values_list('pk', flat=True))), + [report1.pk, report2.pk, report3.pk, report4.pk, report5.pk]) clean_reports() - self.assertListEqual(list(LGRReport.objects.values_list('pk', flat=True)), [report3.pk]) + # unexpired reports should still be there along with ICANN reports + self.assertListEqual(sorted(list(LGRReport.objects.values_list('pk', flat=True))), [report3.pk, report5.pk])