From 6bdd9ac6e57fdf6e90c2bc7a2c23f417c6f9d859 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 14 Sep 2021 10:07:34 +0200 Subject: [PATCH 1/3] rename delete_filter_trials to cleanup_filter_trials --- .../{delete_filter_trials.py => cleanup_filter_trials.py} | 0 docs/deployment.md | 2 +- docs/example_deployment/crontab | 2 +- ..._delete_filter_trials.py => test_cleanup_filter_trials.py} | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename castellum/studies/management/commands/{delete_filter_trials.py => cleanup_filter_trials.py} (100%) rename tests/studies/management_commands/{test_delete_filter_trials.py => test_cleanup_filter_trials.py} (72%) diff --git a/castellum/studies/management/commands/delete_filter_trials.py b/castellum/studies/management/commands/cleanup_filter_trials.py similarity index 100% rename from castellum/studies/management/commands/delete_filter_trials.py rename to castellum/studies/management/commands/cleanup_filter_trials.py diff --git a/docs/deployment.md b/docs/deployment.md index e842e3df0..5e5bb0191 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -86,7 +86,7 @@ user requests. We provide the following management commands for that: is sent to the respective study coordinators instead. - `notify_sessions_end`: Remind study members to finish a study when sessions end. -- `delete_filter_trials`: Delete filter trials as they are meant to be +- `cleanup_filter_trials`: Delete filter trials as they are meant to be used only once. ## Initial setup diff --git a/docs/example_deployment/crontab b/docs/example_deployment/crontab index 428e99586..fb8ec0960 100644 --- a/docs/example_deployment/crontab +++ b/docs/example_deployment/crontab @@ -4,5 +4,5 @@ 2 1 * * * django-admin notify_to_be_deleted http://example.com 3 1 * * * django-admin send_appointment_reminders http://example.com 4 1 * * * django-admin notify_sessions_end -5 1 * * * django-admin delete_filter_trials +5 1 * * * django-admin cleanup_filter_trials 6 1 * * 1 django-admin geocode_all diff --git a/tests/studies/management_commands/test_delete_filter_trials.py b/tests/studies/management_commands/test_cleanup_filter_trials.py similarity index 72% rename from tests/studies/management_commands/test_delete_filter_trials.py rename to tests/studies/management_commands/test_cleanup_filter_trials.py index b9d939e1d..41c7b99a6 100644 --- a/tests/studies/management_commands/test_delete_filter_trials.py +++ b/tests/studies/management_commands/test_cleanup_filter_trials.py @@ -1,10 +1,10 @@ from model_bakery import baker -from castellum.studies.management.commands.delete_filter_trials import Command +from castellum.studies.management.commands.cleanup_filter_trials import Command from castellum.studies.models import Study -def test_delete_filter_trial(study): +def test_cleanup_filter_trial(study): baker.make(Study, is_filter_trial=True) cmd = Command() -- GitLab From 162aef55f3245af4c7a0d867b191e34d1125b303 Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 14 Sep 2021 10:29:13 +0200 Subject: [PATCH 2/3] add cleanup_availability --- .../commands/cleanup_availability.py | 36 +++++++++++++++++++ docs/deployment.md | 2 ++ docs/example_deployment/crontab | 1 + 3 files changed, 39 insertions(+) create mode 100644 castellum/subjects/management/commands/cleanup_availability.py diff --git a/castellum/subjects/management/commands/cleanup_availability.py b/castellum/subjects/management/commands/cleanup_availability.py new file mode 100644 index 000000000..4b938f650 --- /dev/null +++ b/castellum/subjects/management/commands/cleanup_availability.py @@ -0,0 +1,36 @@ +# (c) 2018-2021 +# MPIB , +# MPI-CBS , +# MPIP +# +# This file is part of Castellum. +# +# Castellum is free software; you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Castellum is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with Castellum. If not, see +# . + +from django.core.management.base import BaseCommand +from django.utils import timezone + +from castellum.subjects.models import Subject + + +class Command(BaseCommand): + help = 'Remove obsolete "not available until" entries.' + + def handle(self, *args, **options): + now = timezone.now() + subjects = Subject.objects.filter(not_available_until__lt=now) + count = subjects.update(not_available_until=None) + if options['verbosity'] > 0 and count > 0: + self.stdout.write('Cleared {} "not available until" entries'.format(count)) diff --git a/docs/deployment.md b/docs/deployment.md index 5e5bb0191..6a07cfc9d 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -79,6 +79,8 @@ user requests. We provide the following management commands for that: - `clearsessions`: Delete expired sessions. - `cleanup_media`: Delete unused uploaded files. +- `cleanup_availability`: Remove obsolete "not available until" + entries. - `notify_to_be_deleted`: Automatically notify about content that should be deleted. - `send_appointment_reminders`: Send email reminders to subjects with diff --git a/docs/example_deployment/crontab b/docs/example_deployment/crontab index fb8ec0960..99c4b902e 100644 --- a/docs/example_deployment/crontab +++ b/docs/example_deployment/crontab @@ -1,6 +1,7 @@ # min hour day month weekday command 0 1 * * * django-admin clearsessions 1 1 * * * django-admin cleanup_media +1 1 * * * django-admin cleanup_availability 2 1 * * * django-admin notify_to_be_deleted http://example.com 3 1 * * * django-admin send_appointment_reminders http://example.com 4 1 * * * django-admin notify_sessions_end -- GitLab From 61f4b48f8f3829b636145539e21d5d9cb853534d Mon Sep 17 00:00:00 2001 From: Tobias Bengfort Date: Tue, 14 Sep 2021 10:29:39 +0200 Subject: [PATCH 3/3] reorder crontab --- docs/deployment.md | 8 ++++---- docs/example_deployment/crontab | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/deployment.md b/docs/deployment.md index 6a07cfc9d..d17dbaae9 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -81,15 +81,15 @@ user requests. We provide the following management commands for that: - `cleanup_media`: Delete unused uploaded files. - `cleanup_availability`: Remove obsolete "not available until" entries. +- `cleanup_filter_trials`: Delete filter trials as they are meant to be + used only once. - `notify_to_be_deleted`: Automatically notify about content that should be deleted. +- `notify_sessions_end`: Remind study members to finish a study when + sessions end. - `send_appointment_reminders`: Send email reminders to subjects with upcoming appointments. If the subjects have no email address, a note is sent to the respective study coordinators instead. -- `notify_sessions_end`: Remind study members to finish a study when - sessions end. -- `cleanup_filter_trials`: Delete filter trials as they are meant to be - used only once. ## Initial setup diff --git a/docs/example_deployment/crontab b/docs/example_deployment/crontab index 99c4b902e..9ca976c84 100644 --- a/docs/example_deployment/crontab +++ b/docs/example_deployment/crontab @@ -1,9 +1,9 @@ # min hour day month weekday command 0 1 * * * django-admin clearsessions 1 1 * * * django-admin cleanup_media -1 1 * * * django-admin cleanup_availability -2 1 * * * django-admin notify_to_be_deleted http://example.com -3 1 * * * django-admin send_appointment_reminders http://example.com -4 1 * * * django-admin notify_sessions_end -5 1 * * * django-admin cleanup_filter_trials -6 1 * * 1 django-admin geocode_all +2 1 * * * django-admin cleanup_availability +3 1 * * * django-admin cleanup_filter_trials +4 1 * * * django-admin notify_to_be_deleted http://example.com +5 1 * * * django-admin notify_sessions_end +6 1 * * * django-admin send_appointment_reminders http://example.com +7 1 * * 1 django-admin geocode_all -- GitLab