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': ''}
def get_context(self, context, **kwargs): request = context['request'] page = request.current_page sections = [] placeholder = _get_placeholder(page, page, context, "homepage_content") objects = placeholder.get_plugins_list() for obj in objects: if isinstance(obj, CMSPlugin): plugin = obj instance, plugin = plugin.get_plugin_instance() if isinstance( instance, Section) and instance.active and instance.show_on_menu: sections.append(instance) return {'sections': sections}
def test_create_placeholder_if_not_exist_in_template(self): """ Tests that adding a new placeholder to a an exising page's template creates the placeholder. """ page = create_page('Test', 'col_two.html', 'en') # I need to make it seem like the user added another plcaeholder to the SAME template. page._template_cache = 'col_three.html' class FakeRequest(object): current_page = page REQUEST = {'language': 'en'} placeholder = _get_placeholder(page, page, dict(request=FakeRequest()), 'col_right') page.placeholders.get(slot='col_right') self.assertEqual(placeholder.slot, 'col_right')
def get_nodes(self, request): nodes = [] glasfaser_cms = 'ungleich_page/glasfaser_cms_page.html' if (request and request.current_page and request.current_page.get_template() == glasfaser_cms): template_context = { "request": request, } placeholder_name_list = [ 'Top Section', 'Middle Section', 'Glasfaser Services', 'Glasfaser About', 'Contact Section' ] plugins_list = [ 'SectionWithImage', 'UngelichContactUsSection', 'UngelichTextSection', 'Service', 'About' ] for placeholder_name in placeholder_name_list: placeholder = _get_placeholder(request.current_page, request.current_page, template_context, placeholder_name) plugins = get_plugins(request, placeholder, request.current_page.get_template()) for plugin in plugins: if type(plugin).__name__ in plugins_list: section_hash = request.build_absolute_uri() if hasattr(plugin, 'menu_text'): menu_text = plugin.menu_text if menu_text.strip() == '': continue menu_words = menu_text.split() if len(menu_words) > 0: section_hash = '{}#{}'.format( section_hash, menu_words[0]) else: continue newnode = NavigationNode(menu_text, url=section_hash, id="{}-{}".format( request.current_page.id, plugin.id)) nodes.append(newnode) return nodes
def render_tag(self, context, name, plugin_class_name, plugin_attr, extra_bits, nodelist=None): validate_placeholder_name(name) width = None for bit in extra_bits: if bit == 'inherit': pass elif bit.isdigit(): width = int(bit) import warnings warnings.warn( "The width parameter for the placeholder " + "tag is deprecated.", DeprecationWarning) if not 'request' in context: return '' request = context['request'] if width: context.update({'width': width}) page = request.current_page if not page or page == 'dummy': if nodelist: return nodelist.render(context) return '' placeholder = _get_placeholder(page, page, context, name) res = get_placholder_attr(placeholder, name, plugin_class_name, plugin_attr) return res
def render_tag( self, context, name, plugin_class_name, plugin_attr, extra_bits, nodelist=None): validate_placeholder_name(name) width = None for bit in extra_bits: if bit == 'inherit': pass elif bit.isdigit(): width = int(bit) import warnings warnings.warn( "The width parameter for the placeholder " + "tag is deprecated.", DeprecationWarning ) if not 'request' in context: return '' request = context['request'] if width: context.update({'width': width}) page = request.current_page if not page or page == 'dummy': if nodelist: return nodelist.render(context) return '' placeholder = _get_placeholder(page, page, context, name) res = get_placholder_attr( placeholder, name, plugin_class_name, plugin_attr) return res