Skip to content

Commit

Permalink
extended participant edit form for lab managers
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonf committed Oct 29, 2024
1 parent b3fd93d commit 4959f85
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
43 changes: 23 additions & 20 deletions lab/participants/forms.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lab/participants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4959f85

Please sign in to comment.