Skip to content

Commit

Permalink
Merge pull request #7565 from readthedocs/humitos/context-procesor-no…
Browse files Browse the repository at this point in the history
…tifications

Add our `readthedocs_processor` data to our notifications
  • Loading branch information
humitos authored Oct 22, 2020
2 parents 50f0fd0 + 656862a commit c85171a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion readthedocs/notifications/notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Support for templating of notifications."""

import logging
from readthedocs.core.context_processors import readthedocs_processor

from django.conf import settings
from django.db import models
Expand Down Expand Up @@ -50,14 +51,16 @@ def get_subject(self):
return template.render(context=Context(self.get_context_data()))

def get_context_data(self):
return {
context = {
self.context_object_name: self.object,
'request': self.request,
'production_uri': '{scheme}://{host}'.format(
scheme='https',
host=settings.PRODUCTION_DOMAIN,
),
}
context.update(readthedocs_processor(self.request))
return context

def get_template_names(self, backend_name, source_format=constants.HTML):
names = []
Expand Down
24 changes: 24 additions & 0 deletions readthedocs/rtd_tests/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ class TestNotification(Notification):
'foo': build,
'production_uri': 'https://readthedocs.org',
'request': req,

# readthedocs_processor context
'DASHBOARD_ANALYTICS_CODE': None,
'DO_NOT_TRACK_ENABLED': False,
'GLOBAL_ANALYTICS_CODE': None,
'PRODUCTION_DOMAIN': 'readthedocs.org',
'PUBLIC_DOMAIN': None,
'SITE_ROOT': mock.ANY,
'SUPPORT_EMAIL': None,
'TEMPLATE_ROOT': mock.ANY,
'USE_PROMOS': False,
'USE_SUBDOMAIN': False,
},
)

Expand Down Expand Up @@ -220,6 +232,18 @@ def test_context_data(self):
'request': None,
'production_uri': 'https://readthedocs.org',
'other': {'name': 'other name'},

# readthedocs_processor context
'DASHBOARD_ANALYTICS_CODE': None,
'DO_NOT_TRACK_ENABLED': False,
'GLOBAL_ANALYTICS_CODE': None,
'PRODUCTION_DOMAIN': 'readthedocs.org',
'PUBLIC_DOMAIN': None,
'SITE_ROOT': mock.ANY,
'SUPPORT_EMAIL': None,
'TEMPLATE_ROOT': mock.ANY,
'USE_PROMOS': False,
'USE_SUBDOMAIN': False,
}
self.assertEqual(self.n.get_context_data(), context)

Expand Down

0 comments on commit c85171a

Please sign in to comment.