Skip to content

Commit

Permalink
Merge pull request #2636 from carpentries/feature/2622-list-related-s…
Browse files Browse the repository at this point in the history
…cheduled-emails

[#2622] List related scheduled emails
  • Loading branch information
pbanaszkiewicz committed Apr 17, 2024
2 parents d2a03d0 + d280424 commit 5f0a4aa
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 3 deletions.
17 changes: 16 additions & 1 deletion amy/emails/templatetags/emails.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from django import template
from django.contrib.contenttypes.models import ContentType
from django.db.models import Model, QuerySet

from emails.models import ScheduledEmailStatus, ScheduledEmailStatusActions
from emails.models import (
ScheduledEmail,
ScheduledEmailStatus,
ScheduledEmailStatusActions,
)

register = template.Library()

Expand All @@ -12,3 +18,12 @@ def allowed_actions_for_status(status: ScheduledEmailStatus) -> list[str]:
for key, statuses in ScheduledEmailStatusActions.items()
if status in statuses
]


@register.simple_tag
def get_related_scheduled_emails(obj: Model) -> QuerySet[ScheduledEmail]:
content_type = ContentType.objects.get_for_model(obj.__class__)
return ScheduledEmail.objects.filter(
generic_relation_content_type=content_type,
generic_relation_pk=obj.pk,
).order_by("-created_at")
6 changes: 6 additions & 0 deletions amy/templates/fiscal/membership.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@
</tr>
<tr><th>Emergency contact:</th>
<td colspan="2">{% if membership.emergency_contact %}<pre>{{ membership.emergency_contact }}</pre>{% else %}&mdash;{% endif %}</td></tr>
<tr>
<th>Related scheduled emails:</th>
<td>
{% include "includes/related_scheduled_emails.html" with object=membership %}
</td>
</tr>
</table>

<div class="clearfix">
Expand Down
6 changes: 6 additions & 0 deletions amy/templates/includes/event_details_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@
{% endif %}
{% endwith %}
</td></tr>
<tr>
<th>Related scheduled emails:</th>
<td>
{% include "includes/related_scheduled_emails.html" with object=event %}
</td>
</tr>
</table>
6 changes: 5 additions & 1 deletion amy/templates/includes/instructorrecruitment.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
></i>
</th>
<th>Action</th>
<th>Related scheduled emails</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -88,10 +89,13 @@
</form>
<a href="{% url 'instructorrecruitmentsignup_edit' signup.pk %}" class="btn btn-sm btn-primary">Edit</a>
</td>
<td>
{% include "includes/related_scheduled_emails.html" with object=signup %}
</td>
</tr>
{% empty %}
<tr>
<td colspan=9><em>No applications yet.</em></td>
<td colspan=11><em>No applications yet.</em></td>
</tr>
{% endfor %}
</tbody>
Expand Down
12 changes: 12 additions & 0 deletions amy/templates/includes/related_scheduled_emails.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% load emails %}

{% get_related_scheduled_emails object as related_scheduled_emails %}
{% 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>
{% endfor %}
</ul>
{% else %}
No related scheduled emails.
{% endif %}
10 changes: 10 additions & 0 deletions amy/templates/includes/related_scheduled_emails_no_empty_msg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% load emails %}

{% get_related_scheduled_emails object as related_scheduled_emails %}
{% 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>
{% endfor %}
</ul>
{% endif %}
4 changes: 4 additions & 0 deletions amy/templates/recruitment/instructorrecruitment_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ <h4 class="mt-4">
<td><i class="fas fa-user-cog"></i></td>
<td>{% if object.assigned_to %}Assigned to: <a href="{{ object.assigned_to.get_absolute_url }}">{{ object.assigned_to.full_name }}</a>{% else %}Unassigned{% endif %}</td>
</tr>
<tr>
<td></td>
<td><a href="{{ object.get_absolute_url }}">See details</a></td>
</tr>
</table>
</p>
<div class="card recruitment-notes">
Expand Down
18 changes: 18 additions & 0 deletions amy/templates/workshops/person.html
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,24 @@
{% endwith %}
</td>
</tr>
<tr>
<th>Related scheduled emails:</th>
<td>
{% include "includes/related_scheduled_emails.html" with object=person %}
</td>
</tr>
<tr>
<th>Related scheduled emails for awards:</th>
<td>
{% with awards=person.award_set.all %}
{% for award in awards %}
{% include "includes/related_scheduled_emails_no_empty_msg.html" with object=award %}
{% empty%}
&mdash;
{% endfor %}
{% endwith %}
</td>
</tr>
</table>

<div class="edit-object">
Expand Down
2 changes: 1 addition & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
),
AMY_SITE_BANNER=(str, "local"), # should be "local", "testing", or "production"
# Feature flags
AMY_INSTRUCTOR_RECRUITMENT_ENABLED=(bool, False),
AMY_INSTRUCTOR_RECRUITMENT_ENABLED=(bool, True),
)

# OS environment variables take precedence over variables from .env
Expand Down

0 comments on commit 5f0a4aa

Please sign in to comment.