Skip to content

Commit

Permalink
Fix subscription expiry logo - EDLY-3257 (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
taimoor-ahmed-1 authored Jul 27, 2021
1 parent 11bc531 commit 8cfdf8d
Show file tree
Hide file tree
Showing 4 changed files with 237 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import date, timedelta
import logging

from django.contrib.sites.models import Site
from django.core.management.base import BaseCommand
from django.db.models import Q
from edx_ace import ace
Expand All @@ -13,8 +12,10 @@
from openedx.core.djangoapps.ace_common.template_context import get_base_template_context
from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.theming.helpers import get_config_value_from_site_or_settings
from openedx.core.djangoapps.user_api.preferences.api import get_user_preference
from openedx.core.lib.celery.task_utils import emulate_http_request
from openedx.features.edly.context_processor import Colour
from openedx.features.subscriptions.message_types import ExpiredNotification, ImpendingExpiryNotification
from openedx.features.subscriptions.models import UserSubscription
from openedx.features.subscriptions.utils import get_subscription_renew_url
Expand All @@ -35,15 +36,37 @@ def _get_message_context(self, site):
marketing_root_url='' if not marketing_site_root else marketing_site_root
)
message_context['subscriptions_marketing_url'] = subscriptions_marketing_url
color_dict = get_config_value_from_site_or_settings(
'COLORS',
site=site,
)

primary_color = Colour(str(color_dict.get('primary')))

message_context.update({
'edly_fonts_config': get_config_value_from_site_or_settings(
'FONTS',
site=site,
),
'edly_branding_config': get_config_value_from_site_or_settings(
'BRANDING',
site=site,
),
'edly_copyright_text': get_config_value_from_site_or_settings(
'EDLY_COPYRIGHT_TEXT',
site=site,
),
'edly_colors_config': {'primary': primary_color},
})

return message_context

def _send_email_notifications(self, context_values, ace_message_class):
"""
Send email notifications from the given context values.
"""
site = Site.objects.get_current()
message_context = self._get_message_context(site)
for subscription_id, user in context_values:
for subscription_id, user, site in context_values:
message_context = self._get_message_context(site)
if ace_message_class == ExpiredNotification:
subscription_renew_url = get_subscription_renew_url(subscription_id, user)
message_context.update({
Expand Down Expand Up @@ -72,14 +95,16 @@ def handle(self, *args, **options):
Q(expiration_date__isnull=False) & Q(expiration_date=date.today() + timedelta(days=1))
)
impending_expiry_subscriptions_context_values = [
(subscription.subscription_id, subscription.user) for subscription in impending_expiry_subscriptions
(subscription.subscription_id, subscription.user, subscription.site)
for subscription in impending_expiry_subscriptions
]

expired_subscriptions = UserSubscription.objects.filter(
Q(expiration_date__isnull=False) & Q(expiration_date=date.today() - timedelta(days=1))
)
expired_subscriptions_context_values = [
(subscription.subscription_id, subscription.user) for subscription in expired_subscriptions
(subscription.subscription_id, subscription.user, subscription.site)
for subscription in expired_subscriptions
]

self._send_email_notifications(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{% load i18n %}
{% load ace %}

{% get_current_language as LANGUAGE_CODE %}
{% get_current_language_bidi as LANGUAGE_BIDI %}

{# This is preview text that is visible in the inbox view of many email clients but not visible in the actual #}
{# email itself. #}

<div lang="{{ LANGUAGE_CODE|default:"en" }}" style="
display:none;
font-size:1px;
line-height:1px;
max-height:0px;
max-width:0px;
opacity:0;
overflow:hidden;
visibility:hidden;
">
{% block preview_text %}{% endblock %}
</div>

{% for image_src in channel.tracker_image_sources %}
<img src="{image_src}" alt="" role="presentation" aria-hidden="true" />
{% endfor %}

{% google_analytics_tracking_pixel %}

<div lang="{{ LANGUAGE_CODE|default:"en" }}" dir="{{ LANGUAGE_BIDI|yesno:"rtl,ltr" }}" style="
background-color: #f5f5f5;
margin: 0;
min-width: 100%;
padding-bottom: 30px;
padding-top: 30px;
">
<!-- Hack for outlook 2010, which wants to render everything in Times New Roman -->
<!--[if mso]>
<style type="text/css">
body, table, td {font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif !important;}
</style>
<![endif]-->

<!--[if (gte mso 9)|(IE)]>
<table role="presentation" width="600" align="center" cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<![endif]-->

<!-- CONTENT -->
<table class="content" role="presentation" align="center" cellpadding="0" cellspacing="0" border="0" width="100%" style="
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 1.5;
max-width: 600px;
padding: 0 20px 0 20px;
">
<tr>
<!-- HEADER -->
<td class="header" style="
padding: 20px 30px;
">
<table role="presentation" width="100%" align="left" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="70">
<a href="{% with_link_tracking homepage_url %}">
<img
src="{{ edly_branding_config.logo }}"
alt="{% blocktrans %}Go to {{ platform_name }} Home Page{% endblocktrans %}"
width="200"
/>
</a>
</td>
<td align="right" style="text-align: {{ LANGUAGE_BIDI|yesno:"left,right" }}; padding-bottom: 6px;">
<a class="login" href="{% with_link_tracking dashboard_url %}" style="color: {{ edly_colors_config.primary }}; text-decoration: none;">
{% trans "Sign In" %}
</a>
</td>
</tr>
</table>
</td>
</tr>

<tr>
<!-- MAIN -->
<td class="main" bgcolor="#ffffff" style="
padding: 30px 30px 40px;
box-shadow: 0 1px 5px rgba(0,0,0,0.25);
">
{% block content %}{% endblock %}
</td>
</tr>

<tr>
<!-- FOOTER -->
<td class="footer" style="padding: 20px; text-align: center;">
<table role="presentation" width="100%" align="left" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<!-- SOCIAL -->
<table role="presentation" align="{{ LANGUAGE_BIDI|yesno:"right,left" }}" border="0" border="0" cellpadding="0" cellspacing="0" width="210">
<tr>
{% if social_media_urls.linkedin %}
<td height="32" width="42">
<a href="{{ social_media_urls.linkedin|safe }}">
<img src="https://media.sailthru.com/595/1k1/8/o/599f354ec70cb.png"
width="32" height="32" alt="{% blocktrans %}{{ platform_name }} on LinkedIn{% endblocktrans %}"/>
</a>
</td>
{% endif %}
{% if social_media_urls.twitter %}
<td height="32" width="42">
<a href="{{ social_media_urls.twitter|safe }}">
<img src="https://media.sailthru.com/595/1k1/8/o/599f354d9c26e.png"
width="32" height="32" alt="{% blocktrans %}{{ platform_name }} on Twitter{% endblocktrans %}"/>
</a>
</td>
{% endif %}
{% if social_media_urls.facebook %}
<td height="32" width="42">
<a href="{{ social_media_urls.facebook|safe }}">
<img src="https://media.sailthru.com/595/1k1/8/o/599f355052c8e.png"
width="32" height="32" alt="{% blocktrans %}{{ platform_name }} on Facebook{% endblocktrans %}"/>
</a>
</td>
{% endif %}
{% if social_media_urls.google_plus %}
<td height="32" width="42">
<a href="{{ social_media_urls.google_plus|safe }}">
<img src="https://media.sailthru.com/595/1k1/8/o/599f354fc554a.png"
width="32" height="32" alt="{% blocktrans %}{{ platform_name }} on Google Plus{% endblocktrans %}"/>
</a>
</td>
{% endif %}
{% if social_media_urls.reddit %}
<td height="32" width="42">
<a href="{{ social_media_urls.reddit|safe }}">
<img src="https://media.sailthru.com/595/1k1/8/o/599f354e326b9.png"
width="32" height="32" alt="{% blocktrans %}{{ platform_name }} on Reddit{% endblocktrans %}"/>
</a>
</td>
{% endif %}
</tr>
</table>
</td>
</tr>
<tr>
<!-- APP BUTTONS -->
<td>
{% if mobile_store_urls.apple %}
<a href="{{ mobile_store_urls.apple|safe }}" style="text-decoration: none">
<img src="https://media.sailthru.com/595/1k1/6/2/5931cfbba391b.png"
alt="{% trans "Download the iOS app on the Apple Store" %}"
width="136" height="50" style="margin-{{ LANGUAGE_BIDI|yesno:"left,right" }}: 10px"/>
</a>
{% endif %}
{% if mobile_store_urls.google %}
<a href="{{ mobile_store_urls.google|safe }}" style="text-decoration: none">
<img src="https://media.sailthru.com/595/1k1/6/2/5931cf879a033.png"
alt="{% trans "Download the Android app on the Google Play Store" %}"
width="136" height="50"/>
</a>
{% endif %}
</td>
</tr>
<tr>
<!-- Actions -->
<td>
{% for action_link_url, action_link_text in channel.action_links %}
<p style="padding-bottom: 20px;">
<a href="{{ action_link_url }}" style="color: #960909">
<font color="#960909"><b>{{ action_link_text }}</b></font>
</a>
</p>
{% endfor %}
</td>
</tr>
<tr>
<!-- COPYRIGHT -->
<td style="color: #666666; font-size: 13px; line-height: 26px;">
{% if edly_copyright_text %}
{{ edly_copyright_text }}
{% else %}
&copy; {{ platform_name }} {% now "Y" %}. {% trans "All rights reserved" %}.
{% endif %}
<br/>
{% trans "Our mailing address is" %}: {{ contact_mailing_address }}
</td>
</tr>
</table>
</td>
</tr>
</table>

<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->

</div>

{# Debug info that is not user-visible #}
<span id="ace-message-id" style="display:none;">{{ message.log_id }}</span>
<span id="template-revision" style="display:none;">{{ template_revision }}</span>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'ace_common/edx_ace/common/base_body.html' %}
{% extends 'subscriptions/edx_ace/common/base_body.html' %}

{% load i18n %}
{% load static %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends 'ace_common/edx_ace/common/base_body.html' %}
{% extends 'subscriptions/edx_ace/common/base_body.html' %}

{% load i18n %}
{% load static %}
Expand Down

0 comments on commit 8cfdf8d

Please sign in to comment.