Skip to content

Commit 485aa16

Browse files
committed
Keep track of which projects are using which theme.
This is primarily used so we can send email to folks using alabaster, and other themes we might want to display ads on. This will allow us to give people fair warning before we put ads on their docs.
1 parent 0039c23 commit 485aa16

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

readthedocs/donate/signals.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import random
2+
import logging
23

34
from django.dispatch import receiver
45
from django.conf import settings
6+
from django.core.cache import cache
7+
8+
import redis
59

610
from readthedocs.restapi.signals import footer_response
711
from readthedocs.donate.models import SupporterPromo
812
from readthedocs.donate.constants import INCLUDE, EXCLUDE
913
from readthedocs.donate.utils import offer_promo
1014

1115

16+
log = logging.getLogger(__name__)
17+
1218
PROMO_GEO_PATH = getattr(settings, 'PROMO_GEO_PATH', None)
1319

1420
if PROMO_GEO_PATH:
@@ -200,3 +206,25 @@ def attach_promo_data(sender, **kwargs):
200206

201207
# Set promo object on return JSON
202208
resp_data['promo'] = show_promo
209+
210+
211+
@receiver(footer_response)
212+
def index_theme_data(sender, **kwargs):
213+
"""
214+
Keep track of which projects are using which theme.
215+
216+
This is primarily used so we can send email to folks using alabaster,
217+
and other themes we might want to display ads on.
218+
This will allow us to give people fair warning before we put ads on their docs.
219+
220+
"""
221+
context = kwargs['context']
222+
223+
project = context['project']
224+
theme = context['theme']
225+
226+
try:
227+
redis_client = cache.get_client(None)
228+
redis_client.sadd("readthedocs:v1:index:themes:%s" % theme, project)
229+
except (AttributeError, redis.exceptions.ConnectionError):
230+
log.warning('Redis theme indexing error: %s', exc_info=True)

0 commit comments

Comments
 (0)