Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWPF-770 Add the left DBT functionality back in #454

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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