From ce83de532279eb21f92b9bb8b50f047dddcd4b28 Mon Sep 17 00:00:00 2001 From: Cameron Lamb Date: Mon, 21 Aug 2023 10:25:11 +0100 Subject: [PATCH] Add details component back into the skills section of the edit form --- src/peoplefinder/forms/profile_edit.py | 181 ++++++++++++------ .../templates/gds/layout/details.html | 1 + src/peoplefinder/views/profile.py | 8 +- 3 files changed, 130 insertions(+), 60 deletions(-) create mode 100644 src/peoplefinder/templates/gds/layout/details.html diff --git a/src/peoplefinder/forms/profile_edit.py b/src/peoplefinder/forms/profile_edit.py index d05464872..c7a35f39f 100644 --- a/src/peoplefinder/forms/profile_edit.py +++ b/src/peoplefinder/forms/profile_edit.py @@ -1,14 +1,56 @@ +from crispy_forms.layout import LayoutObject +from crispy_forms.utils import TEMPLATE_PACK from crispy_forms_gds.helper import FormHelper from crispy_forms_gds.layout import HTML, Field, Fieldset, Layout, Size, Submit from django import forms from django.core.validators import ValidationError from django.template import Context, Template +from django.template.loader import render_to_string from peoplefinder.forms.profile import GovUkRadioSelect, GroupedModelChoiceField from peoplefinder.forms.role import RoleForm from peoplefinder.models import Person, UkStaffLocation +class GovUKDetails(LayoutObject): + template = "%s/layout/details.html" + + def __init__(self, *fields, summary=None, **kwargs): + pre_fields_html_str = """ +
+ """ + if summary: + pre_fields_html_str += f""" + + + {summary} + + + """ + pre_fields_html_str += """ +
+ """ + pre_fields_html = HTML(pre_fields_html_str) + post_fields_html = HTML("
") + self.fields = [pre_fields_html] + list(fields) + [post_fields_html] + + def render( + self, + form, + form_style, + context, + template_pack=TEMPLATE_PACK, + extra_context=None, + **kwargs, + ): + fields = self.get_rendered_fields( + form, form_style, context, template_pack, **kwargs + ) + + template = self.get_template_name(template_pack) + return render_to_string(template, {"fields": fields}) + + class PersonalProfileEditForm(forms.ModelForm): class Meta: model = Person @@ -226,17 +268,17 @@ def __init__(self, *args, **kwargs): legend_size=Size.MEDIUM, legend="Who is your line manager?", ), - Fieldset( - HTML( - Template( - "{% include 'peoplefinder/components/teams-and-roles.html' %}" - ).render( - Context({"profile": person, "role_forms": role_forms}), - ) - ), - legend_size=Size.MEDIUM, - legend="Team and role", - ), + # Fieldset( + # HTML( + # Template( + # "{% include 'peoplefinder/components/teams-and-roles.html' %}" + # ).render( + # Context({"profile": person, "role_forms": role_forms}), + # ) + # ), + # legend_size=Size.MEDIUM, + # legend="Team and role", + # ), Submit("submit", "Save section"), ) @@ -413,60 +455,81 @@ def __init__(self, *args, **kwargs): self.helper = FormHelper() self.helper.layout = Layout( - Fieldset( - "key_skills", - legend_size=Size.MEDIUM, - legend=key_skills_label, - ), - Fieldset( - "other_key_skills", - legend_size=Size.MEDIUM, - legend=other_key_skills_label, - ), - Fieldset( - "fluent_languages", - legend_size=Size.MEDIUM, - legend=fluent_languages_label, - ), - Fieldset( - "intermediate_languages", - legend_size=Size.MEDIUM, - legend=intermediate_languages_label, - ), - Fieldset( - "learning_interests", - legend_size=Size.MEDIUM, - legend=learning_interests_label, + GovUKDetails( + Fieldset( + "key_skills", + legend_size=Size.MEDIUM, + legend=key_skills_label, + ), + Fieldset( + "other_key_skills", + legend_size=Size.MEDIUM, + legend=other_key_skills_label, + ), + summary="Add skills", ), - Fieldset( - "other_learning_interests", - legend_size=Size.MEDIUM, - legend=other_learning_interests_label, + GovUKDetails( + Fieldset( + "fluent_languages", + legend_size=Size.MEDIUM, + legend=fluent_languages_label, + ), + Fieldset( + "intermediate_languages", + legend_size=Size.MEDIUM, + legend=intermediate_languages_label, + ), + summary="Add languages", ), - Fieldset( - "networks", - legend_size=Size.MEDIUM, - legend=networks_label, + GovUKDetails( + Fieldset( + "learning_interests", + legend_size=Size.MEDIUM, + legend=learning_interests_label, + ), + Fieldset( + "other_learning_interests", + legend_size=Size.MEDIUM, + legend=other_learning_interests_label, + ), + summary="Add learning and development interests", ), - Fieldset( - "professions", - legend_size=Size.MEDIUM, - legend=professions_label, + GovUKDetails( + Fieldset( + "networks", + legend_size=Size.MEDIUM, + legend=networks_label, + ), + summary="Add networks I belong to", ), - Fieldset( - "additional_roles", - legend_size=Size.MEDIUM, - legend=additional_roles_label, + GovUKDetails( + Fieldset( + "professions", + legend_size=Size.MEDIUM, + legend=professions_label, + ), + summary="Add professions I belong to", ), - Fieldset( - "other_additional_roles", - legend_size=Size.MEDIUM, - legend=other_additional_roles_label, + GovUKDetails( + Fieldset( + "additional_roles", + legend_size=Size.MEDIUM, + legend=additional_roles_label, + ), + Fieldset( + "other_additional_roles", + legend_size=Size.MEDIUM, + legend=other_additional_roles_label, + ), + summary="Add additional roles and responsibilities", ), - Fieldset( - "previous_experience", - legend_size=Size.MEDIUM, - legend=previous_experience_label, + GovUKDetails( + Fieldset( + "previous_experience", + legend_size=Size.MEDIUM, + legend=previous_experience_label, + ), + summary="Add previous experience", ), Submit("submit", "Save section"), ) diff --git a/src/peoplefinder/templates/gds/layout/details.html b/src/peoplefinder/templates/gds/layout/details.html new file mode 100644 index 000000000..dfdb86c8c --- /dev/null +++ b/src/peoplefinder/templates/gds/layout/details.html @@ -0,0 +1 @@ +{{ fields|safe }} diff --git a/src/peoplefinder/views/profile.py b/src/peoplefinder/views/profile.py index cbfaf5393..82f3c8fc0 100644 --- a/src/peoplefinder/views/profile.py +++ b/src/peoplefinder/views/profile.py @@ -151,7 +151,13 @@ def dispatch(self, request: HttpRequest, *args: Any, **kwargs: Any) -> HttpRespo return super().dispatch(request, *args, **kwargs) def get_success_url(self): - return reverse("profile-edit", kwargs={"profile_slug": self.object.slug}) + return reverse( + "profile-edit-section", + kwargs={ + "profile_slug": self.object.slug, + "edit_section": self.edit_section.value, + }, + ) def get_form_kwargs(self): kwargs = super().get_form_kwargs()