Exemple #1
0
def update08styles(request):
    """
    Fill colorschemes with colors from headfiles.
    """
    site = Site.objects.get_current()
    title = "Update PyLucid v0.8 %s styles" % site.name
    out = SimpleStringIO()

    designs = Design.on_site.filter(name__endswith=DESIGN_SUFFIX)
    resaved_headfiles = []
    for design in designs:
        out.write("\n______________________________________________________________")
        out.write("\nUpdate color scheme for design: '%s'" % design.name)

        headfiles = design.headfiles.all()
        for headfile in headfiles:
            if headfile in resaved_headfiles:
                continue
            resaved_headfiles.append(headfile)
            headfile.render = True
            headfile.save()
            out.write("Headfile %s set to render and resaved" % headfile)

    output = out.getlines()
    LogEntry.objects.log_action(
        "pylucid_update", title, request, "successful", long_message="\n".join(output)
    )

    context = {
        "title": title,
        "site": site,
        "results": output,
    }
    return context
Exemple #2
0
def update08styles(request):
    """
    Fill colorschemes with colors from headfiles.
    """
    site = Site.objects.get_current()
    title = "Update PyLucid v0.8 %s styles" % site.name
    out = SimpleStringIO()

    designs = Design.on_site.filter(name__endswith=DESIGN_SUFFIX)
    resaved_headfiles = []
    for design in designs:
        out.write(
            "\n______________________________________________________________")
        out.write("\nUpdate color scheme for design: '%s'" % design.name)

        headfiles = design.headfiles.all()
        for headfile in headfiles:
            if headfile in resaved_headfiles:
                continue
            resaved_headfiles.append(headfile)
            headfile.render = True
            headfile.save()
            out.write("Headfile %s set to render and resaved" % headfile)

    output = out.getlines()
    LogEntry.objects.log_action("pylucid_update",
                                title,
                                request,
                                "successful",
                                long_message="\n".join(output))

    context = {
        "title": title,
        "site": site,
        "results": output,
    }
    return context
Exemple #3
0
def update08templates(request):
    site = Site.objects.get_current()
    title = "Update PyLucid v0.8 %s templates" % site.name
    out = SimpleStringIO()

    templates = Template.on_site.filter(
        name__istartswith=settings.SITE_TEMPLATE_PREFIX)

    count = 0
    for template in templates:
        out.write(
            "\n______________________________________________________________")
        out.write("Update Template: '%s'\n" % template.name)

        content = template.content

        SCRIPT_TAG = (
            '<script src="%(url)s"'
            ' onerror="JavaScript:alert(\'Error loading file [%(url)s] !\');"'
            ' type="text/javascript" /></script>\n')

        new_head_file_tag = ""
        new_head_file_tag += SCRIPT_TAG % {
            "url":
            posixpath.join(settings.MEDIA_URL,
                           settings.PYLUCID.PYLUCID_MEDIA_DIR, "jquery.js")
        }
        new_head_file_tag += SCRIPT_TAG % {
            "url":
            posixpath.join(settings.MEDIA_URL,
                           settings.PYLUCID.PYLUCID_MEDIA_DIR,
                           "pylucid_js_tools.js")
        }
        new_head_file_tag += '<!-- ContextMiddleware extrahead -->\n'

        content = _replace(content, out, "{% lucidTag page_style %}",
                           new_head_file_tag)
        # temp in developer version:
        content = _replace(content, out, "{% lucidTag head_files %}",
                           new_head_file_tag)
        content = _replace(content, out,
                           "<!-- ContextMiddleware head_files -->",
                           new_head_file_tag)

        content = _replace(content, out, "{{ login_link }}",
                           "{% lucidTag auth %}")

        content = _replace(content, out, "{% lucidTag back_links %}",
                           "<!-- ContextMiddleware breadcrumb -->")
        content = _replace(
            content, out, "{{ PAGE.content }}", '<div id="page_content">\n'
            '    {% block content %}{{ page_content }}{% endblock content %}\n'
            '</div>')
        content = _replace(content, out, "{{ PAGE.get_permalink }}",
                           "{{ page_permalink }}")
        content = _replace(content, out, "{{ page_get_permalink }}",
                           "{{ page_permalink }}")  # dev version only
        content = _replace(
            content, out,
            "{% if PAGE.title %}{{ PAGE.title|escape }}{% else %}{{ PAGE.name|escape }}{% endif %}",
            "{{ page_title }}")
        content = _replace(content, out, "PAGE.title", "page_title")
        content = _replace(content, out, "{{ PAGE.keywords }}",
                           "{{ page_keywords }}")
        content = _replace(content, out, "{{ PAGE.description }}",
                           "{{ page_description }}")
        content = _replace(content, out, "{{ robots }}", "{{ page_robots }}")

        content = _replace(content, out, "{{ PAGE.datetime",
                           "{{ page_createtime")

        for timestring in ("lastupdatetime", "createtime"):
            # Change time with filter:
            content = _replace(content, out, "{{ PAGE.%s" % timestring,
                               "{{ page_%s" % timestring)
            # add i18n filter, if not exist:
            content = _replace(
                content,
                out,
                "{{ page_%s }}" % timestring,
                '{{ page_%s|date:_("DATETIME_FORMAT") }}' % timestring,
            )

        content = _replace(content, out, "{{ PAGE.", "{{ page_")

        content = _replace(content, out, "{% lucidTag RSS ",
                           "{% lucidTag rss ")

        # http://www.pylucid.org/permalink/81/backwards-incompatible-changes#26-05-2010-own-jquery-js-file-removed
        content = _replace(content, out, "/media/PyLucid/jquery.js",
                           "{{ Django_media_prefix }}js/jquery.min.js")
        content = _replace(content, out, "/media/PyLucid/pylucid_js_tools.js",
                           "{{ PyLucid_media_url }}pylucid_js_tools.js")

        if "{% lucidTag language %}" not in content:
            # Add language plugin after breadcrumb, if not exist
            content = _replace(
                content, out, "<!-- ContextMiddleware breadcrumb -->",
                "<!-- ContextMiddleware breadcrumb -->\n"
                "<p>{% lucidTag language %}</p>\n")

        # TODO: add somthing like: <meta http-equiv="Content-Language" content="en" />

        new_page_msg = '{% include "pylucid/includes/page_msg.html" %}'
        content = _replace(content, out, "<!-- page_messages -->",
                           new_page_msg)

        if new_page_msg not in content:
            out.write(' *** IMPORTANT: You must insert %s in this template!' %
                      new_page_msg)

        if template.content == content:
            out.write("Nothing changed")
        else:
            template.content = content
            template.save()
            count += 1
            out.write("Template updated.")

    out.write("\n\n%s Template items processed." % len(templates))
    out.write("%s items updated." % count)

    output = out.getlines()
    LogEntry.objects.log_action(
        "pylucid_update",
        title,
        request,
        "successful",
        long_message="\n".join(output))

    context = {
        "title": title,
        "site": site,
        "results": output,
    }
    return context
Exemple #4
0
def update08templates(request):
    site = Site.objects.get_current()
    title = "Update PyLucid v0.8 %s templates" % site.name
    out = SimpleStringIO()

    templates = Template.on_site.filter(
        name__istartswith=settings.SITE_TEMPLATE_PREFIX)

    count = 0
    for template in templates:
        out.write(
            "\n______________________________________________________________")
        out.write("Update Template: '%s'\n" % template.name)

        content = template.content

        SCRIPT_TAG = (
            '<script src="%(url)s"'
            ' onerror="JavaScript:alert(\'Error loading file [%(url)s] !\');"'
            ' type="text/javascript" /></script>\n')

        new_head_file_tag = ""
        new_head_file_tag += SCRIPT_TAG % {
            "url":
            posixpath.join(settings.STATIC_URL,
                           settings.PYLUCID.PYLUCID_MEDIA_DIR, "jquery.js")
        }
        new_head_file_tag += SCRIPT_TAG % {
            "url":
            posixpath.join(settings.STATIC_URL,
                           settings.PYLUCID.PYLUCID_MEDIA_DIR,
                           "pylucid_js_tools.js")
        }
        new_head_file_tag += '<!-- ContextMiddleware extrahead -->\n'

        content = _replace(content, out, "{% lucidTag page_style %}",
                           new_head_file_tag)
        # temp in developer version:
        content = _replace(content, out, "{% lucidTag head_files %}",
                           new_head_file_tag)
        content = _replace(content, out,
                           "<!-- ContextMiddleware head_files -->",
                           new_head_file_tag)

        content = _replace(content, out, "{{ login_link }}",
                           "{% lucidTag auth %}")

        content = _replace(content, out, "{% lucidTag back_links %}",
                           "<!-- ContextMiddleware breadcrumb -->")
        content = _replace(
            content, out, "{{ PAGE.content }}", '<div id="page_content">\n'
            '    {% block content %}{{ page_content }}{% endblock content %}\n'
            '</div>')
        content = _replace(content, out, "{{ PAGE.get_permalink }}",
                           "{{ page_permalink }}")
        content = _replace(content, out, "{{ page_get_permalink }}",
                           "{{ page_permalink }}")  # dev version only
        content = _replace(
            content, out,
            "{% if PAGE.title %}{{ PAGE.title|escape }}{% else %}{{ PAGE.name|escape }}{% endif %}",
            "{{ page_title }}")
        content = _replace(content, out, "PAGE.title", "page_title")
        content = _replace(content, out, "{{ PAGE.keywords }}",
                           "{{ page_keywords }}")
        content = _replace(content, out, "{{ PAGE.description }}",
                           "{{ page_description }}")
        content = _replace(content, out, "{{ robots }}", "{{ page_robots }}")

        content = _replace(content, out, "{{ PAGE.datetime",
                           "{{ page_createtime")

        for timestring in ("lastupdatetime", "createtime"):
            # Change time with filter:
            content = _replace(content, out, "{{ PAGE.%s" % timestring,
                               "{{ page_%s" % timestring)
            # add i18n filter, if not exist:
            content = _replace(
                content,
                out,
                "{{ page_%s }}" % timestring,
                '{{ page_%s|date:_("DATETIME_FORMAT") }}' % timestring,
            )

        content = _replace(content, out, "{{ PAGE.", "{{ page_")

        content = _replace(content, out, "{% lucidTag RSS ",
                           "{% lucidTag rss ")

        # http://www.pylucid.org/permalink/81/backwards-incompatible-changes#26-05-2010-own-jquery-js-file-removed
        content = _replace(content, out, "/media/PyLucid/jquery.js",
                           "{{ STATIC_URL }}admin/js/jquery.min.js")
        content = _replace(content, out, "/media/PyLucid/pylucid_js_tools.js",
                           "{{ STATIC_URL }}PyLucid/pylucid_js_tools.js")

        if "{% lucidTag language %}" not in content:
            # Add language plugin after breadcrumb, if not exist
            content = _replace(
                content, out, "<!-- ContextMiddleware breadcrumb -->",
                "<!-- ContextMiddleware breadcrumb -->\n"
                "<p>{% lucidTag language %}</p>\n")

        # TODO: add somthing like: <meta http-equiv="Content-Language" content="en" />

        new_page_msg = '{% include "pylucid/includes/page_msg.html" %}'
        content = _replace(content, out, "<!-- page_messages -->",
                           new_page_msg)

        if new_page_msg not in content:
            out.write(' *** IMPORTANT: You must insert %s in this template!' %
                      new_page_msg)

        if template.content == content:
            out.write("Nothing changed")
        else:
            template.content = content
            template.save()
            count += 1
            out.write("Template updated.")

    out.write("\n\n%s Template items processed." % len(templates))
    out.write("%s items updated." % count)

    output = out.getlines()
    LogEntry.objects.log_action("pylucid_update",
                                title,
                                request,
                                "successful",
                                long_message="\n".join(output))

    context = {
        "title": title,
        "site": site,
        "results": output,
    }
    return context