예제 #1
0
                converted_html = converter.apply_markup(
                    new_markup, dest_markup_no, request, escape_django_tags=True
                )
                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)

    context.update({
        "form": form,
    })
    return context
예제 #2
0
            return HttpResponse(msg)

        templatename = dbtemplate_obj.name

        template_path = self._filesystem_template_path(templatename)
        if template_path is None:
            msg = "Error: Template %r not found on filesystem." % templatename
            return HttpResponse(msg)

        try:
            filesystem_template = self._get_filesystem_template(template_path)
        except Exception, err:
            msg = "Error: Can't read %r: %s" % (template_path, err)
            return HttpResponse(msg)

        diff_html = hightlighter.get_pygmentize_diff(filesystem_template, edit_content)

        return HttpResponse(diff_html)

    def get_urls(self):
        """Returns the additional urls."""
        urls = super(DBTemplatesAdmin, self).get_urls()
        admin_site = self.admin_site
        opts = self.model._meta
        info = opts.app_label, opts.module_name
        new_urls = patterns("", url("^(.+)/diff/$", admin_site.admin_view(self.diff_view), name="%s_%s_diff" % info))
        return new_urls + urls

    def usage_info(self, obj):
        designs = models.Design.objects.all().filter(template=obj.name)
예제 #3
0
def _do_find_and_replace(request, context, find_string, replace_string, content_type, simulate, languages, sites):
    content_type_no = int(content_type)
    model_name = CONTENT_TYPES[content_type_no][0]
    model = CONTENT_TYPES_DICT[content_type_no]

    search_languages = Language.objects.filter(code__in=languages)

    queryset = model.objects.all()
    messages.info(
        request,
        _("%(count)s %(model_name)s entries total exist.") % {"count": queryset.count(), "model_name": model_name},
    )

    if model_name == u"PageContent":
        queryset = queryset.filter(pagemeta__language__in=search_languages)
        queryset = queryset.filter(pagemeta__pagetree__site__in=sites)
    elif model_name == u"EditableHtmlHeadFile":
        context["no_link"] = True
    else:
        queryset = queryset.filter(sites__in=sites)

    if model_name not in (u"PageContent", u"EditableHtmlHeadFile", u"DBTemplate"):
        queryset = queryset.filter(language__in=search_languages)

    filtered_count = queryset.count()
    messages.info(
        request,
        _("%(count)s %(model_name)s filtered entries found.") % {"count": filtered_count, "model_name": model_name},
    )
    if filtered_count == 0:
        return

    queryset = queryset.filter(content__contains=find_string)
    messages.info(
        request,
        _("%(count)s %(model_name)s entries contains 'find string'.")
        % {"count": queryset.count(), "model_name": model_name},
    )

    total_changes = 0
    changed_entry_count = 0
    results = []
    changed_entrys = []
    for entry in queryset:
        old_content = entry.content

        changes = old_content.count(find_string)
        if changes == 0:
            continue

        changed_entry_count += 1
        total_changes += changes

        new_content = old_content.replace(find_string, replace_string)
        if not simulate:
            # Save the find/replace result
            entry.content = new_content
            entry.save()
            changed_entrys.append(entry)

        diff_html = hightlighter.get_pygmentize_diff(old_content, new_content)

        results.append({"entry": entry, "changes": changes, "diff_html": diff_html})

    if total_changes > 0:
        messages.info(
            request,
            _("%(changes)s changes in %(count)s %(model_name)s entries.")
            % {"changes": total_changes, "count": changed_entry_count, "model_name": model_name},
        )
        if simulate:
            messages.info(request, "Simulate only, no entry changed.")

    context["results"] = results
    context["changed_entry_count"] = changed_entry_count
    context["total_changes"] = total_changes
예제 #4
0
            return HttpResponse(msg)

        templatename = dbtemplate_obj.name

        template_path = self._filesystem_template_path(templatename)
        if template_path is None:
            msg = "Error: Template %r not found on filesystem." % templatename
            return HttpResponse(msg)

        try:
            filesystem_template = self._get_filesystem_template(template_path)
        except Exception, err:
            msg = "Error: Can't read %r: %s" % (template_path, err)
            return HttpResponse(msg)

        diff_html = hightlighter.get_pygmentize_diff(filesystem_template,
                                                     edit_content)

        return HttpResponse(diff_html)

    def get_urls(self):
        """Returns the additional urls."""
        urls = super(DBTemplatesAdmin, self).get_urls()
        admin_site = self.admin_site
        opts = self.model._meta
        info = opts.app_label, opts.module_name,
        new_urls = patterns(
            "",
            url("^(.+)/diff/$",
                admin_site.admin_view(self.diff_view),
                name='%s_%s_diff' % info),
        )
예제 #5
0
def _do_find_and_replace(request, context, find_string, replace_string,
                         content_type, simulate, languages, sites):
    content_type_no = int(content_type)
    model_name = CONTENT_TYPES[content_type_no][0]
    model = CONTENT_TYPES_DICT[content_type_no]

    search_languages = Language.objects.filter(code__in=languages)

    queryset = model.objects.all()
    messages.info(
        request,
        _("%(count)s %(model_name)s entries total exist.") % {
            "count": queryset.count(),
            "model_name": model_name,
        })

    if model_name == u"PageContent":
        queryset = queryset.filter(pagemeta__language__in=search_languages)
        queryset = queryset.filter(pagemeta__pagetree__site__in=sites)
    elif model_name == u"BlogEntryContent":
        queryset = queryset.filter(entry__sites__in=sites)
    elif model_name == u"EditableHtmlHeadFile":
        context["no_link"] = True
    else:
        queryset = queryset.filter(sites__in=sites)

    if model_name not in (u"PageContent", u"EditableHtmlHeadFile",
                          u"DBTemplate"):
        queryset = queryset.filter(language__in=search_languages)

    filtered_count = queryset.count()
    messages.info(
        request,
        _("%(count)s %(model_name)s filtered entries found.") % {
            "count": filtered_count,
            "model_name": model_name,
        })
    if filtered_count == 0:
        return

    queryset = queryset.filter(content__contains=find_string)
    messages.info(
        request,
        _("%(count)s %(model_name)s entries contains 'find string'.") % {
            "count": queryset.count(),
            "model_name": model_name,
        })

    total_changes = 0
    changed_entry_count = 0
    results = []
    changed_entrys = []
    for entry in queryset:
        old_content = entry.content

        changes = old_content.count(find_string)
        if changes == 0:
            continue

        changed_entry_count += 1
        total_changes += changes

        new_content = old_content.replace(find_string, replace_string)
        if not simulate:
            # Save the find/replace result
            entry.content = new_content
            entry.save()
            changed_entrys.append(entry)

        diff_html = hightlighter.get_pygmentize_diff(old_content, new_content)

        results.append({
            "entry": entry,
            "changes": changes,
            "diff_html": diff_html,
        })

    if total_changes > 0:
        messages.info(
            request,
            _("%(changes)s changes in %(count)s %(model_name)s entries.") % {
                "changes": total_changes,
                "count": changed_entry_count,
                "model_name": model_name,
            })
        if simulate:
            messages.info(request, "Simulate only, no entry changed.")

    context["results"] = results
    context["changed_entry_count"] = changed_entry_count
    context["total_changes"] = total_changes
예제 #6
0
                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)

    context.update({
        "form": form,
    })
    return context