def __render(self, template, context, debug=False): """ render the template string with the given context and returned it. -debug the context, if debug is on. """ html = render_string_template(template, context) if debug: self.response.write("<fieldset><legend>template debug:</legend>") self.response.write("<legend>context:</legend>") self.response.write("<pre>") self.response.write(escape(pprint.pformat(context))) self.response.write("</pre>") self.response.write("<legend>template:</legend>") self.response.write("<pre>") self.response.write(escape(template)) self.response.write("</pre>") if debug>1: self.response.write("<legend>result html code:</legend>") self.response.write("<pre>") self.response.write(escape(html)) self.response.write("</pre>") self.response.write("</fieldset>") return html
def logout(self): """ Delete the instpass cookie, so the user is logout. """ self.context["no_menu_link"] = True # no "back to menu" link html = render_string_template(LOGOUT_TEMPLATE, self.context) response = HttpResponse(html) response.set_cookie(INSTALL_COOKIE_NAME, value="") return response
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 replace_add_data(context, content): """ Replace the temporary inserted "add data" tag, with all collected CSS/JS contents, e.g. from the internal pages. Note: The tag added in PyLucid.plugins_internal.page_style """ internal_page_content = get_internal_page(context, "page_style", "add_data") context = { "js_data": context["js_data"], "css_data": context["css_data"], } html = render_string_template( internal_page_content, context, autoescape=False ) content = content.replace(settings.ADD_DATA_TAG, html) return content
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
return _redirect_access_denied(request) # http://www.djangoproject.com/documentation/templates_python/#filters-and-auto-escaping page_content = mark_safe(page_content) # turn djngo auto-escaping off context["PAGE"].content = page_content # Get the template instance: consider the overwrite from page_style.switch() # or get the template from the current page object. template = get_template(request) # Get the content from the model instance template_content = template.content # Render the Template to build the complete html page: content = render_string_template(template_content, context) # insert JS/CSS data from any Plugin *after* the page rendered with the # django template engine: content = replace_add_data(context, content) # TODO: Remove in PyLucid >v0.8.5 middleware = 'PyLucid.middlewares.pagemessages.PageMessagesMiddleware' if middleware not in settings.MIDDLEWARE_CLASSES: msg = ( u"ERROR: %s not in settings.MIDDLEWARE_CLASSES!" " More info: %s" ) % (middleware, PAGE_MSG_INFO_LINK) content = content.replace(u"<!-- page_messages -->", msg) return HttpResponse(content)
{% for message in page_msg %}\t{{ message }}<br /> {% endfor %} </fieldset>""" class PageMessagesMiddleware(object): def process_response(self, request, response): """ insert all page messages into the html page. """ if not is_html(response): # No HTML Page -> do nothing return response try: # get PyLucid.system.page_msg.PageMessages(): page_msg = request.page_msg except AttributeError, e: message_string = "Error getting page_msg: %s" % e else: if len(page_msg) == 0: # There exists no page messages message_string = "" else: message_string = render_string_template( TEMPLATE, context={"page_msg": page_msg} ) response = replace_content(response, TAG, message_string) return response
def _render(self, template): """ render the template and returns the result as a HttpResponse object. """ html = render_string_template(template, self.context) return HttpResponse(html)