Skip to content

Commit

Permalink
Have the weekly email preview reflect the lab selection on the dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMadBug committed Sep 5, 2023
1 parent a3b9770 commit d07e529
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
{% if not dlab.lab_id %}
{% labelled row_css="my-4" label="Email Preview" admin_only=True %}
<div class="link-toolbar">
<a class="download-link type-csv" href="{% url 'summary_email_html' %}">HTML</a>
<a class="download-link type-json" href="{% url 'summary_email_text' %}">TEXT</a>
<a class="download-link type-csv" href="{% url 'summary_email_html' %}/{{ dlab.lab_picker.selection }}">HTML</a>
<a class="download-link type-json" href="{% url 'summary_email_text' %}/{{ dlab.lab_picker.selection }}">TEXT</a>
</div>
{% endlabelled %}
{% endif %}
Expand Down
3 changes: 2 additions & 1 deletion classification/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@
perm_path('evidence_keys', views.evidence_keys, name='evidence_keys'),

perm_path('summary_email', summary_email_preview_html, name='summary_email_html'),
perm_path('summary_email/<str:lab_id>', summary_email_preview_html, name='summary_email_html'),
perm_path('summary_email_text', summary_email_preview_text, name='summary_email_text'),

perm_path('summary_email_text/<str:lab_id>', summary_email_preview_text, name='summary_email_html'),

perm_path('dashboard', classification_dashboard_view.classification_dashboard, name='classification_dashboard'),
perm_path('dashboard/<str:lab_id>', classification_dashboard_view.classification_dashboard, name='classification_dashboard'),
Expand Down
40 changes: 15 additions & 25 deletions classification/views/classification_email_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,9 @@ def imported_30_days_count(self):

class EmailSummaryData:

def __init__(self, user: User):
self.user = user
# labs
labs_qs: QuerySet
if user.is_superuser:
labs_qs = Lab.objects
else:
labs_qs = Lab.valid_labs_qs(user)

labs_qs = labs_qs.order_by('group_name')
self.lab_summaries: List[EmailLabSummaryData] = [EmailLabSummaryData(lab=lab, user=user) for lab in labs_qs]

@property
def has_issues(self) -> bool:
for lab_summary in self.lab_summaries:
if lab_summary.flagged_variants_count > 0:
return True
return False
def __init__(self, perspective: LabPickerData):
labs = sorted(perspective.selected_labs)
self.lab_summaries: List[EmailLabSummaryData] = [EmailLabSummaryData(lab=lab, user=perspective.user) for lab in labs]


@celery.shared_task
Expand All @@ -144,7 +129,7 @@ def send_summary_emails():
def send_summary_email_to_user(user: User):
discordance_email = settings.DISCORDANCE_EMAIL
if discordance_email:
content = summary_email_content(user)
content = summary_email_content(LabPickerData.for_user(user))

return EmailLog.send_mail(subject=content.subject,
html=content.html,
Expand All @@ -153,16 +138,21 @@ def send_summary_email_to_user(user: User):
recipient_list=[user.email])


def summary_email_preview_html(request: HttpRequest) -> HttpResponse:
return HttpResponse(summary_email_content(request.user).html)
def summary_email_preview_html(request: HttpRequest, lab_id: Optional[str] = None) -> HttpResponse:
return HttpResponse(
summary_email_content(LabPickerData.for_user(request.user, selection=lab_id)).html
)


def summary_email_preview_text(request: HttpRequest) -> HttpResponse:
return HttpResponse(summary_email_content(request.user).text, content_type="text/plain")
def summary_email_preview_text(request: HttpRequest, lab_id: Optional[str] = None) -> HttpResponse:
return HttpResponse(
summary_email_content(LabPickerData.for_user(request.user, selection=lab_id)).text,
content_type="text/plain"
)


def summary_email_content(user: User) -> EmailOutput:
data = EmailSummaryData(user=user)
def summary_email_content(perspective: LabPickerData) -> EmailOutput:
data = EmailSummaryData(perspective=perspective)
subject = 'Weekly Classification Summary'

context = {
Expand Down

0 comments on commit d07e529

Please sign in to comment.