Skip to content

Commit

Permalink
Merge pull request #2676 from carpentries/feature/2675-ui-improvement…
Browse files Browse the repository at this point in the history
…s-for-emails

[Emails] UI improvements for emails
  • Loading branch information
pbanaszkiewicz authored Jul 16, 2024
2 parents 7e6b002 + 337854e commit ee82a60
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
56 changes: 56 additions & 0 deletions amy/emails/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import django_filters

from emails.models import EmailTemplate, ScheduledEmail
from workshops.filters import AMYFilterSet


class EmailTemplateFilter(AMYFilterSet):
name = django_filters.CharFilter(lookup_expr="icontains")
signal = django_filters.CharFilter(lookup_expr="icontains")
from_header = django_filters.CharFilter(lookup_expr="icontains")
subject = django_filters.CharFilter(lookup_expr="icontains")
body = django_filters.CharFilter(lookup_expr="icontains")

order_by = django_filters.OrderingFilter(
fields=(
"name",
"signal",
),
)

class Meta:
model = EmailTemplate
fields = [
"name",
"active",
"signal",
"from_header",
"subject",
"body",
]


class ScheduledEmailFilter(AMYFilterSet):
name = django_filters.CharFilter(
field_name="template__name",
lookup_expr="icontains",
label="Name",
)
subject = django_filters.CharFilter(lookup_expr="icontains")

order_by = django_filters.OrderingFilter(
fields=(
"template__name",
"state",
"scheduled_at",
"subject",
),
)

class Meta:
model = ScheduledEmail
fields = [
"name",
"state",
"subject",
]
3 changes: 3 additions & 0 deletions amy/emails/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from markdownx.utils import markdownify

from emails.controller import EmailController
from emails.filters import EmailTemplateFilter, ScheduledEmailFilter
from emails.forms import (
EmailTemplateCreateForm,
EmailTemplateUpdateForm,
Expand Down Expand Up @@ -42,6 +43,7 @@ class AllEmailTemplates(OnlyForAdminsMixin, FlaggedViewMixin, AMYListView):
template_name = "emails/email_template_list.html"
queryset = EmailTemplate.objects.order_by("name")
title = "Email templates"
filter_class = EmailTemplateFilter


class EmailTemplateDetails(OnlyForAdminsMixin, FlaggedViewMixin, AMYDetailView):
Expand Down Expand Up @@ -123,6 +125,7 @@ class AllScheduledEmails(OnlyForAdminsMixin, FlaggedViewMixin, AMYListView):
template_name = "emails/scheduled_email_list.html"
queryset = ScheduledEmail.objects.select_related("template").order_by("-created_at")
title = "Scheduled emails"
filter_class = ScheduledEmailFilter


class ScheduledEmailDetails(OnlyForAdminsMixin, FlaggedViewMixin, AMYDetailView):
Expand Down
2 changes: 1 addition & 1 deletion amy/templates/emails/email_template_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base_nav.html" %}
{% extends "base_nav_sidebar.html" %}

{% load pagination %}
{% load tags %}
Expand Down
2 changes: 1 addition & 1 deletion amy/templates/emails/scheduled_email_list.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base_nav.html" %}
{% extends "base_nav_sidebar.html" %}

{% load pagination %}
{% load tags %}
Expand Down
2 changes: 1 addition & 1 deletion amy/templates/includes/related_scheduled_emails.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% if related_scheduled_emails %}
<ul>
{% for email in related_scheduled_emails %}
<li><a href="{{ email.get_absolute_url }}">{{ email.subject }} | {{ email.pk }} | {{ email.get_state_display }}</a></li>
<li><a href="{{ email.get_absolute_url }}">{{ email.template.name }}</a></li>
{% endfor %}
</ul>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% if related_scheduled_emails %}
<ul>
{% for email in related_scheduled_emails %}
<li><a href="{{ email.get_absolute_url }}">{{ email.subject }} | {{ email.pk }} | {{ email.get_state_display }}</a></li>
<li><a href="{{ email.get_absolute_url }}">{{ email.template.name }}</a></li>
{% endfor %}
</ul>
{% endif %}

0 comments on commit ee82a60

Please sign in to comment.