Skip to content
Snippets Groups Projects

Fixes issue #222 in which the voucher partner and health partner shown the option to select a role

Merged Fixes issue #222 in which the voucher partner and health partner shown the option to select a role
1 unresolved thread
Merged Carlos Vega requested to merge fix/222_voucher_partner_role_option into master
1 unresolved thread
Files
3
@@ -9,7 +9,7 @@ from django_common.auth_backends import User
from web.models import Worker, WorkerStudyRole
from web.models.constants import GLOBAL_STUDY_ID
from web.models.worker import role_choices_by_worker_type, worker_type_by_worker
from web.models.worker_study_role import WORKER_STAFF, WORKER_VOUCHER_PARTNER
from web.models.worker_study_role import WORKER_STAFF, WORKER_VOUCHER_PARTNER, WORKER_HEALTH_PARTNER
logger = logging.getLogger(__name__)
@@ -33,7 +33,18 @@ class WorkerForm(ModelForm):
initial_role = roles[0].role
choices = role_choices_by_worker_type(worker_type)
self.fields['role'] = forms.ChoiceField(label='Role', choices=choices)
if worker_type in [WORKER_VOUCHER_PARTNER, WORKER_HEALTH_PARTNER]:
'''
Since ChoiceField expects tuples (id, label), for a *custom* HiddenInput field we need to create a charfield with TextInput widget
providing the value of the *id*. hidden_form_field CSS class is defined in templates/doctors/add.html and has display:none property.
'''
if initial_role is None:
initial_role = choices[0][0] # get 1st element of 1st tuple (('VOUCHER_PARTNER', 'Voucher Partner'),)
self.fields['role'] = forms.CharField(label='Role', widget=forms.TextInput(attrs={'class': 'hidden_form_field'}), disabled=True)
else:
self.fields['role'] = forms.ChoiceField(label='Role', choices=choices)
self.fields['role'].initial = initial_role
del self.fields['user']
Loading