Beispiel #1
0
def apply_tinytextile(content, page_msg):
    """ tinyTextile markup """
    from pylucid_project.apps.pylucid.markup.tinyTextile import TinyTextileParser
    out_obj = SimpleStringIO()
    markup_parser = TinyTextileParser(out_obj, page_msg)
    markup_parser.parse(smart_str(content))
    return force_unicode(out_obj.getvalue())
Beispiel #2
0
def update08pagesRedirect(request):
    site = Site.objects.get_current()
    title = "Add %s permalink Redirect entries." % site.name
    out = SimpleStringIO()

    new_page_id_data = _get_page_id_data(site)

    for (old_page_id, tree_entry_id) in new_page_id_data.iteritems():
        old_page = Page08.objects.only("id", "shortcut").get(id=old_page_id)

        old_path = "/%s/%i/%s/" % (settings.PYLUCID.OLD_PERMALINK_PREFIX,
                                   old_page.id, old_page.shortcut)
        new_path = "/%s/%i/%s/" % (settings.PYLUCID.PERMALINK_URL_PREFIX,
                                   tree_entry_id, old_page.shortcut)

        created = Redirect.objects.get_or_create(
            site=site, old_path=old_path, defaults={"new_path": new_path})[1]
        if created:
            out.write(
                "Add permalink redirect. ( %s -> %s )" % (old_path, new_path))
        else:
            out.write("Permalink redirect for this page exist. ( %s -> %s )" %
                      (old_path, new_path))

    output = _get_output(request, out,
                         title)  # merge page_msg and log the complete output

    context = {
        "title": title,
        "site": site,
        "results": output,
    }
    return context
Beispiel #3
0
def apply_tinytextile(content, page_msg):
    """ tinyTextile markup """
    from pylucid_project.apps.pylucid.markup.tinyTextile import TinyTextileParser
    out_obj = SimpleStringIO()
    markup_parser = TinyTextileParser(out_obj, page_msg)
    markup_parser.parse(smart_str(content))
    return force_unicode(out_obj.getvalue())
Beispiel #4
0
def _update08plugins(request, language):
    site = Site.objects.get_current()
    title = "Update PyLucid v0.8 plugin data"
    out = SimpleStringIO()

    method_kwargs = {
        "out": out,
        "language": language,
    }

    filename = settings.PYLUCID.UPDATE08_PLUGIN_FILENAME
    view_name = settings.PYLUCID.UPDATE08_PLUGIN_VIEWNAME

    for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
        try:
            plugin_instance.call_plugin_view(request, filename, view_name,
                                             method_kwargs)
        except Exception, err:
            if str(err).endswith("No module named %s" % filename):
                # Plugin has no update API
                continue
            if settings.DEBUG:
                raise
            messages.error(request, "failed updating %s." % plugin_name)
            messages.debug(request,
                           mark_safe("<pre>%s</pre>" % traceback.format_exc()))
        else:
            out.write(" --- %s END ---" % plugin_name)
Beispiel #5
0
def _update08plugins(request, language):
    site = Site.objects.get_current()
    title = "Update PyLucid v0.8 plugin data"
    out = SimpleStringIO()

    method_kwargs = {
        "out": out,
        "language": language,
    }

    filename = settings.PYLUCID.UPDATE08_PLUGIN_FILENAME
    view_name = settings.PYLUCID.UPDATE08_PLUGIN_VIEWNAME

    for plugin_name, plugin_instance in PYLUCID_PLUGINS.iteritems():
        try:
            plugin_instance.call_plugin_view(request, filename, view_name,
                                             method_kwargs)
        except Exception, err:
            if str(err).endswith("No module named %s" % filename):
                # Plugin has no update API
                continue
            if settings.DEBUG:
                raise
            messages.error(request, "failed updating %s." % plugin_name)
            messages.debug(request,
                           mark_safe("<pre>%s</pre>" % traceback.format_exc()))
        else:
            out.write(" --- %s END ---" % plugin_name)
Beispiel #6
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
Beispiel #7
0
def wipe_site(request):
    """ Delete all PageTree, PageMeta, PagePlugin for the current site. """
    current_site = Site.objects.get_current()
    title = _("Wipe all page data on '%s'." % current_site.name)
    context = {"title": title, "site": current_site}
    out = SimpleStringIO()

    if request.method == 'POST':
        form = WipeSiteConfirm(request.POST)
        if form.is_valid():

            sid = transaction.savepoint()
            try:
                Preference.objects.all().filter(site=current_site).delete()
                PageTree.on_site.all().delete()
            except Exception, err:
                transaction.savepoint_rollback(sid)
                LogEntry.objects.log_action(
                    "pylucid_update",
                    title,
                    request,
                    "Error: %s" % err,
                    long_message=traceback.format_exc())
                raise
            else:
                transaction.savepoint_commit(sid)
                LogEntry.objects.log_action("pylucid_update", title, request,
                                            "successful")
                messages.info(request, "Wipe site data successful")

            return HttpResponseRedirect(reverse("PyLucidUpdate-menu"))
Beispiel #8
0
def update08pagesRedirect(request):
    site = Site.objects.get_current()
    title = "Add %s permalink Redirect entries." % site.name
    out = SimpleStringIO()

    new_page_id_data = _get_page_id_data(site)

    for (old_page_id, tree_entry_id) in new_page_id_data.iteritems():
        old_page = Page08.objects.only("id", "shortcut").get(id=old_page_id)

        old_path = "/%s/%i/%s/" % (settings.PYLUCID.OLD_PERMALINK_PREFIX,
                                   old_page.id, old_page.shortcut)
        new_path = "/%s/%i/%s/" % (settings.PYLUCID.PERMALINK_URL_PREFIX,
                                   tree_entry_id, old_page.shortcut)

        created = Redirect.objects.get_or_create(
            site=site, old_path=old_path, defaults={"new_path": new_path})[1]
        if created:
            out.write("Add permalink redirect. ( %s -> %s )" %
                      (old_path, new_path))
        else:
            out.write("Permalink redirect for this page exist. ( %s -> %s )" %
                      (old_path, new_path))

    output = _get_output(request, out,
                         title)  # merge page_msg and log the complete output

    context = {
        "title": title,
        "site": site,
        "results": output,
    }
    return context
Beispiel #9
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
Beispiel #10
0
def _update08migrate_pages(request, language):
    """
    Mirgate page data from a old v0.8 installation into the new v0.9 tables.
    
    Originally, this migration can be callable multiple times. But we migrate the old tree not
    in hierarchical order. Thus, migration can only be called unique.
    """
    site = Site.objects.get_current()
    title = "migrate v0.8 pages (on site: %s)" % site
    out = SimpleStringIO()

    out.write("migrate old page model data")

    old_pages = Page08.objects.order_by('parent', 'id').all()

    designs = {}
    page_dict = {}
    parent_attach_data = {}
    new_page_id_data = {}
    for old_page in old_pages:
        out.write(
            "\nmove '%s' page (old ID:%s)" % (old_page.name, old_page.id))

        fix_old_user(
            out,
            obj=old_page,
            attrnames=["createby", "lastupdateby"],
            alternative_user=request.user)

        #---------------------------------------------------------------------
        # create/get Design entry

        if old_page.template.name == old_page.style.name:
            design_key = "%s %s" % (old_page.template.name, DESIGN_SUFFIX)
        else:
            design_key = "%s + %s %s" % (old_page.template.name,
                                         old_page.style.name, DESIGN_SUFFIX)

        if design_key in designs:
            design = designs[design_key]
            out.write("Design: %r created in the past." % design)
        else:
            # The template/style combination was not created, yet.
            new_template_name = _make_new_template_name(
                old_page.template.name, site)
            design, created = Design.objects.get_or_create(
                name=design_key, defaults={"template": new_template_name})
            if created:
                design.sites.add(site)
                out.write("New design %s created." % design_key)
            else:
                out.write("Use existing Design: %r" % design)

            # Add old page css file
            new_style_name = _make_new_style_name(old_page.style.name, site)
            try:
                css_file = EditableHtmlHeadFile.objects.get(
                    filepath=new_style_name)
            except EditableHtmlHeadFile.DoesNotExist:
                out.write(
                    "Error getting headfile %r. (Can't add it to design %r)" %
                    (new_style_name, design))
            else:
                design.headfiles.add(css_file)

            colorscheme, created = ColorScheme.objects.get_or_create(
                name=old_page.style.name)
            if created:
                out.write("Use new color scheme: %s" % colorscheme.name)
                out.write("Colors can be extracted later.")
            else:
                out.write("Use color scheme: %s" % colorscheme.name)

            design.colorscheme = colorscheme
            design.save()
            designs[design_key] = design

        #---------------------------------------------------------------------
        # create PageTree entry

        page_parent_exist = True  # Exist the parent page tree or was he not created, yet?
        if old_page.parent == None:
            parent = None
        else:
            old_parent_id = old_page.parent.id
            try:
                parent = page_dict[old_parent_id]
            except KeyError, err:
                page_parent_exist = False
                msg = (" *** Error: parent id %r not found!"
                       " Attach as root page and try later.") % old_parent_id
                out.write(msg)

        tree_entry = PageTree(
            site=site,
            slug=old_page.shortcut,
            parent=parent,
            position=old_page.position,
            page_type=PageTree.
            PAGE_TYPE,  # FIXME: Find plugin entry in page content
            design=design,
            createtime=old_page.createtime,
            lastupdatetime=old_page.lastupdatetime,
            createby=old_page.createby,
            lastupdateby=old_page.lastupdateby,
        )
        tree_entry.save()
        out.write("PageTree entry '%s' created." % tree_entry.slug)

        # Collect the information old page ID <-> new PageTree ID
        new_page_id_data[old_page.id] = tree_entry.id

        page_dict[old_page.id] = tree_entry

        if old_page.id in parent_attach_data:
            # We have create a page tree witch was missing in the past.
            # Attach the right parent
            out.write(" +++ Attach the now created page tree %r as parent to:"
                      % tree_entry)
            for created_page in parent_attach_data[old_page.id]:
                out.write("\t%r" % created_page)
                created_page.parent = tree_entry
                created_page.save()
            del (parent_attach_data[old_page.id])  # No longer needed

        if not page_parent_exist:
            # The parent page for the created tree_entry was not created yed.
            # Save this and attach the right parent page, after create.
            out.write("Remember page %r for later parent attach." % tree_entry)
            if old_parent_id not in parent_attach_data:
                parent_attach_data[old_parent_id] = [tree_entry]
            else:
                parent_attach_data[old_parent_id].append(tree_entry)

        #---------------------------------------------------------------------
        # create PageMeta entry

        pagemeta_entry = PageMeta(
            pagetree=tree_entry,
            language=language,
            name=old_page.name,
            title=old_page.title,
            keywords=old_page.keywords,
            description=old_page.description,

            # django-tagging can't handle case insensitive tags :(
            # So we get a duplicate entry IntegrityError an e.g.: "CGI, cgi"
            # work-a-round here: .lower() all tags :(
            # see: http://code.google.com/p/django-tagging/issues/detail?id=46
            tags=old_page.keywords.lower(),
            createtime=old_page.createtime,
            lastupdatetime=old_page.lastupdatetime,
            createby=old_page.createby,
            lastupdateby=old_page.lastupdateby,
        )
        pagemeta_entry.save()
        out.write("PageMeta entry '%s' - '%s' created." % (language,
                                                           tree_entry.slug))

        #---------------------------------------------------------------------
        # create PageContent or PluginPage entry

        if old_page.content.strip() == "{% lucidTag blog %}":
            # Create a blog plugin page, but only if there is no additional content
            tree_entry.page_type = PageTree.PLUGIN_TYPE
            tree_entry.save()

            new_pluginpage = PluginPage(
                app_label="pylucid_project.pylucid_plugins.blog")
            new_pluginpage.pagetree = tree_entry
            new_pluginpage.save()
            out.write("PluginPage entry 'blog' created for: %r" % tree_entry)
        else:
            # create PageContent entry
            content_entry = PageContent(
                pagemeta=pagemeta_entry,
                content=old_page.content,
                markup=old_page.markup,
                createtime=old_page.createtime,
                lastupdatetime=old_page.lastupdatetime,
                createby=old_page.createby,
                lastupdateby=old_page.lastupdateby,
            )
            content_entry.save()
            out.write("PageContent entry '%s' - '%s' created." %
                      (language, tree_entry.slug))
Beispiel #11
0
def update08migrate_stj(request):
    out = SimpleStringIO()
    site = Site.objects.get_current()
    title = "migrate v0.8 styles, templates, JS-SHA-Login data (on site: %s)" % site

    out.write("Move JS-SHA-Login data into new UserProfile\n")
    for old_entry in JS_LoginData08.objects.all():
        try:
            user = old_entry.user
        except User.DoesNotExist, err:
            out.write(
                "Old JS_LoginData08 User doesn't exist. Skip updating UserProfile."
            )
            continue

        userprofile, created = UserProfile.objects.get_or_create(user=user)
        if created:
            out.write("UserProfile for user '%s' created." % user.username)
        else:
            out.write("UserProfile for user '%s' exist." % user.username)

        if not userprofile.sha_login_checksum:
            # Add old sha login data, only if not exist.
            sha_login_checksum = old_entry.sha_checksum
            userprofile.sha_login_checksum = sha_login_checksum

            sha_login_salt = old_entry.salt
            userprofile.sha_login_salt = sha_login_salt

            userprofile.save()
            out.write("Add old JS-SHA-Login data.")
Beispiel #12
0
def _update08migrate_pages(request, language):
    """
    Mirgate page data from a old v0.8 installation into the new v0.9 tables.
    
    Originally, this migration can be callable multiple times. But we migrate the old tree not
    in hierarchical order. Thus, migration can only be called unique.
    """
    site = Site.objects.get_current()
    title = "migrate v0.8 pages (on site: %s)" % site
    out = SimpleStringIO()

    out.write("migrate old page model data")

    old_pages = Page08.objects.order_by('parent', 'id').all()

    designs = {}
    page_dict = {}
    parent_attach_data = {}
    new_page_id_data = {}
    for old_page in old_pages:
        out.write("\nmove '%s' page (old ID:%s)" %
                  (old_page.name, old_page.id))

        fix_old_user(out,
                     obj=old_page,
                     attrnames=["createby", "lastupdateby"],
                     alternative_user=request.user)

        #---------------------------------------------------------------------
        # create/get Design entry

        if old_page.template.name == old_page.style.name:
            design_key = "%s %s" % (old_page.template.name, DESIGN_SUFFIX)
        else:
            design_key = "%s + %s %s" % (old_page.template.name,
                                         old_page.style.name, DESIGN_SUFFIX)

        if design_key in designs:
            design = designs[design_key]
            out.write("Design: %r created in the past." % design)
        else:
            # The template/style combination was not created, yet.
            new_template_name = _make_new_template_name(
                old_page.template.name, site)
            design, created = Design.objects.get_or_create(
                name=design_key, defaults={"template": new_template_name})
            if created:
                design.sites.add(site)
                out.write("New design %s created." % design_key)
            else:
                out.write("Use existing Design: %r" % design)

            # Add old page css file
            new_style_name = _make_new_style_name(old_page.style.name, site)
            try:
                css_file = EditableHtmlHeadFile.objects.get(
                    filepath=new_style_name)
            except EditableHtmlHeadFile.DoesNotExist:
                out.write(
                    "Error getting headfile %r. (Can't add it to design %r)" %
                    (new_style_name, design))
            else:
                design.headfiles.add(css_file)

            colorscheme, created = ColorScheme.objects.get_or_create(
                name=old_page.style.name)
            if created:
                out.write("Use new color scheme: %s" % colorscheme.name)
                out.write("Colors can be extracted later.")
            else:
                out.write("Use color scheme: %s" % colorscheme.name)

            design.colorscheme = colorscheme
            design.save()
            designs[design_key] = design

        #---------------------------------------------------------------------
        # create PageTree entry

        page_parent_exist = True  # Exist the parent page tree or was he not created, yet?
        if old_page.parent == None:
            parent = None
        else:
            old_parent_id = old_page.parent.id
            try:
                parent = page_dict[old_parent_id]
            except KeyError, err:
                page_parent_exist = False
                msg = (" *** Error: parent id %r not found!"
                       " Attach as root page and try later.") % old_parent_id
                out.write(msg)

        tree_entry = PageTree(
            site=site,
            slug=old_page.shortcut,
            parent=parent,
            position=old_page.position,
            page_type=PageTree.
            PAGE_TYPE,  # FIXME: Find plugin entry in page content
            design=design,
            createtime=old_page.createtime,
            lastupdatetime=old_page.lastupdatetime,
            createby=old_page.createby,
            lastupdateby=old_page.lastupdateby,
        )
        tree_entry.save()
        out.write("PageTree entry '%s' created." % tree_entry.slug)

        # Collect the information old page ID <-> new PageTree ID
        new_page_id_data[old_page.id] = tree_entry.id

        page_dict[old_page.id] = tree_entry

        if old_page.id in parent_attach_data:
            # We have create a page tree witch was missing in the past.
            # Attach the right parent
            out.write(
                " +++ Attach the now created page tree %r as parent to:" %
                tree_entry)
            for created_page in parent_attach_data[old_page.id]:
                out.write("\t%r" % created_page)
                created_page.parent = tree_entry
                created_page.save()
            del (parent_attach_data[old_page.id])  # No longer needed

        if not page_parent_exist:
            # The parent page for the created tree_entry was not created yed.
            # Save this and attach the right parent page, after create.
            out.write("Remember page %r for later parent attach." % tree_entry)
            if old_parent_id not in parent_attach_data:
                parent_attach_data[old_parent_id] = [tree_entry]
            else:
                parent_attach_data[old_parent_id].append(tree_entry)

        #---------------------------------------------------------------------
        # create PageMeta entry

        pagemeta_entry = PageMeta(
            pagetree=tree_entry,
            language=language,
            name=old_page.name,
            title=old_page.title,
            keywords=old_page.keywords,
            description=old_page.description,

            # django-tagging can't handle case insensitive tags :(
            # So we get a duplicate entry IntegrityError an e.g.: "CGI, cgi"
            # work-a-round here: .lower() all tags :(
            # see: http://code.google.com/p/django-tagging/issues/detail?id=46
            tags=old_page.keywords.lower(),
            createtime=old_page.createtime,
            lastupdatetime=old_page.lastupdatetime,
            createby=old_page.createby,
            lastupdateby=old_page.lastupdateby,
        )
        pagemeta_entry.save()
        out.write("PageMeta entry '%s' - '%s' created." %
                  (language, tree_entry.slug))

        #---------------------------------------------------------------------
        # create PageContent or PluginPage entry

        if old_page.content.strip() == "{% lucidTag blog %}":
            # Create a blog plugin page, but only if there is no additional content
            tree_entry.page_type = PageTree.PLUGIN_TYPE
            tree_entry.save()

            new_pluginpage = PluginPage(
                app_label="pylucid_project.pylucid_plugins.blog")
            new_pluginpage.pagetree = tree_entry
            new_pluginpage.save()
            out.write("PluginPage entry 'blog' created for: %r" % tree_entry)
        else:
            # create PageContent entry
            content_entry = PageContent(
                pagemeta=pagemeta_entry,
                content=old_page.content,
                markup=old_page.markup,
                createtime=old_page.createtime,
                lastupdatetime=old_page.lastupdatetime,
                createby=old_page.createby,
                lastupdateby=old_page.lastupdateby,
            )
            content_entry.save()
            out.write("PageContent entry '%s' - '%s' created." %
                      (language, tree_entry.slug))
Beispiel #13
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
Beispiel #14
0
def _replace08URLs(request, language):
    """ replace old absolute page URLs with new permalink. """
    site = Site.objects.get_current()
    title = "Add %s permalink Redirect entries." % site.name
    out = SimpleStringIO()

    # get the dict with the information old page ID <-> new PageTree ID
    new_page_id_data = _get_page_id_data(site)

    old_pages = Page08.objects.only("id", "shortcut")
    old_absolute_urls = []
    url_to_new_id = {}  # old absolute url <-> new PageTree ID
    too_short_urls = []
    for old_page in old_pages:
        old_absolute_url = old_page.get_absolute_url()
        if old_page.parent == None:
            too_short_urls.append(old_absolute_url)
        else:
            url_to_new_id[old_absolute_url] = new_page_id_data[old_page.id]
            old_absolute_urls.append(old_absolute_url)

    out.write("Skip too short urls: %r" % too_short_urls)

    # sort from longest to shortest
    old_absolute_urls.sort(cmp=lambda x, y: cmp(len(x), len(y)), reverse=True)

    # Update only the PageContent objects from the current site.
    pages = PageContent.objects.filter(pagemeta__pagetree__site=site)
    count = 0
    permalink_cache = {}
    replace_data = []
    for pagecontent in pages:
        content = pagecontent.content

        for old_absolute_url in old_absolute_urls:
            if old_absolute_url in content:
                if old_absolute_url in permalink_cache:
                    permalink = permalink_cache[old_absolute_url]
                else:
                    page_tree_id = url_to_new_id[old_absolute_url]
                    page_tree = PageTree.objects.get(id=page_tree_id)
                    page_meta = PageMeta.objects.get(pagetree=page_tree,
                                                     language=language)
                    permalink = page_meta.get_permalink()
                    permalink_cache[old_absolute_url] = permalink

                page_absolute_url = pagecontent.get_absolute_url()

                content = content.replace(old_absolute_url, permalink)

                replace_data.append({
                    "old_absolute_url": old_absolute_url,
                    "permalink": permalink,
                    "page_absolute_url": page_absolute_url,
                })
                out.write("replace %r with %r in page %r" %
                          (old_absolute_url, permalink, page_absolute_url))

        if content == pagecontent.content:
            # Nothing changed
            continue
        count += 1
        pagecontent.content = content
        pagecontent.save()
        out.write("PageContent updated: %r\n" % pagecontent)

    out.write("\n%s PageContent items processed." % len(pages))
    out.write("%s items updated." % count)

    output = _get_output(request, out,
                         title)  # merge page_msg and log the complete output

    context = {
        "template_name": "pylucid_update/replace08URLs.html",
        "title": title,
        "site": site,
        "too_short_urls": too_short_urls,
        "replace_data": replace_data,
        "items_count": len(pages),
        "update_count": count,
    }
    return context
Beispiel #15
0
def update08pages(request):
    site = Site.objects.get_current()
    title = "Update %s PageContent" % site.name
    out = SimpleStringIO()

    # get the dict with the information old page ID <-> new PageTree ID
    new_page_id_data = _get_page_id_data(site)

    # Update only the PageContent objects from the current site.
    pages = PageContent.objects.filter(pagemeta__pagetree__site=site)
    count = 0
    delete_ids = []
    for pagecontent in pages:
        content = pagecontent.content

        content = _update_permalink(content, new_page_id_data)
        if content != pagecontent.content:
            out.write("Permalink in page %r updated." %
                      pagecontent.get_absolute_url())

        if "{% lucidTag blog %}" in content:
            # There exist additional content in this page -> don't delete it
            msg = (
                "*** You must manually convert page %s into a real blog plugin page!"
            ) % pagecontent.get_absolute_url()
            out.write(msg)

        content = _replace(content, out, "{% lucidTag page_update_list %}",
                           "{% lucidTag update_journal %}")
        content = _replace(content, out, "{% lucidTag page_update_list count=",
                           "{% lucidTag update_journal count=")
        content = _replace(content, out, "{% lucidTag RSS ",
                           "{% lucidTag rss ")
        if content == pagecontent.content:
            # Nothing changed
            continue
        count += 1
        pagecontent.content = content
        pagecontent.save()
        out.write("PageContent updated: %r\n" % pagecontent)

    if delete_ids:
        out.write("Delete %s obsolete PageContent items: %r" %
                  (len(delete_ids), delete_ids))
        PageContent.objects.filter(id__in=delete_ids).delete()

    out.write("\n%s PageContent items processed." % len(pages))
    out.write("%s items updated." % count)

    output = _get_output(request, out,
                         title)  # merge page_msg and log the complete output

    context = {
        "title": title,
        "site": site,
        "results": output,
    }
    return context
Beispiel #16
0
def update08pages(request):
    site = Site.objects.get_current()
    title = "Update %s PageContent" % site.name
    out = SimpleStringIO()

    # get the dict with the information old page ID <-> new PageTree ID
    new_page_id_data = _get_page_id_data(site)

    # Update only the PageContent objects from the current site.
    pages = PageContent.objects.filter(pagemeta__pagetree__site=site)
    count = 0
    delete_ids = []
    for pagecontent in pages:
        content = pagecontent.content

        content = _update_permalink(content, new_page_id_data)
        if content != pagecontent.content:
            out.write("Permalink in page %r updated." %
                      pagecontent.get_absolute_url())

        if "{% lucidTag blog %}" in content:
            # There exist additional content in this page -> don't delete it
            msg = (
                "*** You must manually convert page %s into a real blog plugin page!"
            ) % pagecontent.get_absolute_url()
            out.write(msg)

        content = _replace(content, out, "{% lucidTag page_update_list %}",
                           "{% lucidTag update_journal %}")
        content = _replace(content, out, "{% lucidTag page_update_list count=",
                           "{% lucidTag update_journal count=")
        content = _replace(content, out, "{% lucidTag RSS ",
                           "{% lucidTag rss ")
        if content == pagecontent.content:
            # Nothing changed
            continue
        count += 1
        pagecontent.content = content
        pagecontent.save()
        out.write("PageContent updated: %r\n" % pagecontent)

    if delete_ids:
        out.write("Delete %s obsolete PageContent items: %r" %
                  (len(delete_ids), delete_ids))
        PageContent.objects.filter(id__in=delete_ids).delete()

    out.write("\n%s PageContent items processed." % len(pages))
    out.write("%s items updated." % count)

    output = _get_output(request, out,
                         title)  # merge page_msg and log the complete output

    context = {
        "title": title,
        "site": site,
        "results": output,
    }
    return context
Beispiel #17
0
def _replace08URLs(request, language):
    """ replace old absolute page URLs with new permalink. """
    site = Site.objects.get_current()
    title = "Add %s permalink Redirect entries." % site.name
    out = SimpleStringIO()

    # get the dict with the information old page ID <-> new PageTree ID
    new_page_id_data = _get_page_id_data(site)

    old_pages = Page08.objects.only("id", "shortcut")
    old_absolute_urls = []
    url_to_new_id = {}  # old absolute url <-> new PageTree ID
    too_short_urls = []
    for old_page in old_pages:
        old_absolute_url = old_page.get_absolute_url()
        if old_page.parent == None:
            too_short_urls.append(old_absolute_url)
        else:
            url_to_new_id[old_absolute_url] = new_page_id_data[old_page.id]
            old_absolute_urls.append(old_absolute_url)

    out.write("Skip too short urls: %r" % too_short_urls)

    # sort from longest to shortest
    old_absolute_urls.sort(cmp=lambda x, y: cmp(len(x), len(y)), reverse=True)

    # Update only the PageContent objects from the current site.
    pages = PageContent.objects.filter(pagemeta__pagetree__site=site)
    count = 0
    permalink_cache = {}
    replace_data = []
    for pagecontent in pages:
        content = pagecontent.content

        for old_absolute_url in old_absolute_urls:
            if old_absolute_url in content:
                if old_absolute_url in permalink_cache:
                    permalink = permalink_cache[old_absolute_url]
                else:
                    page_tree_id = url_to_new_id[old_absolute_url]
                    page_tree = PageTree.objects.get(id=page_tree_id)
                    page_meta = PageMeta.objects.get(
                        pagetree=page_tree, language=language)
                    permalink = page_meta.get_permalink()
                    permalink_cache[old_absolute_url] = permalink

                page_absolute_url = pagecontent.get_absolute_url()

                content = content.replace(old_absolute_url, permalink)

                replace_data.append({
                    "old_absolute_url": old_absolute_url,
                    "permalink": permalink,
                    "page_absolute_url": page_absolute_url,
                })
                out.write("replace %r with %r in page %r" %
                          (old_absolute_url, permalink, page_absolute_url))

        if content == pagecontent.content:
            # Nothing changed
            continue
        count += 1
        pagecontent.content = content
        pagecontent.save()
        out.write("PageContent updated: %r\n" % pagecontent)

    out.write("\n%s PageContent items processed." % len(pages))
    out.write("%s items updated." % count)

    output = _get_output(request, out,
                         title)  # merge page_msg and log the complete output

    context = {
        "template_name": "pylucid_update/replace08URLs.html",
        "title": title,
        "site": site,
        "too_short_urls": too_short_urls,
        "replace_data": replace_data,
        "items_count": len(pages),
        "update_count": count,
    }
    return context
Beispiel #18
0
    try:
        if ext == "":
            lexer = lexers.guess_lexer(sourcecode)
        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
Beispiel #19
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
Beispiel #20
0
def base_check(request):
    out = SimpleStringIO()

    if settings.DEBUG:
        out.write(
            "*** Error: settings.DEBUG in on!"
            " (Should be off in productive environments!)"
        )
        out.write("\n" + _("more info:"))
        out.write(mark_safe('\t<a href="http://docs.djangoproject.com/en/dev/ref/settings/#debug">django documentation</a>'))
    else:
        out.write("settings.DEBUG, ok")
    out.write("\n" + "- " * 40)


    if settings.PYLUCID.I18N_DEBUG:
        out.write(
            "\n*** Error: pylucid app_settings.I18N_DEBUG is on!"
            " (Should be off in productive environments!)"
        )
    else:
        out.write("\npylucid app_settings.I18N_DEBUG, ok.")
    out.write("\n" + "- " * 40)


    if settings.SECRET_KEY == "":
        out.write(
            "\n*** Error: settings.SECRET_KEY not set!"
            " (You should add it into local-settings.py!)"
        )
        out.write("\n" + _("more info:"))
        out.write(mark_safe('\t<a href="http://docs.djangoproject.com/en/dev/ref/settings/#secret-key">django documentation</a>'))
    else:
        out.write("\nsettings.SECRET_KEY, ok.")
    out.write("\n" + "- " * 40)

    if "mysql" in settings.DATABASES['default']['ENGINE']:
        try:
            import MySQLdb
            out.write("MySQLdb.__version__  : %s" % repr(MySQLdb.__version__))
            out.write("MySQLdb.version_info : %s" % repr(MySQLdb.version_info))
        except Exception, err:
            out.write("MySQLdb info error: %s" % err)

        cursor = connection.cursor()
        out.write("\nSome MySQL encoding related variables:")

        for var_name in MYSQL_ENCODING_VARS:
            cursor.execute("SHOW VARIABLES LIKE %s;", (var_name,))
            raw_result = cursor.fetchall()
            try:
                result = raw_result[0][1]
            except IndexError, err:
                out.write("%30s: Error: %s (raw result: %r)" % (var_name, err, raw_result))
            else:
                out.write("%30s: %s" % (var_name, result))
Beispiel #21
0
    source_type = source_type.lower().strip("'\" ").lstrip(".")

    try:
        lexer = get_lexer(source_type, sourcecode)
    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
Beispiel #22
0
def update08migrate_stj(request):
    out = SimpleStringIO()
    site = Site.objects.get_current()
    title = "migrate v0.8 styles, templates, JS-SHA-Login data (on site: %s)" % site

    out.write("Move JS-SHA-Login data into new UserProfile\n")
    for old_entry in JS_LoginData08.objects.all():
        try:
            user = old_entry.user
        except User.DoesNotExist, err:
            out.write(
                "Old JS_LoginData08 User doesn't exist. Skip updating UserProfile."
            )
            continue

        userprofile, created = UserProfile.objects.get_or_create(user=user)
        if created:
            out.write("UserProfile for user '%s' created." % user.username)
        else:
            out.write("UserProfile for user '%s' exist." % user.username)

        if not userprofile.sha_login_checksum:
            # Add old sha login data, only if not exist.
            sha_login_checksum = old_entry.sha_checksum
            userprofile.sha_login_checksum = sha_login_checksum

            sha_login_salt = old_entry.salt
            userprofile.sha_login_salt = sha_login_salt

            userprofile.save()
            out.write("Add old JS-SHA-Login data.")