Skip to content

Commit

Permalink
DWPF-703 removes email sending logic, notify package and its dependen…
Browse files Browse the repository at this point in the history
…cies (#24)

removed logic inside form_valid()
removed code inside notify.py
removed notifications-python-client with poetry remove
  • Loading branch information
nicopicchio authored Aug 22, 2023
1 parent 83d5069 commit 4ea28fb
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 284 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,9 @@ You'll need an API key and template ID from the gov.uk Notify service.
CRISPY_ALLOWED_TEMPLATE_PACKS = ["gds"]
CRISPY_TEMPLATE_PACK = "gds"

# Gov Notify
GOVUK_NOTIFY_API_KEY="<your-api-key>"

# Django Feedback GovUK
DJANGO_FEEDBACK_GOVUK = {
"SERVICE_NAME": "<your-service>",
"FEEDBACK_NOTIFICATION_EMAIL_TEMPLATE_ID": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"FEEDBACK_NOTIFICATION_EMAIL_RECIPIENTS": ["[email protected]"],
"COPY": {
#...add any copy tags to override here
},
Expand Down Expand Up @@ -240,3 +235,19 @@ poetry config pypi-token.pypi XXXXXXXX
```

Now the make commands should work as expected.

## Sending automated emails after form submission

Based on the needs of your project you may want to be notified of the feedback received. For example you might want to receive an email if there is new feedback to be reviewed. To do this you can create a method and call it on a regular schedule (e.g. once a day) through cron, Celery Beat, etc.

```
feedback_submitted_past_day = (
BaseFeedback.objects.all().filter(
submitted_at__gte=timezone.now() + timedelta(days=-1),
).exists()
)
if feedback_submitted_past_day:
send_email() # This is not a real method, just an example to show this is where the send email logic would go.
```

This can be achieved through the [GovUK Notify](https://docs.notifications.service.gov.uk/python.html#python-client-documentation) Client.
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
# Generated by Django 3.2.18 on 2023-05-12 05:15

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('django_feedback_govuk', '0001_initial'),
("django_feedback_govuk", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name='feedback',
name='submitter',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
model_name="feedback",
name="submitter",
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
]
11 changes: 6 additions & 5 deletions django_feedback_govuk/migrations/0004_alter_basefeedback_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@


class Migration(migrations.Migration):

dependencies = [
('django_feedback_govuk', '0003_restructure_feedback'),
("django_feedback_govuk", "0003_restructure_feedback"),
]

operations = [
migrations.AlterField(
model_name='basefeedback',
name='id',
field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
model_name="basefeedback",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
]
25 changes: 0 additions & 25 deletions django_feedback_govuk/notify.py

This file was deleted.

4 changes: 0 additions & 4 deletions django_feedback_govuk/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@

DEFAULTS = {
"SERVICE_NAME": "Example service",
"FEEDBACK_NOTIFICATION_EMAIL_TEMPLATE_ID": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"FEEDBACK_NOTIFICATION_EMAIL_RECIPIENTS": [
"[email protected]",
],
"COPY": {
"SUBMIT_TITLE": "Give feedback on {{ service_name }}",
"CONFIRM_TITLE": "Feedback submitted",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
<nav class="govuk-pagination" role="navigation" aria-label="results">
{% if page.has_previous %}
<div class="govuk-pagination__prev">
<a class="govuk-link govuk-pagination__link" href="{% get_pagination_url page.previous_page_number %}" rel="prev">
<svg class="govuk-pagination__icon govuk-pagination__icon--prev" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z"></path>
<a class="govuk-link govuk-pagination__link"
href="{% get_pagination_url page.previous_page_number %}"
rel="prev">
<svg class="govuk-pagination__icon govuk-pagination__icon--prev"
xmlns="http://www.w3.org/2000/svg"
height="13"
width="15"
aria-hidden="true"
focusable="false"
viewBox="0 0 15 13">
<path d="m6.5938-0.0078125-6.7266 6.7266 6.7441 6.4062 1.377-1.449-4.1856-3.9768h12.896v-2h-12.984l4.2931-4.293-1.414-1.414z">
</path>
</svg>
<span class="govuk-pagination__link-title">Previous</span>
</a>
Expand All @@ -15,23 +24,37 @@
{% for num in page|get_elided_page_range %}
{% if num == page.number %}
<li class="govuk-pagination__item govuk-pagination__item--current">
<a class="govuk-link govuk-pagination__link" href="{% get_pagination_url num %}" aria-label="Page {{ num }}" aria-current="page">{{ num }}</a>
<a class="govuk-link govuk-pagination__link"
href="{% get_pagination_url num %}"
aria-label="Page {{ num }}"
aria-current="page">{{ num }}</a>
</li>
{% elif num == page.paginator.ELLIPSIS %}
<li class="govuk-pagination__item govuk-pagination__item--ellipses">&ctdot;</li>
{% else %}
<li class="govuk-pagination__item">
<a class="govuk-link govuk-pagination__link" href="{% get_pagination_url num %}" aria-label="Page {{ num }}">{{ num }}</a>
<a class="govuk-link govuk-pagination__link"
href="{% get_pagination_url num %}"
aria-label="Page {{ num }}">{{ num }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% if page.has_next %}
<div class="govuk-pagination__next">
<a class="govuk-link govuk-pagination__link" href="{% get_pagination_url page.next_page_number %}" rel="next">
<a class="govuk-link govuk-pagination__link"
href="{% get_pagination_url page.next_page_number %}"
rel="next">
<span class="govuk-pagination__link-title">Next</span>
<svg class="govuk-pagination__icon govuk-pagination__icon--next" xmlns="http://www.w3.org/2000/svg" height="13" width="15" aria-hidden="true" focusable="false" viewBox="0 0 15 13">
<path d="m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z"></path>
<svg class="govuk-pagination__icon govuk-pagination__icon--next"
xmlns="http://www.w3.org/2000/svg"
height="13"
width="15"
aria-hidden="true"
focusable="false"
viewBox="0 0 15 13">
<path d="m8.107-0.0078125-1.4136 1.414 4.2926 4.293h-12.986v2h12.896l-4.1855 3.9766 1.377 1.4492 6.7441-6.4062-6.7246-6.7266z">
</path>
</svg>
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

{% load feedback_tags %}
{% feedback_confirm form_id=form_id %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% load l10n crispy_forms_gds %}
<fieldset class="govuk-fieldset"
{% if field.errors %}aria-describedby="{% for error in field.errors %} {{ field.auto_id }}_{{ forloop.counter }}_error{% endfor %}"{% endif %}
{% if field.help_text %}aria-describedby="{{ field.auto_id }}_hint"{% endif %}>
{% if field.errors %}aria-describedby="{% for error in field.errors %} {{ field.auto_id }}_{{ forloop.counter }}_error{% endfor %}
"
{% endif %}
{% if field.help_text %}aria-describedby="{{ field.auto_id }}_hint"{% endif %}>

{% if field.label %}
<legend class="govuk-fieldset__legend{% if legend_size %} {{ legend_size }}{% endif %}">
Expand All @@ -16,15 +18,15 @@
<div class="govuk-radios{% if radios_inline %}--inline{% endif %}{% if radios_small %} govuk-radios--small{% endif %} star-rating3__stars">
{% for choice in field.field.choices %}
<input type="radio"
name="{{ field.html_name }}"
class="star-rating3__input"
id="id_{{ field.html_name }}_{{ forloop.counter }}"
value="{{ choice.0|unlocalize }}"
{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked="checked" {% endif %}
{% if choice.hint %} aria-describedby="id_{{ field.html_name }}_{{ forloop.counter }}_hint"{% endif %} />
name="{{ field.html_name }}"
class="star-rating3__input"
id="id_{{ field.html_name }}_{{ forloop.counter }}"
value="{{ choice.0|unlocalize }}"
{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|stringformat:"s" %} checked="checked" {% endif %}
{% if choice.hint %}aria-describedby="id_{{ field.html_name }}_{{ forloop.counter }}_hint"{% endif %} />
<label class="star-rating3__label"
for="id_{{ field.html_name }}_{{ forloop.counter }}"
aria-label="{{ choice.1|unlocalize }}">
for="id_{{ field.html_name }}_{{ forloop.counter }}"
aria-label="{{ choice.1|unlocalize }}">
<span class="govuk-label text">{{ choice.1|unlocalize }}</span>
</label>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
<div class="govuk-character-count"
data-module="govuk-character-count"
{% if max_characters %} data-maxlength="{{ max_characters }}" {% else %} data-maxwords="{{ max_words }}" {% endif %}
{% if threshold %} data-threshold="{{ threshold }}"{% endif %}>
{% if threshold %}data-threshold="{{ threshold }}"{% endif %}>
{% endif %}

{% if tag %}
<{{ tag }} id="div_{{ field.auto_id }}"
class="govuk-form-group{% if form_show_errors %}{% if field.errors %} govuk-form-group--error{% endif %}{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">
class="govuk-form-group
{% if form_show_errors %}
{% if field.errors %}govuk-form-group--error{% endif %}
{% endif %}
{% if wrapper_class %}{{ wrapper_class }}{% endif %}
{% if field.css_classes %}{{ field.css_classes }}{% endif %}
">

{% include "django_feedback_govuk/widgets/star_rating/radios.html" %}

Expand All @@ -36,4 +42,4 @@
{% endif %}

{% if max_characters or max_words %}</div>{% endif %}
{% endif %}
{% endif %}
11 changes: 0 additions & 11 deletions django_feedback_govuk/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.utils.module_loading import import_string
from django.views.generic import FormView, ListView, TemplateView

from django_feedback_govuk import notify
from django_feedback_govuk.models import BaseFeedback
from django_feedback_govuk.settings import DEFAULT_FEEDBACK_ID, dfg_settings

Expand Down Expand Up @@ -40,16 +39,6 @@ def get_initial(self):

def form_valid(self, form):
form.save()
feedback_listing_path = reverse(
"feedback-listing",
kwargs={"form_id": self.form_id},
)
# Send an email to inform the team of the feedback
notify.email(
personalisation={
"feedback_url": self.request.build_absolute_uri(feedback_listing_path),
},
)
return super().form_valid(form)

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
Expand Down
39 changes: 30 additions & 9 deletions example_project/custom_feedback/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
# Generated by Django 4.1.10 on 2023-08-07 12:55

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('django_feedback_govuk', '0004_alter_basefeedback_id'),
("django_feedback_govuk", "0004_alter_basefeedback_id"),
]

operations = [
migrations.CreateModel(
name='CustomFeedback',
name="CustomFeedback",
fields=[
('basefeedback_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='django_feedback_govuk.basefeedback')),
('satisfaction', models.CharField(choices=[('very_dissatisfied', 'Very dissatisfied'), ('dissatisfied', 'Dissatisfied'), ('neutral', 'Neither satisfied or dissatisfied'), ('satisfied', 'Satisfied'), ('very_satisfied', 'Very satisfied')], max_length=30)),
('comment', models.TextField(blank=True)),
('extra_comments', models.TextField(blank=True)),
(
"basefeedback_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="django_feedback_govuk.basefeedback",
),
),
(
"satisfaction",
models.CharField(
choices=[
("very_dissatisfied", "Very dissatisfied"),
("dissatisfied", "Dissatisfied"),
("neutral", "Neither satisfied or dissatisfied"),
("satisfied", "Satisfied"),
("very_satisfied", "Very satisfied"),
],
max_length=30,
),
),
("comment", models.TextField(blank=True)),
("extra_comments", models.TextField(blank=True)),
],
bases=('django_feedback_govuk.basefeedback',),
bases=("django_feedback_govuk.basefeedback",),
),
]
3 changes: 2 additions & 1 deletion example_project/example/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'example.settings')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

application = get_asgi_application()
12 changes: 6 additions & 6 deletions example_project/example/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
</title>
<link rel="mask-icon"
href='{% static "govuk-frontend/govuk/assets/images/govuk-mask-icon.svg" %}'
color="blue"/>
color="blue" />
<link rel="apple-touch-icon"
sizes="180x180"
href='{% static "govuk-frontend/govuk/images/govuk-apple-touch-icon-180x180.png" %}'/>
href='{% static "govuk-frontend/govuk/images/govuk-apple-touch-icon-180x180.png" %}' />
<link rel="apple-touch-icon"
sizes="167x167"
href='{% static "govuk-frontend/govuk/images/govuk-apple-touch-icon-167x167.png" %}'/>
href='{% static "govuk-frontend/govuk/images/govuk-apple-touch-icon-167x167.png" %}' />
<link rel="apple-touch-icon"
sizes="152x152"
href='{% static "govuk-frontend/govuk/images/govuk-apple-touch-icon-152x152.png" %}'/>
href='{% static "govuk-frontend/govuk/images/govuk-apple-touch-icon-152x152.png" %}' />
<link rel="apple-touch-icon"
href='{% static "govuk-frontend/govuk/images/govuk-apple-touch-icon.png" %}'/>
href='{% static "govuk-frontend/govuk/images/govuk-apple-touch-icon.png" %}' />
<link href="{% static 'css/styles.css' %}" rel="stylesheet" type="text/css" />
<!--[if lt IE 9]>
<script src="/html5-shiv/html5shiv.js"></script>
<![endif]-->
<meta property="og:image"
content="govuk-frontend/govuk/assets/images/govuk-opengraph-image.png"/>
content="govuk-frontend/govuk/assets/images/govuk-opengraph-image.png" />
</head>
<body class="govuk-template__body app-body-class">
<script>
Expand Down
3 changes: 2 additions & 1 deletion example_project/example/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'example.settings')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")

application = get_wsgi_application()
Loading

0 comments on commit 4ea28fb

Please sign in to comment.