diff --git a/castellum/locale/de/LC_MESSAGES/django.po b/castellum/locale/de/LC_MESSAGES/django.po index 907dd2bffdc1764676255afea7f0cf6d367c3f9a..92e7e24752d329912cfea86a138aea811a3448d4 100644 --- a/castellum/locale/de/LC_MESSAGES/django.po +++ b/castellum/locale/de/LC_MESSAGES/django.po @@ -2056,8 +2056,8 @@ msgid "Type" msgstr "Typ" #: castellum/studies/forms.py:114 -msgid "One time invitation" -msgstr "Einmalige Einladung" +msgid "Anonymous invitation" +msgstr "Anonyme Einladung" #: castellum/studies/forms.py:131 msgid "All subjects will be reminded {} days before each appointment." @@ -2263,8 +2263,8 @@ msgid "Excluded studies" msgstr "Ausgeschlossene Studien" #: castellum/studies/models.py:172 -msgid "Is a one time invitation" -msgstr "Ist eine einmalige Einladung" +msgid "Is an anonymous invitation" +msgstr "Ist eine anonyme Einladung" #: castellum/studies/models.py:174 msgid "" @@ -3005,8 +3005,8 @@ msgid "UUID" msgstr "UUID" #: castellum/subjects/models.py:64 -msgid "Does not want to participate in one time invitations" -msgstr "Möchte nicht an einmaligen Einladungen teilnehmen" +msgid "Does not want to participate in anonymous invitations" +msgstr "Möchte nicht an anonymen Einladungen teilnehmen" #: castellum/subjects/models.py:69 msgid "Does not want to participate in the following study types" diff --git a/castellum/recruitment/filter_queries.py b/castellum/recruitment/filter_queries.py index 34d42596d828bfcd69425a4dbd13a05278163e43..86805d52fbe1c375f5ed65cad3f105f0ace47b33 100644 --- a/castellum/recruitment/filter_queries.py +++ b/castellum/recruitment/filter_queries.py @@ -88,8 +88,8 @@ def study_exclusion(study): def study_disinterest(study): """Exclude subjects who are disinterested in this study's study type.""" - if study.is_onetime_invitation: - return models.Q(onetime_invitation_disinterest=False) + if study.is_anonymous_invitation: + return models.Q(anonymous_invitation_disinterest=False) else: return ~models.Q(study_type_disinterest__in=study.study_type.all()) diff --git a/castellum/recruitment/forms.py b/castellum/recruitment/forms.py index 8f906b44871162c23133ff3d6b209d2b59f67d00..33ea48b62d5b5c20d069ecd3b2274a37f75fa6e2 100644 --- a/castellum/recruitment/forms.py +++ b/castellum/recruitment/forms.py @@ -136,7 +136,7 @@ class AttributesForm(forms.ModelForm): class Meta: model = Subject - fields = ['study_type_disinterest', 'onetime_invitation_disinterest'] + fields = ['study_type_disinterest', 'anonymous_invitation_disinterest'] widgets = { 'study_type_disinterest': forms.CheckboxSelectMultiple(), } @@ -154,10 +154,10 @@ class AttributesForm(forms.ModelForm): if key + '_answer_declined' in self.data: cleaned_data[key] = ANSWER_DECLINED study_type_disinterest = cleaned_data.pop('study_type_disinterest') - onetime_invitation_disinterest = cleaned_data.pop('onetime_invitation_disinterest') + anonymous_invitation_disinterest = cleaned_data.pop('anonymous_invitation_disinterest') return { 'study_type_disinterest': study_type_disinterest, - 'onetime_invitation_disinterest': onetime_invitation_disinterest, + 'anonymous_invitation_disinterest': anonymous_invitation_disinterest, 'attributes': cleaned_data, } diff --git a/castellum/recruitment/migrations/0040_change_anonymous_invitation_participation_status.py b/castellum/recruitment/migrations/0040_change_anonymous_invitation_participation_status.py new file mode 100644 index 0000000000000000000000000000000000000000..fde289e0f7a31aae3b31f7d7a88c8541c8dccf92 --- /dev/null +++ b/castellum/recruitment/migrations/0040_change_anonymous_invitation_participation_status.py @@ -0,0 +1,25 @@ +from django.db import migrations + +STUDY_FINISHED = 2 +PARTICIPATION_AWAITING_RESPONSE = 5 + + +def migrate_data(apps, schema_editor): + Study = apps.get_model('studies', 'Study') + + for study in Study.objects.filter(is_anonymous_invitation=True): + if study.status == STUDY_FINISHED: + study.participation_set.all().delete() + else: + study.participation_set.all().update(status=PARTICIPATION_AWAITING_RESPONSE) + + +class Migration(migrations.Migration): + dependencies = [ + ('recruitment', '0039_subject_uuid_foreign_key'), + ('studies', '0046_rename_study_is_onetime_invitation'), + ] + + operations = [ + migrations.RunPython(migrate_data), + ] diff --git a/castellum/recruitment/mixins.py b/castellum/recruitment/mixins.py index 0136e2f5aad3466f7e6e71eaa71d7deecadd601a..ee49a0c4935f76fa0683d51242d321a2b5291e98 100644 --- a/castellum/recruitment/mixins.py +++ b/castellum/recruitment/mixins.py @@ -22,7 +22,6 @@ import datetime import logging import random from typing import List -from typing import Optional from django.conf import settings from django.contrib import messages @@ -183,7 +182,6 @@ class BaseFollowUpFeed(BaseCalendarFeed): class BaseMailRecruitmentView(StudyMixin, PermissionRequiredMixin, FormView): template_name = 'recruitment/mail.html' form_class = SendMailForm - participation_status: Optional[int] = None def personalize_mail_body(self, mail_body, contact): return mail_body.replace('{name}', contact.full_name) @@ -191,12 +189,6 @@ class BaseMailRecruitmentView(StudyMixin, PermissionRequiredMixin, FormView): def create_participations(self, batch_size): subjects = get_recruitable(self.study) - attempts = 0 - if self.participation_status in [ - Participation.NOT_REACHED, Participation.AWAITING_RESPONSE - ]: - attempts = 1 - participations = [] with MailContext('recruitment') as ctx: while len(participations) < batch_size and subjects: @@ -216,8 +208,8 @@ class BaseMailRecruitmentView(StudyMixin, PermissionRequiredMixin, FormView): participations.append(Participation( study=self.study, subject=pick, - status=self.participation_status, - attempts=attempts, + status=Participation.AWAITING_RESPONSE, + attempts=1, )) return participations diff --git a/castellum/recruitment/templates/recruitment/attributes_form.html b/castellum/recruitment/templates/recruitment/attributes_form.html index e85b477c32554f3eaa496939b5e9392ea2c1ef6d..f86204f0db3893fdaffcade60a6f11090ca3df57 100644 --- a/castellum/recruitment/templates/recruitment/attributes_form.html +++ b/castellum/recruitment/templates/recruitment/attributes_form.html @@ -44,7 +44,7 @@ {% endfor %} {% bootstrap_field form.study_type_disinterest %} - {% bootstrap_field form.onetime_invitation_disinterest %} + {% bootstrap_field form.anonymous_invitation_disinterest %}