diff --git a/src/peoplefinder/forms/profile.py b/src/peoplefinder/forms/profile.py
index 7392a8420..21b2f19d1 100644
--- a/src/peoplefinder/forms/profile.py
+++ b/src/peoplefinder/forms/profile.py
@@ -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",
diff --git a/src/peoplefinder/templates/peoplefinder/profile.html b/src/peoplefinder/templates/peoplefinder/profile.html
index a5bc2114a..b554c5d2c 100644
--- a/src/peoplefinder/templates/peoplefinder/profile.html
+++ b/src/peoplefinder/templates/peoplefinder/profile.html
@@ -121,6 +121,20 @@
{{ profile.full_name }}
{% else %}
Last edited {{ profile.edited_or_confirmed_at|naturalday:"j F Y" }}
{% endif %}
+
+ {% if profile.is_active %}
+ {% if request.user == profile.user %}
+
+ Let us know if you are leaving DBT.
+
+ {% else %}
+
+ Let us know if {{ profile.full_name }} has left DBT.
+
+ {% endif %}
+ {% endif %}
diff --git a/src/peoplefinder/urls.py b/src/peoplefinder/urls.py
index d22d823b7..dc488aca1 100644
--- a/src/peoplefinder/urls.py
+++ b/src/peoplefinder/urls.py
@@ -19,6 +19,7 @@
ProfileDeleteView,
ProfileDetailView,
ProfileEditView,
+ ProfileLeavingDbtView,
ProfileLegacyView,
ProfileUpdateUserView,
get_profile_by_staff_sso_id,
@@ -101,6 +102,12 @@
ProfileEditView.as_view(),
name="profile-edit-section",
),
+ # Leaving DBT
+ path(
+ "/leaving-dbt",
+ ProfileLeavingDbtView.as_view(),
+ name="profile-leaving-dit",
+ ),
path(
"/delete/",
ProfileDeleteView.as_view(),
diff --git a/src/peoplefinder/views/profile.py b/src/peoplefinder/views/profile.py
index 34adbfdd1..f51e6f893 100644
--- a/src/peoplefinder/views/profile.py
+++ b/src/peoplefinder/views/profile.py
@@ -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,
@@ -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
@@ -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