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

[Emails] Improvements to scheduled emails list and details #2640

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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ node_modules : package.json
## serve : run a server
serve :
gunicorn \
--workers=4 \
--workers=1 \
--bind=127.0.0.1:8000 \
--access-logfile - \
--capture-output \
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rq-scheduler = "~=0.13.0"
social-auth-core = "~=4.1.0"
social-auth-app-django = "~=5.0.0"
gunicorn = "~=22.0.0"
whitenoise = "~=6.1"
whitenoise = "~=6.6"
django-better-admin-arrayfield = "==1.4.2"
django-test-migrations = "~=1.3.0"
typing-extensions = "*"
Expand Down
38 changes: 14 additions & 24 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions amy/emails/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,20 @@ def test_messages_action_scheduled(self, mock_messages_info) -> None:
signal_name = "test_signal"
scheduled_at = timezone.now()
scheduled_email = ScheduledEmail(scheduled_at=scheduled_at)
name = (
scheduled_email.template.name if scheduled_email.template else signal_name
)

# Act
messages_action_scheduled(request, signal_name, scheduled_email)

# Assert
mock_messages_info.assert_called_once_with(
request,
f"New email action ({signal_name}) was scheduled to run "
f"New email action was scheduled to run "
f'<relative-time datetime="{scheduled_at}"></relative-time>: '
f'<a href="{scheduled_email.get_absolute_url()}"><code>'
f"{scheduled_email.pk}</code></a>.",
f"{name}</code></a>.",
extra_tags=settings.ONLY_FOR_ADMINS_TAG,
)

Expand All @@ -209,6 +212,9 @@ def test_messages_action_updated(self, mock_messages_info) -> None:
signal_name = "test_signal"
scheduled_at = timezone.now()
scheduled_email = ScheduledEmail(scheduled_at=scheduled_at)
name = (
scheduled_email.template.name if scheduled_email.template else signal_name
)

# Act
messages_action_updated(request, signal_name, scheduled_email)
Expand All @@ -217,7 +223,7 @@ def test_messages_action_updated(self, mock_messages_info) -> None:
mock_messages_info.assert_called_once_with(
request,
f'Existing <a href="{scheduled_email.get_absolute_url()}">email action '
f"({signal_name})</a> was updated.",
f"({name})</a> was updated.",
extra_tags=settings.ONLY_FOR_ADMINS_TAG,
)

Expand All @@ -230,6 +236,9 @@ def test_messages_action_cancelled(self, mock_messages_warning) -> None:
signal_name = "test_signal"
scheduled_at = timezone.now()
scheduled_email = ScheduledEmail(scheduled_at=scheduled_at)
name = (
scheduled_email.template.name if scheduled_email.template else signal_name
)

# Act
messages_action_cancelled(request, signal_name, scheduled_email)
Expand All @@ -238,7 +247,7 @@ def test_messages_action_cancelled(self, mock_messages_warning) -> None:
mock_messages_warning.assert_called_once_with(
request,
f'Existing <a href="{scheduled_email.get_absolute_url()}">email action '
f"({signal_name})</a> was cancelled.",
f"({name})</a> was cancelled.",
extra_tags=settings.ONLY_FOR_ADMINS_TAG,
)

Expand Down
12 changes: 7 additions & 5 deletions amy/emails/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,16 @@ def messages_missing_template_link(
def messages_action_scheduled(
request: HttpRequest, signal_name: str, scheduled_email: ScheduledEmail
) -> None:
name = scheduled_email.template.name if scheduled_email.template else signal_name
messages.info(
request,
format_html(
"New email action ({}) was scheduled to run "
"New email action was scheduled to run "
'<relative-time datetime="{}"></relative-time>: '
'<a href="{}"><code>{}</code></a>.',
signal_name,
scheduled_email.scheduled_at,
scheduled_email.get_absolute_url(),
scheduled_email.pk,
name,
),
extra_tags=settings.ONLY_FOR_ADMINS_TAG,
)
Expand All @@ -103,12 +103,13 @@ def messages_action_scheduled(
def messages_action_updated(
request: HttpRequest, signal_name: str, scheduled_email: ScheduledEmail
) -> None:
name = scheduled_email.template.name if scheduled_email.template else signal_name
messages.info(
request,
format_html(
'Existing <a href="{}">email action ({})</a> was updated.',
scheduled_email.get_absolute_url(),
signal_name,
name,
),
extra_tags=settings.ONLY_FOR_ADMINS_TAG,
)
Expand All @@ -117,12 +118,13 @@ def messages_action_updated(
def messages_action_cancelled(
request: HttpRequest, signal_name: str, scheduled_email: ScheduledEmail
) -> None:
name = scheduled_email.template.name if scheduled_email.template else signal_name
messages.warning(
request,
format_html(
'Existing <a href="{}">email action ({})</a> was cancelled.',
scheduled_email.get_absolute_url(),
signal_name,
name,
),
extra_tags=settings.ONLY_FOR_ADMINS_TAG,
)
Expand Down
5 changes: 5 additions & 0 deletions amy/recruitment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ def __str__(self) -> str:
f"Instructor Signup applicant {self.person.full_name} "
f"for {self.recruitment.event}"
)

def get_absolute_url(self) -> str:
return reverse(
"instructorrecruitment_details", kwargs={"pk": self.recruitment.pk}
)
32 changes: 16 additions & 16 deletions amy/templates/emails/scheduled_email_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,20 @@ <h1>

<table class="table table-striped">
<tr>
<th width="20%">ID:</th>
<td colspan="2">{{ scheduled_email.id }}</td>
<th>Email template:</th>
<td colspan="2"><a href="{{ scheduled_email.template.get_absolute_url }}">{{ scheduled_email.template }}</a></td>
</tr>
<tr>
<th>Related object:</th>
<td colspan="2">
{% if scheduled_email.generic_relation and scheduled_email.generic_relation.get_absolute_url %}
<a href="{{ scheduled_email.generic_relation.get_absolute_url }}">{{ scheduled_email.generic_relation }}</a>
{% elif scheduled_email.generic_relation %}
{{ scheduled_email.generic_relation }}
{% else %}
&mdash;
{% endif %}
</td>
</tr>
<tr>
<th>State:</th>
Expand Down Expand Up @@ -141,20 +153,8 @@ <h1>
</td>
</tr>
<tr>
<th>Email template:</th>
<td colspan="2"><a href="{{ scheduled_email.template.get_absolute_url }}">{{ scheduled_email.template }}</a></td>
</tr>
<tr>
<th>Related object:</th>
<td colspan="2">
{% if scheduled_email.generic_relation and scheduled_email.generic_relation.get_absolute_url %}
<a href="{{ scheduled_email.generic_relation.get_absolute_url }}">{{ scheduled_email.generic_relation }}</a>
{% elif scheduled_email.generic_relation %}
{{ scheduled_email.generic_relation }}
{% else %}
&mdash;
{% endif %}
</td>
<th width="20%">ID:</th>
<td colspan="2">{{ scheduled_email.id }}</td>
</tr>
</table>

Expand Down
18 changes: 14 additions & 4 deletions amy/templates/emails/scheduled_email_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@
{% if scheduled_emails %}
<table class="table table-striped">
<tr>
<th>ID</th>
<th>Name</th>
<th>State</th>
<th>Scheduled at</th>
<th>Related object</th>
<th>To</th>
<th>From</th>
<th>Subject</th>
<th>Template</th>
</tr>
{% for email in scheduled_emails %}
<tr>
<td><a href="{{ email.get_absolute_url }}">{{ email.id }}</a></td>
<td>
<a href="{{ email.get_absolute_url }}">{{ email.template.name }}</a>
</td>
<td class="text-{% if email.state == 'failed' %}danger{% elif email.state == 'succeeded'%}success{% elif email.state == 'cancelled' %}secondary{% else %}info{% endif %}">{{ email.state }}</td>
<td>{{ email.scheduled_at }}</td>
<td>
{% if email.generic_relation and email.generic_relation.get_absolute_url %}
<a href="{{ email.generic_relation.get_absolute_url }}">{{ email.generic_relation }}</a>
{% elif email.generic_relation %}
{{ email.generic_relation }}
{% else %}
&mdash;
{% endif %}
</td>
<td>
{% if email.to_header %}
<ul>
Expand All @@ -33,7 +44,6 @@
</td>
<td>{{ email.from_header }}</td>
<td>{{ email.subject }}</td>
<td><a href="{{ email.template.get_absolute_url }}">{{ email.template.name }}</a></td>
</tr>
{% endfor %}
</table>
Expand Down
3 changes: 3 additions & 0 deletions amy/workshops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,9 @@ def __str__(self):
self.person, self.badge, self.awarded, self.event
)

def get_absolute_url(self) -> str:
return reverse("person_details", args=[self.person.pk])


# ------------------------------------------------------------

Expand Down
Loading