diff --git a/lab/participants/forms.py b/lab/participants/forms.py index 5f7bfea4..2cb3ddc3 100644 --- a/lab/participants/forms.py +++ b/lab/participants/forms.py @@ -1,8 +1,4 @@ -from cdh.core.forms import ( - BootstrapCheckboxInput, - BootstrapRadioSelect, - TemplatedModelForm, -) +from cdh.core.forms import BootstrapCheckboxInput, TemplatedModelForm from django import forms from .models import ExtraData, ParticipantData @@ -11,33 +7,40 @@ class ParticipantForm(TemplatedModelForm): show_valid_fields = False + class Meta: + model = ParticipantData + exclude = [] + widgets = { + "name": forms.TextInput, + "phonenumber": forms.TextInput, + "phonenumber_alt": forms.TextInput, + "parent_first_name": forms.TextInput, + "parent_last_name": forms.TextInput, + "save_longer": BootstrapCheckboxInput, + "email_subscription": BootstrapCheckboxInput, + "english_contact": BootstrapCheckboxInput, + } + + +class LeaderParticipantForm(TemplatedModelForm): + show_valid_fields = False + class Meta: model = ParticipantData # note: this form intentionally does not include the more sensitive fields, # because it's also less likely that an experiment leader would have to edit those - fields = [ - "name", - "email", - "birth_date", - "languages", - "phonenumber", - "phonenumber_alt", - "sex", - "email_subscription", - "english_contact", - ] + exclude = ["pregnancy_duration", "birth_weight", "dyslexic_parent", "tos_parent", "save_longer"] widgets = { "name": forms.TextInput, "phonenumber": forms.TextInput, "phonenumber_alt": forms.TextInput, - "sex": BootstrapRadioSelect, + "parent_first_name": forms.TextInput, + "parent_last_name": forms.TextInput, + "save_longer": BootstrapCheckboxInput, "email_subscription": BootstrapCheckboxInput, "english_contact": BootstrapCheckboxInput, } - def __init__(self, *args, **kwargs): - super(ParticipantForm, self).__init__(*args, **kwargs) - class ExtraDataForm(TemplatedModelForm): show_valid_fields = False diff --git a/lab/participants/views.py b/lab/participants/views.py index 7fb5b6b7..232e6939 100644 --- a/lab/participants/views.py +++ b/lab/participants/views.py @@ -22,7 +22,7 @@ RandomLeaderMixin, ) -from .forms import ExtraDataForm, ParticipantForm +from .forms import ExtraDataForm, ParticipantForm, LeaderParticipantForm from .models import ExtraData, Participant, ParticipantData from .permissions import can_leader_access_participant, participants_visible_to_leader @@ -91,7 +91,11 @@ class ParticipantUpdateView(RandomLeaderMixin, SuccessMessageMixin, generic.Upda model = ParticipantData template_name = "participants/edit.html" success_message = _("participants:messages:updated_participant") - form_class = ParticipantForm + + def get_form_class(self): + if self.request.user.is_staff: + return ParticipantForm + return LeaderParticipantForm def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs)