|
1 | 1 | import random
|
| 2 | +import logging |
2 | 3 |
|
3 | 4 | from django.dispatch import receiver
|
4 | 5 | from django.conf import settings
|
| 6 | +from django.core.cache import cache |
| 7 | + |
| 8 | +import redis |
5 | 9 |
|
6 | 10 | from readthedocs.restapi.signals import footer_response
|
7 | 11 | from readthedocs.donate.models import SupporterPromo
|
8 | 12 | from readthedocs.donate.constants import INCLUDE, EXCLUDE
|
9 | 13 | from readthedocs.donate.utils import offer_promo
|
10 | 14 |
|
11 | 15 |
|
| 16 | +log = logging.getLogger(__name__) |
| 17 | + |
12 | 18 | PROMO_GEO_PATH = getattr(settings, 'PROMO_GEO_PATH', None)
|
13 | 19 |
|
14 | 20 | if PROMO_GEO_PATH:
|
@@ -200,3 +206,25 @@ def attach_promo_data(sender, **kwargs):
|
200 | 206 |
|
201 | 207 | # Set promo object on return JSON
|
202 | 208 | 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