コード例 #1
0
def _show_placeholder_attr_for_page(context,
                                    placeholder_name,
                                    plugin_class_name,
                                    plugin_attr,
                                    page_lookup,
                                    lang=None,
                                    site=None,
                                    cache_result=True):

    validate_placeholder_name(placeholder_name)

    request = context.get('request', False)
    site_id = get_site_id(site)

    if not request:
        return {'content': ''}
    if lang is None:
        lang = get_language_from_request(request)

    if cache_result:
        base_key = _get_cache_key('_show_placeholder_for_page', page_lookup,
                                  lang, site_id)

        cache_key = _clean_key('%s_placeholder:%s' %
                               (base_key, placeholder_name)
                               ) + plugin_class_name + '.' + plugin_attr

        cached_value = cache.get(cache_key)
        if isinstance(cached_value, dict):  # new style
            _restore_sekizai(context, cached_value['sekizai'])
            return {'content': mark_safe(cached_value['content'])}
        elif isinstance(cached_value, string_types):  # old style
            return {'content': mark_safe(cached_value)}

    page = _get_page_by_untyped_arg(page_lookup, request, site_id)
    if not page:
        return {'content': ''}
    watcher = Watcher(context)

    placeholder = _get_placeholder(page, page, context, placeholder_name)
    content = get_placholder_attr(placeholder, placeholder_name,
                                  plugin_class_name, plugin_attr)

    changes = watcher.get_changes()

    if cache_result:
        cache.set(cache_key, {
            'content': content,
            'sekizai': changes
        },
                  get_cms_setting('CACHE_DURATIONS')['content'])

    if content:
        return {'content': mark_safe(content)}

    return {'content': ''}
def _show_placeholder_attr_for_page(
        context, placeholder_name,
        plugin_class_name, plugin_attr,
        page_lookup, lang=None,
        site=None, cache_result=True):

    validate_placeholder_name(placeholder_name)

    request = context.get('request', False)
    site_id = get_site_id(site)

    if not request:
        return {'content': ''}
    if lang is None:
        lang = get_language_from_request(request)

    if cache_result:
        base_key = _get_cache_key(
            '_show_placeholder_for_page', page_lookup, lang, site_id)

        cache_key = _clean_key(
            '%s_placeholder:%s' % (
                base_key, placeholder_name
            )) + plugin_class_name + '.' + plugin_attr

        cached_value = cache.get(cache_key)
        if isinstance(cached_value, dict):  # new style
            _restore_sekizai(context, cached_value['sekizai'])
            return {'content': mark_safe(cached_value['content'])}
        elif isinstance(cached_value, string_types):  # old style
            return {'content': mark_safe(cached_value)}

    page = _get_page_by_untyped_arg(page_lookup, request, site_id)
    if not page:
        return {'content': ''}
    watcher = Watcher(context)

    placeholder = _get_placeholder(page, page, context, placeholder_name)
    content = get_placholder_attr(
        placeholder, placeholder_name, plugin_class_name, plugin_attr)

    changes = watcher.get_changes()

    if cache_result:
        cache.set(
            cache_key,
            {
                'content': content,
                'sekizai': changes
            }, get_cms_setting('CACHE_DURATIONS')['content'])

    if content:
        return {'content': mark_safe(content)}

    return {'content': ''}
コード例 #3
0
ファイル: templatetags.py プロジェクト: catyshka/kisele
def _show_content_for_page(context, placeholder_name, page_lookup, lang=None,
                               site=None, cache_result=True, content_max_length=None):
    """
    Shows the content of a page as content of placeholder with name 'content' and given lookup
    arguments in the given language.
    This is useful if you want to have some more or less static content that is
    shared among many pages, such as a footer.

    See _get_page_by_untyped_arg() for detailed information on the allowed types
    and their interpretation for the page_lookup argument.
    """
    validate_placeholder_name(placeholder_name)

    request = context.get('request', False)
    site_id = get_site_id(site)

    if not request:
        return {'content': ''}
    if lang is None:
        lang = get_language_from_request(request)

    if cache_result:
        base_key = _get_cache_key('_show_content_for_page', page_lookup, lang, site_id)
        cache_key = _clean_key('%s_placeholder:%s' % (base_key, placeholder_name))
        cached_value = cache.get(cache_key)
        if isinstance(cached_value, dict): # new style
            _restore_sekizai(context, cached_value['sekizai'])
            return {'content': mark_safe(cached_value['content'])}
        elif isinstance(cached_value, basestring): # old style
            return {'content': mark_safe(cached_value)}

    page = _get_page_by_untyped_arg(page_lookup, request, site_id)
    if not page:
        return {'content': ''}
    try:
        placeholder = page.placeholders.get(slot=placeholder_name)
    except PlaceholderModel.DoesNotExist:
        if settings.DEBUG:
            raise
        return {'content': ''}
    watcher = Watcher(context)
    content = render_placeholder(placeholder, context, placeholder_name)
     
    if content_max_length:
        content = remove_tags(content)[:content_max_length]
     
    changes = watcher.get_changes()
    if cache_result:
        cache.set(cache_key, {'content': content, 'sekizai': changes}, get_cms_setting('CACHE_DURATIONS')['content'])

    if content:
        return {'content': mark_safe(content)}
    return {'content': ''}
コード例 #4
0
ファイル: tags.py プロジェクト: ecofunds/ecofunds-trunk
def get_page(request, page_lookup, lang, site=None):
    site_id = cms_tags.get_site_id(site)
    
    if page_lookup:
        if isinstance(page_lookup, Page):
            return page_lookup
        else:
            cache_key = cms_tags._get_cache_key('tags_page_url', page_lookup, lang, site_id)+'_type:absolute_url'
            page = cache.get(cache_key)
            if not page:
                page = Page.objects.get(site=site_id, reverse_id=page_lookup)
                cache.set(cache_key, page, settings.CMS_CACHE_DURATIONS['content'])

            return page
    else:
        return None
コード例 #5
0
ファイル: templatetags.py プロジェクト: oencoding/django-cms
 def test_get_site_id_from_str(self):
     with SettingsOverride(SITE_ID=10):
         self.assertEqual(10, get_site_id("something"))
コード例 #6
0
ファイル: templatetags.py プロジェクト: oencoding/django-cms
 def test_get_site_id_from_str_int(self):
     self.assertEqual(10, get_site_id('10'))
コード例 #7
0
ファイル: templatetags.py プロジェクト: oencoding/django-cms
 def test_get_site_id_from_site(self):
     site = Site()
     site.id = 10
     self.assertEqual(10, get_site_id(site))
コード例 #8
0
ファイル: templatetags.py プロジェクト: oencoding/django-cms
 def test_get_site_id_from_int(self):
     self.assertEqual(10, get_site_id(10))
コード例 #9
0
ファイル: templatetags.py プロジェクト: oencoding/django-cms
 def test_get_site_id_from_nothing(self):
     with SettingsOverride(SITE_ID=10):
         self.assertEqual(10, get_site_id(None))
コード例 #10
0
ファイル: templatetags.py プロジェクト: catyshka/kisele
def _show_content_for_page(context,
                           placeholder_name,
                           page_lookup,
                           lang=None,
                           site=None,
                           cache_result=True,
                           content_max_length=None):
    """
    Shows the content of a page as content of placeholder with name 'content' and given lookup
    arguments in the given language.
    This is useful if you want to have some more or less static content that is
    shared among many pages, such as a footer.

    See _get_page_by_untyped_arg() for detailed information on the allowed types
    and their interpretation for the page_lookup argument.
    """
    validate_placeholder_name(placeholder_name)

    request = context.get('request', False)
    site_id = get_site_id(site)

    if not request:
        return {'content': ''}
    if lang is None:
        lang = get_language_from_request(request)

    if cache_result:
        base_key = _get_cache_key('_show_content_for_page', page_lookup, lang,
                                  site_id)
        cache_key = _clean_key('%s_placeholder:%s' %
                               (base_key, placeholder_name))
        cached_value = cache.get(cache_key)
        if isinstance(cached_value, dict):  # new style
            _restore_sekizai(context, cached_value['sekizai'])
            return {'content': mark_safe(cached_value['content'])}
        elif isinstance(cached_value, basestring):  # old style
            return {'content': mark_safe(cached_value)}

    page = _get_page_by_untyped_arg(page_lookup, request, site_id)
    if not page:
        return {'content': ''}
    try:
        placeholder = page.placeholders.get(slot=placeholder_name)
    except PlaceholderModel.DoesNotExist:
        if settings.DEBUG:
            raise
        return {'content': ''}
    watcher = Watcher(context)
    content = render_placeholder(placeholder, context, placeholder_name)

    if content_max_length:
        content = remove_tags(content)[:content_max_length]

    changes = watcher.get_changes()
    if cache_result:
        cache.set(cache_key, {
            'content': content,
            'sekizai': changes
        },
                  get_cms_setting('CACHE_DURATIONS')['content'])

    if content:
        return {'content': mark_safe(content)}
    return {'content': ''}