~netlandish/django-wiki

88d284f3b20c754173db59e905b9847fc41585e6 — Benjamin Bach 4 years ago 6846328
Improve some user-facing messages, add r'..' to regular expression
M src/wiki/plugins/editsection/markdown_extensions.py => src/wiki/plugins/editsection/markdown_extensions.py +4 -2
@@ 1,14 1,16 @@
import re

from markdown import Extension
from markdown.treeprocessors import Treeprocessor
from markdown.util import etree

from . import settings


class EditSectionExtension(Extension):
    def __init__(self, *args, **kwargs):
        self.config = {
            'level': [settings.MAX_LEVEL, 'Allow to edit sections till this level'],
            'level': [settings.MAX_LEVEL, 'Allow to edit sections until this level'],
            'headers': None,     # List of FindHeader, all headers with there positions
            'location': None,    # To be extracted header
            'header_id': None,   # Header text ID of the to be extracted header


@@ 22,7 24,7 @@ class EditSectionExtension(Extension):


def get_header_id(header):
    header_id = ''.join(w[0] for w in re.findall("\w+", header))
    header_id = ''.join(w[0] for w in re.findall(r"\w+", header))
    if not len(header_id):
        return '_'
    return header_id

M src/wiki/plugins/editsection/views.py => src/wiki/plugins/editsection/views.py +18 -9
@@ 3,7 3,7 @@ import re
from django.contrib import messages
from django.shortcuts import get_object_or_404, redirect
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.utils.translation import gettext_lazy
from wiki import models
from wiki.core.markdown import article_markdown
from wiki.core.plugins.registry import get_markdown_extensions


@@ 13,6 13,20 @@ from wiki.views.article import Edit as EditView

from . import settings

ERROR_SECTION_CHANGED = gettext_lazy(
    "Unable to find the selected section. The article was modified meanwhile."
)
ERROR_SECTION_UNSAVED = gettext_lazy(
    "Your changes must be re-applied in the new section structure of the "
    "article."
)
ERROR_ARTICLE_CHANGED = gettext_lazy(
    "Unable to find the selected section in the current article. The article "
    "was changed in between. Your changed section is still available as the "
    "last now inactive revision of this article."
)
ERROR_TRY_AGAIN = gettext_lazy("Please try again.")


class FindHeader:
    """Locate the start, header text, and end of the header text of the next


@@ 111,8 125,7 @@ class EditSection(EditView):
            else:
                messages.error(
                    request,
                    _("Unable to find the selected section in the current article."
                      " The article was changed in between. Please try again.")
                    " ".format(ERROR_SECTION_CHANGED, ERROR_TRY_AGAIN)
                )
                return redirect('wiki:get', path=self.urlpath.path)
        else:


@@ 138,9 151,7 @@ class EditSection(EditView):
                list(messages.get_messages(self.request))
                messages.warning(
                    self.request,
                    _("The selected text section was changed in between."
                      " Please check the history of the article and reinclude"
                      " required changes from the intermediate versions.")
                    " ".format(ERROR_SECTION_CHANGED, ERROR_SECTION_UNSAVED, ERROR_TRY_AGAIN)
                )
            # Include the edited section into the complete previous article
            self.article.current_revision.content = text[0:location[0]] + section + text[location[1]:]


@@ 152,9 163,7 @@ class EditSection(EditView):
            list(messages.get_messages(self.request))
            messages.error(
                self.request,
                _("Unable to find the selected section in the current article. The article"
                  " was changed in between. Your changed section is still available as the"
                  " last now inactive revision of this article. Please try again.")
                " ".format(ERROR_ARTICLE_CHANGED, ERROR_TRY_AGAIN)
            )

        return redirect('wiki:get', path=self.urlpath.path)