From 6907b6c5bdfbfb40c22259630837c6d3d583360b Mon Sep 17 00:00:00 2001 From: shankar ambady Date: Mon, 22 Jul 2024 12:20:30 -0400 Subject: [PATCH 01/25] adding resource type --- learning_resources_search/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/learning_resources_search/tasks.py b/learning_resources_search/tasks.py index 1d94d7b935..341e52305a 100644 --- a/learning_resources_search/tasks.py +++ b/learning_resources_search/tasks.py @@ -183,6 +183,7 @@ def _get_percolated_rows(resources, subscription_type): { "resource_url": resource.url, "resource_title": resource.title, + "resource_type": resource.resource_type, "user_id": user, "group": _infer_percolate_group(query), "search_url": _infer_search_url(query), @@ -209,7 +210,6 @@ def send_subscription_emails(self, subscription_type, period="daily"): ) rows = _get_percolated_rows(new_learning_resources, subscription_type) template_data = _group_percolated_rows(rows) - email_tasks = celery.group( [ attempt_send_digest_email_batch.si(user_template_items) From 8d9c398a89b1a104741912f1157e8a437ca8e554 Mon Sep 17 00:00:00 2001 From: shankar ambady Date: Mon, 22 Jul 2024 12:59:26 -0400 Subject: [PATCH 02/25] conditionalizing subject line --- learning_resources_search/tasks.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/learning_resources_search/tasks.py b/learning_resources_search/tasks.py index 341e52305a..db8c73a210 100644 --- a/learning_resources_search/tasks.py +++ b/learning_resources_search/tasks.py @@ -816,6 +816,16 @@ def finish_recreate_index(results, backing_indices): log.info("recreate_index has finished successfully!") +def _generate_subscription_digest_subject(total_count, unique_resource_types): + if len(unique_resource_types) == 1: + return ( + f"{total_count} New" + " {unique_resource_types.pop()}{pluralize(total_count)} from MIT" + ) + else: + return f"{total_count} New courses & learning materials from MIT" + + @app.task( acks_late=True, reject_on_worker_lost=True, @@ -825,8 +835,17 @@ def attempt_send_digest_email_batch(user_template_items): for user_id, template_data in user_template_items: log.info("Sending email to user %s", user_id) user = User.objects.get(id=user_id) - total_count = sum([len(template_data[group]) for group in template_data]) - subject = f"{settings.MITOPEN_TITLE} New Learning Resources for You" + total_count = 0 + unique_resource_types = set() + for group in template_data: + total_count += len(template_data[group]) + unique_resource_types.update( + [resource["resource_type"] for resource in template_data[group]] + ) + + subject = _generate_subscription_digest_subject( + total_count, unique_resource_types + ) send_template_email( [user.email], subject, From c0661d65fa30a72c77996eb21b55f3a39711c106 Mon Sep 17 00:00:00 2001 From: shankar ambady Date: Mon, 22 Jul 2024 13:44:42 -0400 Subject: [PATCH 03/25] limiting list of resources to 5 --- main/templates/email/subscribed_channel_digest.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/templates/email/subscribed_channel_digest.html b/main/templates/email/subscribed_channel_digest.html index 5c25c7bd08..7d98d1d07b 100644 --- a/main/templates/email/subscribed_channel_digest.html +++ b/main/templates/email/subscribed_channel_digest.html @@ -69,7 +69,7 @@ -{% for item in items %} +{% for item in items|slice:":5" %} From 20937dc14d3d693f5970be080b41e74ab1854e28 Mon Sep 17 00:00:00 2001 From: shankar ambady Date: Mon, 22 Jul 2024 13:59:55 -0400 Subject: [PATCH 04/25] adding images to email --- learning_resources_search/tasks.py | 1 + .../email/subscribed_channel_digest.html | 24 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/learning_resources_search/tasks.py b/learning_resources_search/tasks.py index db8c73a210..85b1dc68c2 100644 --- a/learning_resources_search/tasks.py +++ b/learning_resources_search/tasks.py @@ -183,6 +183,7 @@ def _get_percolated_rows(resources, subscription_type): { "resource_url": resource.url, "resource_title": resource.title, + "resource_image_url": resource.image.url, "resource_type": resource.resource_type, "user_id": user, "group": _infer_percolate_group(query), diff --git a/main/templates/email/subscribed_channel_digest.html b/main/templates/email/subscribed_channel_digest.html index 7d98d1d07b..b80b494461 100644 --- a/main/templates/email/subscribed_channel_digest.html +++ b/main/templates/email/subscribed_channel_digest.html @@ -24,10 +24,7 @@ font-weight: bold; " > - {{total_count}} - new course{{ total_count|pluralize:'s' }} - in MIT Open that match{{ total_count|pluralize:'es,' }} - your preferences + {{subject}} @@ -60,7 +57,7 @@ font-weight: bold; " > - {{resource_group}} + Results for "{{resource_group}}" @@ -82,6 +79,23 @@ width="100%" > + + {{item.resource_title}} + Date: Tue, 23 Jul 2024 10:37:57 -0400 Subject: [PATCH 06/25] template style fixes --- .../email/subscribed_channel_digest.html | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/main/templates/email/subscribed_channel_digest.html b/main/templates/email/subscribed_channel_digest.html index b80b494461..8c86b11a52 100644 --- a/main/templates/email/subscribed_channel_digest.html +++ b/main/templates/email/subscribed_channel_digest.html @@ -48,17 +48,17 @@ color: #555555; " > -

Results for "{{resource_group}}" -

+ @@ -79,7 +79,7 @@ width="100%" > - + - - {{item.resource_title|safe}} - + {{item.resource_title|safe}} + + View + {{item.resource_type}} +

+ + + + + +
+ {% block footer %} + If you don't want to receive these emails in the future, you can + edit your settings + or + unsubscribe.

+ + {% endblock %} + {% block footer-address %} + MIT Open Learning • 600 Technology Square, + NE49-2000 • Cambridge, MA + 02139 • USA + {% endblock %} +
+ -