Skip to content

Commit

Permalink
DST-884 - Licensing - Add optional question for contacting user to H-…
Browse files Browse the repository at this point in the history
…CSAT forms (#158)

* DST-884 - Licensing - Add optional question for contacting user to H-CSAT forms

* fixing tests
  • Loading branch information
chris-pettinga authored Dec 19, 2024
1 parent 27e3ce9 commit bac9567
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 128 deletions.
6 changes: 3 additions & 3 deletions django_app/apply_for_a_licence/choices.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
class BaseChoices(models.TextChoices):
@classmethod
def active_choices(cls):
return [choice for choice in cls.choices if choice[0] not in cls.deactive_choices()]
return [choice for choice in cls.choices if choice[0] not in cls.inactive_choices()]

@classmethod
def deactive_choices(cls):
def inactive_choices(cls):
pass


Expand Down Expand Up @@ -79,7 +79,7 @@ class ProfessionalOrBusinessServicesChoices(models.TextChoices):

class LicensingGroundsChoices(BaseChoices):
@classmethod
def deactive_choices(cls) -> List[str]:
def inactive_choices(cls) -> List[str]:
return ["parent_or_subsidiary_company"]

civil_society = (
Expand Down
9 changes: 8 additions & 1 deletion django_app/feedback/choices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import List

from apply_for_a_licence.choices import BaseChoices
from django.db import models


Expand All @@ -9,7 +12,11 @@ class RatingChoices(models.IntegerChoices):
VERY_SATISFIED = 5, "Very satisfied"


class DidYouExperienceAnyIssues(models.TextChoices):
class DidYouExperienceAnyIssues(BaseChoices):
@classmethod
def inactive_choices(cls) -> List[str]:
return ["no"]

NO = "no", "I did not experience any issues"
NOT_FOUND = "not_found", "I did not find what I was looking for"
DIFFICULT = "difficult", "I found it difficult to navigate"
Expand Down
10 changes: 8 additions & 2 deletions django_app/feedback/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class FeedbackForm(BaseModelForm):
submit_button_text = "Submit"

did_you_experience_any_issues = forms.MultipleChoiceField(
choices=DidYouExperienceAnyIssues.choices,
choices=DidYouExperienceAnyIssues.active_choices(),
widget=forms.CheckboxSelectMultiple,
label="Did you experience any of the following issues?",
required=False,
)

class Meta:
model = FeedbackItem
fields = ("rating", "did_you_experience_any_issues", "how_we_could_improve_the_service")
fields = ("rating", "did_you_experience_any_issues", "how_we_could_improve_the_service", "user_name", "user_email")
labels = {
"how_we_could_improve_the_service": "How could we improve the service?",
"rating": "Overall, how satisfied did you feel with using this service?",
Expand Down Expand Up @@ -61,5 +61,11 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
),
css_class="optional_question",
),
Fieldset(
HTMLTemplate("feedback/participate_in_user_research.html"),
Field.text("user_name", label_size=Size.SMALL),
Field.text("user_email", label_size=Size.SMALL),
css_class="optional_question",
),
HTMLTemplate("feedback/feedback_disclaimer.html"),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.16 on 2024-12-19 09:43

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("feedback", "0002_feedbackitem_url_historicalfeedbackitem_url"),
]

operations = [
migrations.AddField(
model_name="feedbackitem",
name="user_email",
field=models.EmailField(blank=True, max_length=254, null=True),
),
migrations.AddField(
model_name="feedbackitem",
name="user_name",
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name="historicalfeedbackitem",
name="user_email",
field=models.EmailField(blank=True, max_length=254, null=True),
),
migrations.AddField(
model_name="historicalfeedbackitem",
name="user_name",
field=models.CharField(blank=True, max_length=255, null=True),
),
]
2 changes: 2 additions & 0 deletions django_app/feedback/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class FeedbackItem(BaseModel):
)
how_we_could_improve_the_service = models.TextField(null=True, blank=True)
url = models.URLField(null=True, blank=True)
user_name = models.CharField(max_length=255, null=True, blank=True)
user_email = models.EmailField(null=True, blank=True)

def get_did_you_experience_any_issues_display(self) -> str:
display_list = []
Expand Down
2 changes: 2 additions & 0 deletions django_app/feedback/static/feedback/javascript/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ $(window).bind("pageshow", function(event) {
$('.optional_question').hide()
}
})

$("input[name='rating']:checked").trigger("change")
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2 class="govuk-heading-m">Participating in further research</h2>
<p class="govuk-body">We're always improving our services and would like your help to make this one better. If you're happy for us to contact you about participating in further research, please leave your name and email address.</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% extends "core/base.html" %}
{% block cookie_banner %}{% endblock cookie_banner %}
{% block title %}View Feedback for apply sanctioned services licence{% endblock title %}
{% block back_button %}{% endblock back_button %}
{% block column_content %}
<div>
<h1 class="govuk-heading-l">
View feedback on the apply for a sanctioned services licence service
</h1>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">
</div>
<form method="get" action="{% url 'view_a_licence:view_all_feedback' %}" id="filter_form">
{% csrf_token %}
<div class="govuk-form-group">
<label class="govuk-label" >Created at date minimum (inclusive)</label>
<input type="date" class="govuk-form" id="created_at_min" name="date_min">
</div>
<div class="govuk-form-group">
<label class="govuk-label">Created at date maximum (inclusive)</label>
<input type="date" class="form-control" id="created_at_min" name="date_max">
</div>
<button type="submit" class="btn btn-primary">Filter</button>

</form>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">

<h3 class="govuk-heading-s govuk-!-margin-bottom-2">
<table class="govuk-table govuk-table--small-text-until-tablet">
<caption class="govuk-table__caption govuk-table__caption--m">Feedback</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header"> ID </th>
<th scope="col" class="govuk-table__header">Created at</th>
<th scope="col" class="govuk-table__header">Modified at </th>
<th scope="col" class="govuk-table__header">Rating</th>
<th scope="col" class="govuk-table__header">Did you experience any issues? </th>
<th scope="col" class="govuk-table__header">How could we improve the service? </th>
<th scope="col" class="govuk-table__header">URL </th>
<th scope="col" class="govuk-table__header">Agreed to feedback </th>
</tr>
</thead>
<tbody class="govuk-table__body">
{% for feedback_item in object_list %}
<tr class="govuk-table__row">
<td class="govuk-table__cell"><a href="{% url 'view_a_licence:view_feedback' pk=feedback_item.id %}">{{ feedback_item.id }}</a></td>
<td class="govuk-table__cell">{{ feedback_item.created_at }}</td>
<td class="govuk-table__cell">{{ feedback_item.modified_at }}</td>
<td class="govuk-table__cell">{{ feedback_item.get_rating_display}} </td>
<td class="govuk-table__cell">{{ feedback_item.get_did_you_experience_any_issues_display | linebreaksbr }}</td>
<td class="govuk-table__cell">{{ feedback_item.how_we_could_improve_the_service }}</td>
<td class="govuk-table__cell">{{ feedback_item.url }}</td>
<td class="govuk-table__cell">{% if feedback_item.user_name or feedback_item.user_email %}Yes{% else %}No{% endif %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock column_content %}

{% block extra_js %}
{{ block.super }}
<script type="text/javascript" nonce="{{ request.csp_nonce }}">
$(document).ready(function () {
$('body').on('click', '.read_more_button', function () {
$(this).closest('.text_truncator').find('.truncated_text').addClass('hidden');
$(this).closest('.text_truncator').find('.expanded_text').removeClass('hidden');
});
$('body').on('click', '.read_less_button', function () {
$(this).closest('.text_truncator').find('.truncated_text').removeClass('hidden');
$(this).closest('.text_truncator').find('.expanded_text').addClass('hidden');
})
})
</script>
{% endblock extra_js %}
105 changes: 35 additions & 70 deletions django_app/view_a_licence/templates/view_a_licence/view_feedback.html
Original file line number Diff line number Diff line change
@@ -1,74 +1,39 @@
{% extends "core/base.html" %}
{% block cookie_banner %}{% endblock cookie_banner %}
{% block title %}View Feedback for apply sanctioned services licence{% endblock title %}
{% block back_button %}{% endblock back_button %}
{% block column_content %}
<div>
<h1 class="govuk-heading-l">
View feedback on the apply for a sanctioned services licence service
</h1>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">
</div>
<form method="get" action="{% url 'view_a_licence:view_feedback' %}" id="filter_form">
{% csrf_token %}
<div class="govuk-form-group">
<label class="govuk-label" >Created at date minimum (inclusive)</label>
<input type="date" class="govuk-form" id="created_at_min" name="date_min">
</div>
<div class="govuk-form-group">
<label class="govuk-label">Created at date maximum (inclusive)</label>
<input type="date" class="form-control" id="created_at_min" name="date_max">
</div>
<button type="submit" class="btn btn-primary">Filter</button>

</form>
<hr class="govuk-section-break govuk-section-break--m govuk-section-break--visible">

<h3 class="govuk-heading-s govuk-!-margin-bottom-2">
<table class="govuk-table govuk-table--small-text-until-tablet">
<caption class="govuk-table__caption govuk-table__caption--m">Feedback</caption>
<thead class="govuk-table__head">
<tr class="govuk-table__row">

<th scope="col" class="govuk-table__header"> ID </th>
<th scope="col" class="govuk-table__header">Created at</th>
<th scope="col" class="govuk-table__header">Modified at </th>
<th scope="col" class="govuk-table__header">Rating</th>
<th scope="col" class="govuk-table__header">Did you experience any issues? </th>
<th scope="col" class="govuk-table__header">How could we improve the service? </th>
<th scope="col" class="govuk-table__header">URL </th>
</tr>
{% block title %}View individual feedback{% endblock title %}

</thead>
<tbody class="govuk-table__body">

{% for feedback_item in object_list %}
<tr class="govuk-table__row">
<td class="govuk-table__cell">{{ feedback_item.id }}</td>
<td class="govuk-table__cell">{{ feedback_item.created_at }}</td>
<td class="govuk-table__cell">{{ feedback_item.modified_at }}</td>
<td class="govuk-table__cell">{{ feedback_item.get_rating_display}} </td>
<td class="govuk-table__cell">{{ feedback_item.get_did_you_experience_any_issues_display | linebreaksbr }}</td>
<td class="govuk-table__cell">{{ feedback_item.how_we_could_improve_the_service }}</td>
<td class="govuk-table__cell">{{ feedback_item.url }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% block column_content %}
<table class="govuk-table">
<caption class="govuk-table__caption govuk-table__caption--m">Feedback item - {{ feedback.id }}</caption>
<tbody class="govuk-table__body">
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Created at</th>
<td class="govuk-table__cell">{{ feedback.created_at }}</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Rating</th>
<td class="govuk-table__cell">{{ feedback.get_rating_display}}</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Issues</th>
<td class="govuk-table__cell">{{ feedback.get_did_you_experience_any_issues_display | linebreaksbr }}</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Improvements</th>
<td class="govuk-table__cell">{{ feedback.how_we_could_improve_the_service }}</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">URL</th>
<td class="govuk-table__cell">{{ feedback.url }}</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">User name</th>
<td class="govuk-table__cell">{{ feedback.user_name }}</td>
</tr>
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">User email</th>
<td class="govuk-table__cell">{{ feedback.user_email }}</td>
</tr>
</tbody>
</table>
{% endblock column_content %}

{% block extra_js %}
{{ block.super }}
<script type="text/javascript" nonce="{{ request.csp_nonce }}">
$(document).ready(function () {
$('body').on('click', '.read_more_button', function () {
$(this).closest('.text_truncator').find('.truncated_text').addClass('hidden');
$(this).closest('.text_truncator').find('.expanded_text').removeClass('hidden');
});
$('body').on('click', '.read_less_button', function () {
$(this).closest('.text_truncator').find('.truncated_text').removeClass('hidden');
$(this).closest('.text_truncator').find('.expanded_text').addClass('hidden');
})
})
</script>
{% endblock extra_js %}
3 changes: 2 additions & 1 deletion django_app/view_a_licence/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
path("view-all-applications", views.ApplicationListView.as_view(), name="application_list"),
path("view-application/<str:reference>/", views.ViewALicenceApplicationView.as_view(), name="view_application"),
path("manage-users/", views.ManageUsersView.as_view(), name="manage_users"),
path("view-feedback/", views.ViewFeedbackView.as_view(), name="view_feedback"),
path("view-all-feedback/", views.ViewAllFeedbackView.as_view(), name="view_all_feedback"),
path("view-feedback/<int:pk>", views.ViewFeedbackView.as_view(), name="view_feedback"),
]
12 changes: 10 additions & 2 deletions django_app/view_a_licence/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

logger = logging.getLogger(__name__)


# ALL VIEWS HERE MUST BE DECORATED WITH AT LEAST LoginRequiredMixin


Expand Down Expand Up @@ -109,10 +110,10 @@ def get_context_data(self, **kwargs: object) -> dict[str, Any]:


@method_decorator(require_view_a_licence(), name="dispatch")
class ViewFeedbackView(LoginRequiredMixin, ActiveUserRequiredMixin, ListView):
class ViewAllFeedbackView(LoginRequiredMixin, ActiveUserRequiredMixin, ListView):
context_object_name = "feedback"
model = FeedbackItem
template_name = "view_a_licence/view_feedback.html"
template_name = "view_a_licence/view_all_feedback.html"

def get_queryset(self) -> "QuerySet[FeedbackItem]":
queryset = super().get_queryset()
Expand All @@ -121,3 +122,10 @@ def get_queryset(self) -> "QuerySet[FeedbackItem]":
if date_max := self.request.GET.get("date_max"):
queryset = queryset.filter(created_at__date__lte=date_max)
return queryset


@method_decorator(require_view_a_licence(), name="dispatch")
class ViewFeedbackView(LoginRequiredMixin, ActiveUserRequiredMixin, DetailView):
model = FeedbackItem
template_name = "view_a_licence/view_feedback.html"
context_object_name = "feedback"
Loading

0 comments on commit bac9567

Please sign in to comment.