def _render_cms_page(request, context, page_content=None): """ render the cms page. - render a normal cms request - render a _command request: The page.content is the output from the plugin. """ if request.anonymous_view == False: # TODO: remove in v0.9, see: ticket:161 # context["robots"] was set in contex_processors.static() # Hide the response from search engines context["robots"] = "NONE,NOARCHIVE" context["anonymous_view"] = request.anonymous_view current_page = context["PAGE"] if page_content: # The page content comes e.g. from the _command plugin # current_page.content = page_content page_content = escape_django_tags(page_content) else: # get the current page data from the db page_content = current_page.content markup_no = current_page.markup page_content = apply_markup(page_content, context, markup_no) # Render only the CMS page content: try: page_content = render_string_template(page_content, context) # If a user access a public viewable cms page, but in the page content # is a lucidTag witch is a restricted method, the pylucid plugin # manager would normaly raise a AccessDenied. # The Problem is, if settings.TEMPLATE_DEBUG is on, we didn't get a # AccessDenied directly, we always get a TemplateSyntaxError! All # other errors will catched and raised a TemplateSyntaxError, too. # See django/template/debug.py # TODO: Instead of a redirect to the login command, we can insert # the ouput from auth.login directly except TemplateSyntaxError, err: # Check if it was a AccessDenied exception if hasattr(err, "exc_info"): # sys.exc_info() added in django/template/debug.py error_class = err.exc_info[1] if isinstance(error_class, AccessDenied): return _redirect_access_denied(request) raise # raise the original error
def all_pages(self): current_page = self.context["PAGE"] current_page.title = "all pages" current_page_id = current_page.id # page_data = Page.objects.values( # "id", "parent", "shortcut", "name", "title", # "template", "content", "markup" # ).order_by("position") pages = Page.objects.all().order_by("position") page_data = [] for page in pages: content = escape_django_tags(page.content) parent = getattr(page.parent, "id", None) url = page.get_absolute_url() page_data.append({ "id": page.id, "parent": parent, "shortcut": page.shortcut, "name": page.name, "title": page.title, "content": content, "template": page.template.id, "markup": page.markup, "url": url, }) # self.page_msg(page_data) tree = TreeGenerator(page_data) page_list = tree.get_group_list( group_key="template", id=current_page_id )[1:] for page in page_list: content = page["content"] markup_object = page["markup"] content = apply_markup(content, self.context, markup_object) page["content"] = content # self.page_msg(page_list) context = { "page_list": page_list, } self._render_template("all_pages", context)#, debug=True)
def _preview(self, context, page_form, markup_form): # Apply the markup witch is selected in the form content = apply_markup( page_form.cleaned_data["content"], self.context, markup_form.cleaned_data["markup"] ) if "submit_dest_markup" in self.request.POST: # We should convert the markup self._convert_markup(content, page_form, markup_form) preview_escape = page_form.cleaned_data["preview_escape"] if preview_escape == True: # escape django template tags for preview content = escape_django_tags(content) content = render_string_template(content, self.context) context["preview_content"] = content
else: lexer = lexers.get_lexer_by_name(ext) except lexers.ClassNotFound, err: info = _("unknown type") lexer_name = u'<small title="%s">%s</small>' % (err, info) html = no_hightlight(sourcecode) return html, lexer_name lexer_name = lexer.name formatter = get_formatter() out_object = SimpleStringIO() try: highlight(sourcecode, lexer, formatter, out_object) except Exception, err: if settings.DEBUG: raise html = no_hightlight(sourcecode) lexer_name += " (Error: %s)" % err else: html = out_object.getvalue() # If there is e.g. html code with django tags, we must escape this: html = escape_django_tags(html) html = html.decode("utf-8") return html, lexer_name
for regex in STRIP_CONTENT: try: content = regex.sub(u"",content) except Exception, err: if self.request.debug: self.page_msg.red("Error strip content:", err) #______________________________________________________________________ if escape: # Escape "&", "<", ">" and django template tags, e.g. "{" and "}" content = html_escape(content) else: # Escape only django template tags chars, e.g. "{" and "}" content = escape_django_tags(content) # turn django auto-escaping off content = mark_safe(content) # setup preformat if preformat==None and "html" in content_type: preformat = False else: preformat = True context = { "duration_time": duration_time, "url": url, "title": title, "content": content,