def markup_help(request): """ Display a help page for a markup given via GET parameter """ # Fallback: Use 'markup_help_base.html' template, if markup_id is wrong short_markup_name = "base" if request.method == 'GET': form = SelectMarkupForm(request.GET) if form.is_valid(): markup_id = form.cleaned_data["markup_id"] short_markup_name = MARKUP_SHORT_DICT[markup_id] else: form = SelectMarkupForm() template_name = "page_admin/markup_help_%s.html" % short_markup_name # get the EditableHtmlHeadFile path to pygments.css (page_msg created, if not exists) pygments_css_path = get_pygments_css(request) context = { "template_name": template_name, "form_url": request.path, "form": form, "title": "%s markup help" % short_markup_name, "pygments_css": pygments_css_path, } return context
def highlight_code(request): """ hightlight sourcecode for copy&paste """ context = { "title": _("hightlight sourcecode"), "form_url": request.path, } # get the EditableHtmlHeadFile path to pygments.css (page_msg created, if not exists) pygments_css_path = get_pygments_css(request) context["pygments_css"] = pygments_css_path if request.method == "POST": form = HighlightCodeForm(request.POST) if form.is_valid(): sourcecode = form.cleaned_data["sourcecode"] source_type = form.cleaned_data["source_type"] highlighted = make_html(sourcecode, source_type, django_escape=True) context["highlighted"] = highlighted html_code = make_html(highlighted, "html", django_escape=True) context["html_code"] = html_code else: form = HighlightCodeForm() context["form"] = form return context
def override_template(request): """ Overwrite a template: 1. The user can choose between all existing template in filesystem. 2. Read the content from filesystem and create a new dbtemplate entry. 3. redirect to edit the nre dbtemplate entry """ context = { "title": _("override template"), "form_url": request.path, } if request.method != "POST": form = SelectTemplateForm() else: form = SelectTemplateForm(request.POST) if form.is_valid(): fs_path = form.cleaned_data["template"] template = TemplateFile(request, fs_path) if "preview" in request.POST: # Display only the template content preview_html = template.get_content_preview() if preview_html: context["template"] = template # get the EditableHtmlHeadFile path to pygments.css (page_msg created, if not exists) pygments_css_path = get_pygments_css(request) context["pygments_css"] = pygments_css_path else: # A new dbtemplate should be created instance, created = template.get_or_create_dbtemplate() if instance: if created: # New dbtemplate instance created -> edit it # if instance == None: e.g.: error reading file -> page_msg was created msg = _("New dbtemplate entry %s created.") % instance LogEntry.objects.log_action( app_label="pylucid_plugin.extrahead", action="override template %s" % template.name, request=request, message=msg ) else: msg = _("dbtemplate entry %s already exists!") % instance msg += _(" You can edit it now.") messages.info(request, msg) # redirect to edit the new dbtemplate entry url = reverse("admin:dbtemplates_template_change", args=(instance.id,)) return http.HttpResponseRedirect(url) context["form"] = form return context
def find_and_replace(request): """ find and replace a string in all page content. """ context = {"title": _("Find and replace"), "form_url": request.path} if request.method == "POST": form = FindReplaceForm(request.POST) if form.is_valid(): start_time = time.time() _do_find_and_replace(request, context, **form.cleaned_data) context["duration"] = time.time() - start_time # get the EditableHtmlHeadFile path to pygments.css (page_msg created, if not exists) pygments_css_path = hightlighter.get_pygments_css(request) context["pygments_css"] = pygments_css_path else: form = FindReplaceForm() context["form"] = form return context
context["converted_html"] = converted_html if cleaned_data["verbose"]: context["original_markup"] = original_markup orig_html = converter.apply_markup( original_markup, pagecontent.markup, request, escape_django_tags=True ) context["orig_html"] = orig_html def strip_whitespace(html): return "\n".join([line.strip() for line in html.splitlines() if line.strip()]) # Remove whitespace from html code. orig_html2 = strip_whitespace(orig_html) converted_html2 = strip_whitespace(converted_html) if orig_html2 == converted_html2: context["diff_is_the_same"] = True else: context["pygmentize_diff"] = hightlighter.get_pygmentize_diff(orig_html2, converted_html2) # get the EditableHtmlHeadFile path to pygments.css (page_msg created, if not exists) pygments_css_path = hightlighter.get_pygments_css(request) context["pygments_css"] = pygments_css_path context.update({ "form": form, }) return context
def pylucid(request): """ A django TEMPLATE_CONTEXT_PROCESSORS http://www.djangoproject.com/documentation/templates_python/#writing-your-own-context-processors """ if hasattr(request.PYLUCID, "context"): # reuse a exsiting context, so we save a few database requests context = request.PYLUCID.context else: # create a new context # FIXME: Should we only insert pygments in admin section? # We can also add a new template tag to get the path and insert it in pylucid/templates/admin/base_site.html # get the EditableHtmlHeadFile path to pygments.css (page_msg created, if not exists) pygments_css_path = get_pygments_css(request) context = { "powered_by": mark_safe('<a href="http://www.pylucid.org">PyLucid v%s</a>' % VERSION_STRING), # This value would be changed in index._render_cms_page(), if the # plugin manager or any plugin set request.anonymous_view = False "robots": "index,follow", # TODO: remove in v0.9, see: ticket:161 "CSS_PLUGIN_CLASS_NAME": settings.PYLUCID.CSS_PLUGIN_CLASS_NAME, "current_site": Site.objects.get_current(), "sites": Site.objects.all(), "PyLucid_media_url": settings.MEDIA_URL + settings.PYLUCID.PYLUCID_MEDIA_DIR + "/", "Django_media_prefix": settings.ADMIN_MEDIA_PREFIX, "debug": settings.DEBUG, "PYLUCID": request.PYLUCID, "pygments_css": pygments_css_path, } pagetree = getattr(request.PYLUCID, "pagetree", None) if pagetree: if "design_switch_pk" in request.session: # The user has switch the design with pylucid_plugins.design from pylucid_project.apps.pylucid.models import Design # import here, agains import loops design_id = request.session["design_switch_pk"] try: pagetree.design = Design.on_site.get(id=design_id) except Design.DoesNotExist, err: messages.error(request, "Can't switch to design with ID %i: %s" % (design_id, err)) del(request.session["design_switch_pk"]) template_name = pagetree.design.template context["template_name"] = template_name # Add the dbtemplates entry. # Used in pylucid_admin_menu.html for generating the "edit page template" link try: context["template"] = Template.on_site.get(name=template_name) except Template.DoesNotExist: context["template"] = None pagemeta = getattr(request.PYLUCID, "pagemeta", None) if pagemeta: context.update({ "pagemeta": pagemeta, "page_title": pagemeta.get_title(), "page_keywords": pagemeta.keywords, "page_description": pagemeta.description, "page_robots": pagemeta.robots, "page_language": pagemeta.language.code, "page_permalink": pagemeta.get_permalink(), "page_absolute_url": pagemeta.get_absolute_url(), })