<commit_before># -*- coding: utf-8 -*-
from django.utils import timezone
from django.conf import settings
from django.contrib.sites.models import get_current_site

from .models import Channel


def channel_context(request):
    """ Channel context processors
    """
    site = get_current_site(request)
    opps_menu = Channel.objects.filter(site=site,
                                       date_available__lte=timezone.now(),
                                       published=True,
                                       show_in_menu=True).order_by('order')

    return {'opps_menu': opps_menu,
            'opps_channel_conf_all': settings.OPPS_CHANNEL_CONF,
            'site': site}
<commit_msg>Add cache in opps menu list via context processors<commit_after># -*- coding: utf-8 -*-
from django.utils import timezone
from django.conf import settings
from django.contrib.sites.models import get_current_site
from django.core.cache import cache

from .models import Channel


def channel_context(request):
    """ Channel context processors
    """
    site = get_current_site(request)
    opps_menu = cache.get('opps_menu')
    if not opps_menu:
        opps_menu = [channel for channel in Channel.objects.filter(
            site=site,
            date_available__lte=timezone.now(),
            published=True,
            show_in_menu=True).distinct().order_by('order')]
        cache.set('opps_menu', opps_menu, settings.OPPS_CACHE_EXPIRE)

    return {'opps_menu': opps_menu,
            'opps_channel_conf_all': settings.OPPS_CHANNEL_CONF,
            'site': site}

{'fraction_non_alphanumeric': 0.09517766497461928, 'fraction_numerical': 0.0012690355329949238, 'mean_word_length': 2.633640552995392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1539957', 'n_tokens_mistral': 453, 'n_tokens_neox': 442, 'n_words': 101}