def widget(context, widget_name, template_name=None, cache_enabled=False,
           cache_timeout=None, cache_key=None, cache_key_prefix=None,
           vary_on_headers=None, vary_on_cookies=None, active=True,
           vary_on_sessions=None, **kwargs):
    if not active:
        return ''
    f = registry.get(widget_name)
    if not f:
        logger.warn('Widget "%s" not found' % widget_name)
        return ''
    request = context.get('request')
    assert request, """You need to add 'django.core.context_processors.request'
    in your TEMPLATE_CONTEXT_PROCESSORS settings.
    """
    output = None
    if cache_enabled:
        md5 = hashlib.md5()
        md5.update(cache_key_prefix or '')
        md5.update(cache_key or widget_name)
        md5.update(template_name or '')
        if vary_on_headers:
            for header in vary_on_headers:
                header_value = request.META.get(header)
                if header_value:
                    md5.update(header_value)
        if vary_on_cookies:
            for cookie in vary_on_cookies:
                cookie_value = request.COOKIES.get(cookie)
                if cookie_value:
                    md5.update(cookie_value)
        if vary_on_sessions:
            if hasattr(request, 'session'):
                for session in vary_on_sessions:
                    session_value = request.session.get(session)
                    if session_value:
                        md5.update(session_value)
        cache_key = md5.hexdigest()
        output = cache.get(cache_key)
        if output:
            logger.debug('"%s" is got from cache' % widget_name)

    if not output:
        context_data, _template_name = f(context, **kwargs)
        if not template_name:
            template_name = 'cms/widgets/%s.html' % (_template_name or
                                                     widget_name)
        context_data.update({'request': request})
        output = render_to_string(template_name, context_data)
        if cache_enabled:
            logger.debug('"%s" is put into cache' % widget_name)
            cache.set(cache_key, output, cache_timeout)
    return output
dataset/ETHPy150Open metglobal/django-easy-cms/easy_cms/templatetags/cms.py/widget/original