Skip to content

Commit

Permalink
Add details component back into the skills section of the edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
CamLamb committed Aug 21, 2023
1 parent 8d0515a commit ce83de5
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 60 deletions.
181 changes: 122 additions & 59 deletions src/peoplefinder/forms/profile_edit.py
Original file line number Diff line number Diff line change
@@ -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 = """
<details class="govuk-details" data-module="govuk-details">
"""
if summary:
pre_fields_html_str += f"""
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
{summary}
</span>
</summary>
"""
pre_fields_html_str += """
<div class="govuk-details__text">
"""
pre_fields_html = HTML(pre_fields_html_str)
post_fields_html = HTML("</div></details>")
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
Expand Down Expand Up @@ -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"),
)

Expand Down Expand Up @@ -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"),
)
Expand Down
1 change: 1 addition & 0 deletions src/peoplefinder/templates/gds/layout/details.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ fields|safe }}
8 changes: 7 additions & 1 deletion src/peoplefinder/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ce83de5

Please sign in to comment.