Exemplo n.º 1
0
def patch_email(g):
    SENDGRID_USER = SENDGRID_USERNAME = env_or('SENDGRID_USERNAME', None)
    SENDGRID_PASSWORD = env_or('SENDGRID_PASSWORD', None)

    if SENDGRID_USERNAME and SENDGRID_PASSWORD:
        EMAIL_BACKEND = 'sgbackend.SendGridBackend'
    else:
        EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

    log_setting('EMAIL_BACKEND', EMAIL_BACKEND)

    install_caps(g, locals())
Exemplo n.º 2
0
def patch_cacheops(g):
    REDIS_URL = g.get('REDIS_URL')
    if not REDIS_URL:
        return

    log_setting('CACHEOPS', 'is enabled')

    g['CACHEOPS_REDIS'] = keymap(str.lower, dj_redis_url.parse(REDIS_URL))

    g['INSTALLED_APPS'].append('cacheops')

    g['CACHEOPS_DEGRADE_ON_FAILURE'] = True

    g['CACHEOPS_DEFAULTS'] = {'timeout': IN_SECONDS.FIFTEEN_MINUTES}
    g['CACHEOPS'] = {
        # Automatically cache any User.objects.get() calls for 15 minutes
        # This includes request.user or post.author access,
        # where Post.author is a foreign key to auth.User
        'auth.user': {'ops': 'get'},
        'core.user': {'ops': 'get'},

        # Automatically cache all gets and queryset fetches
        # to other django.contrib.auth models for an hour
        'auth.*': {'ops': ('fetch', 'get'), 'timeout': IN_SECONDS.ONE_HOUR},

        # Cache gets, fetches, counts and exists to Permission
        # 'all' is just an alias for ('get', 'fetch', 'count', 'exists')
        'auth.permission': {'ops': 'all', 'timeout': IN_SECONDS.ONE_HOUR},

        # Basically Never changing objects. Allow local_get (in memory)
        'event.event': {'ops': 'all', 'local_get': True},
        'ticket.tickettype': {'ops': 'all', 'local_get': True},
        'ticket.tickettier': {'ops': 'all', 'local_get': True},
        'ticket.ticketaddontype': {'ops': 'all', 'local_get': False},

        # Enable manual caching on all other models with default timeout of an hour
        # Use Post.objects.cache().get(...)
        #  or Tags.objects.filter(...).order_by(...).cache()
        # to cache particular ORM request.
        # Invalidation is still automatic
        '*.*': {'ops': (), 'timeout': IN_SECONDS.ONE_HOUR},

        # And since ops is empty by default you can rewrite last line as:
        '*.*': {'timeout': IN_SECONDS.ONE_HOUR},
    }