Skip to content

Commit

Permalink
DWPF-770 Add the left DBT functionality back in
Browse files Browse the repository at this point in the history
Co-authored-by: Marcel Kornblum <[email protected]>
  • Loading branch information
CamLamb and marcelkornblum committed Sep 20, 2023
1 parent a54fcfc commit efc9a32
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/peoplefinder/forms/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
self.group_field = group_field


class ProfileLeavingDitForm(forms.Form):
class ProfileLeavingDbtForm(forms.Form):
comment = forms.CharField(
label="My comments",
help_text="for example, leaving date",
Expand Down
14 changes: 14 additions & 0 deletions src/peoplefinder/templates/peoplefinder/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ <h1 class="govuk-heading-l mb-0" data-testid="full-name">{{ profile.full_name }}
{% else %}
<p class="govuk-body-s pf-secondary-colour">Last edited {{ profile.edited_or_confirmed_at|naturalday:"j F Y" }}</p>
{% endif %}

{% if profile.is_active %}
{% if request.user == profile.user %}
<p class="govuk-body-s">
Let us know if you are <a class="govuk-link"
href="{% url 'profile-leaving-dit' profile.slug %}">leaving DBT</a>.
</p>
{% else %}
<p class="govuk-body-s">
Let us know if {{ profile.full_name }} has <a class="govuk-link"
href="{% url 'profile-leaving-dit' profile.slug %}">left DBT</a>.
</p>
{% endif %}
{% endif %}
</div>
</div>

Expand Down
7 changes: 7 additions & 0 deletions src/peoplefinder/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ProfileDeleteView,
ProfileDetailView,
ProfileEditView,
ProfileLeavingDbtView,
ProfileLegacyView,
ProfileUpdateUserView,
get_profile_by_staff_sso_id,
Expand Down Expand Up @@ -101,6 +102,12 @@
ProfileEditView.as_view(),
name="profile-edit-section",
),
# Leaving DBT
path(
"<uuid:profile_slug>/leaving-dbt",
ProfileLeavingDbtView.as_view(),
name="profile-leaving-dit",
),
path(
"<uuid:profile_slug>/delete/",
ProfileDeleteView.as_view(),
Expand Down
81 changes: 58 additions & 23 deletions src/peoplefinder/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
from django.utils.decorators import decorator_from_middleware, method_decorator
from django.views.generic import TemplateView
from django.views.generic.detail import DetailView, SingleObjectMixin
from django.views.generic.edit import UpdateView
from django.views.generic.edit import FormView, UpdateView
from django_hawk.middleware import HawkResponseMiddleware
from django_hawk.utils import DjangoHawkAuthenticationFailed, authenticate_request
from webpack_loader.utils import get_static

from peoplefinder.forms.crispy_helper import RoleFormsetFormHelper
from peoplefinder.forms.profile import ProfileUpdateUserForm
from peoplefinder.forms.profile import ProfileLeavingDbtForm, ProfileUpdateUserForm
from peoplefinder.forms.profile_edit import (
AdminProfileEditForm,
ContactProfileEditForm,
Expand Down Expand Up @@ -66,29 +66,29 @@ def get_queryset(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

profile = context["profile"]
field_statuses = PersonService().profile_completion_field_statuses(profile)
if profile := context.get("profile"):
field_statuses = PersonService().profile_completion_field_statuses(profile)

context.update(
missing_profile_completion_fields=[
(
reverse(
"profile-edit-section",
kwargs={
"profile_slug": profile.slug,
"edit_section": PersonService().get_profile_completion_field_edit_section(
field
),
},
context.update(
missing_profile_completion_fields=[
(
reverse(
"profile-edit-section",
kwargs={
"profile_slug": profile.slug,
"edit_section": PersonService().get_profile_completion_field_edit_section(
field
),
},
)
+ "#"
+ PersonService().get_profile_completion_field_form_id(field),
field.replace("_", " ").capitalize(),
)
+ "#"
+ PersonService().get_profile_completion_field_form_id(field),
field.replace("_", " ").capitalize(),
)
for field, field_status in field_statuses.items()
if not field_status
],
)
for field, field_status in field_statuses.items()
if not field_status
],
)
return context


Expand Down Expand Up @@ -389,6 +389,41 @@ def get_field_locations(self):
return field_locations


class ProfileLeavingDbtView(SuccessMessageMixin, ProfileView, FormView):
template_name = "peoplefinder/profile-leaving-dit.html"
form_class = ProfileLeavingDbtForm

def setup(self, request, *args, **kwargs):
super().setup(request, *args, **kwargs)

self.profile = Person.active.get(slug=self.kwargs["profile_slug"])

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

context["profile"] = self.profile

return context

def form_valid(self, form):
person_service = PersonService()

person_service.left_dit(
request=self.request,
person=self.profile,
reported_by=self.request.user.profile,
comment=form.cleaned_data.get("comment"),
)

return super().form_valid(form)

def get_success_url(self):
return reverse("profile-view", kwargs={"profile_slug": self.profile.slug})

def get_success_message(self, cleaned_data):
return f"A deletion request for {self.profile} has been sent to support"


@method_decorator(transaction.atomic, name="post")
class ProfileDeleteView(SingleObjectMixin, ProfileView):
model = Person
Expand Down

0 comments on commit efc9a32

Please sign in to comment.