def render(self, context): if not 'request' in context: return '' l = get_language_from_request(context['request']) request = context['request'] CMSPluginModel = get_cmsplugin_model(request) page = request.current_page plugins = CMSPluginModel.objects.filter(page=page, language=l, placeholder__iexact=self.name, parent__isnull=True).order_by('position').select_related() if settings.CMS_PLACEHOLDER_CONF and self.name in settings.CMS_PLACEHOLDER_CONF: if "extra_context" in settings.CMS_PLACEHOLDER_CONF[self.name]: context.update(settings.CMS_PLACEHOLDER_CONF[self.name]["extra_context"]) c = "" for plugin in plugins: c += plugin.render_plugin(context, self.name) return c
def show_placeholder_by_id(context, placeholder_name, reverse_id, lang=None): """ Show the content of a page with a placeholder name and a reverse id in the right language This is mostly used if you want to have static content in a template of a page (like a footer) """ request = context.get('request', False) PageModel = get_page_model(request) CMSPluginModel = get_cmsplugin_model(request) if not request: return {'content':''} if lang is None: lang = get_language_from_request(request) key = 'show_placeholder_by_id_pid:'+reverse_id+'placeholder:'+placeholder_name+'_l:'+str(lang) content = cache.get(key) if not content: try: page = PageModel.objects.get(reverse_id=reverse_id) except: if settings.DEBUG: raise else: site = Site.objects.get_current() send_mail(_('Reverse ID not found on %(domain)s') % {'domain':site.domain}, _("A show_placeholder_by_id template tag didn't found a page with the reverse_id %(reverse_id)s\n" "The url of the page was: http://%(host)s%(path)s") % {'reverse_id':reverse_id, 'host':request.host, 'path':request.path}, settings.DEFAULT_FROM_EMAIL, settings.MANAGERS, fail_silently=True) plugins = CMSPluginModel.objects.filter(page=page, language=lang, placeholder__iexact=placeholder_name, parent__isnull=True).order_by('position').select_related() content = "" for plugin in plugins: content += plugin.render_plugin(context, placeholder_name) cache.set(key, content, settings.CMS_CONTENT_CACHE_DURATION) if content: return {'content':mark_safe(content)} return {'content':''}