From 98896766adbf0ed2ff203eab0ee86ac21014927a Mon Sep 17 00:00:00 2001 From: Robyn Marowitz Date: Thu, 17 Aug 2023 17:24:42 -0600 Subject: [PATCH] Add role dropdown to profile page --- usaon_vta_survey/forms.py | 7 ++----- usaon_vta_survey/models/tables.py | 1 + usaon_vta_survey/templates/macros/forms/user_profile.j2 | 6 +++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/usaon_vta_survey/forms.py b/usaon_vta_survey/forms.py index 528d2e0b..a76a19ca 100644 --- a/usaon_vta_survey/forms.py +++ b/usaon_vta_survey/forms.py @@ -56,9 +56,8 @@ def conv_String(self, field_args, **extra): FORMS_BY_MODEL: dict[BaseModel, Form] = { User: model_form( User, - only=['orcid', 'biography', 'affiliation', 'role_id'], - # Allows foreign key to be included in form. - exclude_fk=False, + only=['orcid', 'biography', 'affiliation', 'role'], + field_args={'role': {'get_label': 'id'}}, ), Survey: model_form(Survey, only=['title', 'notes']), # Response entities ("nodes" from Sankey diagram perspective) @@ -87,8 +86,6 @@ def conv_String(self, field_args, **extra): ResponseSocietalBenefitArea: model_form( ResponseSocietalBenefitArea, only=['societal_benefit_area'], - exclude_fk=False, - # field_args={'get_label': 'id' }, field_args={'societal_benefit_area': {'get_label': 'id'}}, ), # Response relationships ("edges" from Sankey diagram perspective) diff --git a/usaon_vta_survey/models/tables.py b/usaon_vta_survey/models/tables.py index cea1bca7..fa913a86 100644 --- a/usaon_vta_survey/models/tables.py +++ b/usaon_vta_survey/models/tables.py @@ -94,6 +94,7 @@ class User(BaseModel, UserMixin): String, nullable=True, ) + role = relationship('Role') class Survey(BaseModel): diff --git a/usaon_vta_survey/templates/macros/forms/user_profile.j2 b/usaon_vta_survey/templates/macros/forms/user_profile.j2 index bae3cc18..b1256ee1 100644 --- a/usaon_vta_survey/templates/macros/forms/user_profile.j2 +++ b/usaon_vta_survey/templates/macros/forms/user_profile.j2 @@ -31,10 +31,10 @@ {% endif %}

- {{form.role_id.label}} {{form.role_id(size=50)}} - {% if form.role_id.errors %} + {{form.role.label}} {{form.role}} + {% if form.role.errors %}