From 98cf461798c43edf5c6cb69ad8b093d11b45b937 Mon Sep 17 00:00:00 2001 From: Frank Loemker Date: Sat, 3 Mar 2018 09:36:00 -0500 Subject: [PATCH] Incorporated review comments: - Removed __future__, not needed anymore after the drop of python 2 support. - Use a setting for the [edit] link text, which defaults to a translated [edit]. - Changed link class name from article-edit to article-edit-title-link. - Removed empty constructor from the EditSectionPlugin class. - When testing basic models and tags don't rely on an active EditSection plugin. --- src/wiki/plugins/editsection/__init__.py | 2 -- src/wiki/plugins/editsection/apps.py | 2 -- .../editsection/markdown_extensions.py | 6 ++--- src/wiki/plugins/editsection/settings.py | 7 ++++-- src/wiki/plugins/editsection/views.py | 2 -- src/wiki/plugins/editsection/wiki_plugin.py | 5 ----- .../static/wiki/bootstrap/less/wiki/wiki.less | 2 +- testproject/testproject/settings/base.py | 2 +- tests/core/test_models.py | 6 ++--- tests/core/test_template_tags.py | 10 ++++----- tests/plugins/editsection/test_editsection.py | 22 +++++++++---------- 11 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/wiki/plugins/editsection/__init__.py b/src/wiki/plugins/editsection/__init__.py index c829665e..3435d0b2 100644 --- a/src/wiki/plugins/editsection/__init__.py +++ b/src/wiki/plugins/editsection/__init__.py @@ -1,3 +1 @@ -from __future__ import unicode_literals - default_app_config = 'wiki.plugins.editsection.apps.EditSectionConfig' diff --git a/src/wiki/plugins/editsection/apps.py b/src/wiki/plugins/editsection/apps.py index 518ec06f..0047f288 100644 --- a/src/wiki/plugins/editsection/apps.py +++ b/src/wiki/plugins/editsection/apps.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from django.apps import AppConfig from django.utils.translation import ugettext_lazy as _ diff --git a/src/wiki/plugins/editsection/markdown_extensions.py b/src/wiki/plugins/editsection/markdown_extensions.py index 8c5c2def..08ae4a05 100644 --- a/src/wiki/plugins/editsection/markdown_extensions.py +++ b/src/wiki/plugins/editsection/markdown_extensions.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import re from markdown import Extension from markdown.treeprocessors import Treeprocessor @@ -97,8 +95,8 @@ class EditSectionProcessor(Treeprocessor): # Insert link to allow editing this section link = etree.SubElement(child, 'a') - link.text = "[edit]" - link.attrib["class"] = "article-edit" + link.text = settings.LINK_TEXT + link.attrib["class"] = "article-edit-title-link" link.attrib["href"] = self.markdown.article.get_absolute_url() \ + "_plugin/editsection/" + location \ + "/header/" + header_id + "/" diff --git a/src/wiki/plugins/editsection/settings.py b/src/wiki/plugins/editsection/settings.py index c0155101..c007df9f 100644 --- a/src/wiki/plugins/editsection/settings.py +++ b/src/wiki/plugins/editsection/settings.py @@ -1,9 +1,12 @@ -from __future__ import absolute_import, unicode_literals - from django.conf import settings as django_settings +from django.utils.translation import gettext SLUG = 'editsection' #: Add "[edit]" links to all section headers till this level. By using #: these links editing only the text from the selected section is possible. MAX_LEVEL = getattr(django_settings, 'WIKI_EDITSECTION_MAX_LEVEL', 3) + +#: Text used for the section edit links which will appear next to section +#: headers. These links allow editing only the text of one particular section. +LINK_TEXT = getattr(django_settings, 'WIKI_EDITSECTION_LINK_TEXT', gettext("[edit]")) diff --git a/src/wiki/plugins/editsection/views.py b/src/wiki/plugins/editsection/views.py index 78a6059d..14eb37c3 100644 --- a/src/wiki/plugins/editsection/views.py +++ b/src/wiki/plugins/editsection/views.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, unicode_literals - import re from django.contrib import messages from django.shortcuts import get_object_or_404, redirect diff --git a/src/wiki/plugins/editsection/wiki_plugin.py b/src/wiki/plugins/editsection/wiki_plugin.py index 295651a5..9df6396c 100644 --- a/src/wiki/plugins/editsection/wiki_plugin.py +++ b/src/wiki/plugins/editsection/wiki_plugin.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, unicode_literals - from django.conf.urls import url from wiki.core.plugins import registry from wiki.core.plugins.base import BasePlugin @@ -19,8 +17,5 @@ class EditSectionPlugin(BasePlugin): markdown_extensions = [EditSectionExtension()] - def __init__(self): - pass - registry.register(EditSectionPlugin) diff --git a/src/wiki/static/wiki/bootstrap/less/wiki/wiki.less b/src/wiki/static/wiki/bootstrap/less/wiki/wiki.less index e7dd5605..098f705c 100644 --- a/src/wiki/static/wiki/bootstrap/less/wiki/wiki.less +++ b/src/wiki/static/wiki/bootstrap/less/wiki/wiki.less @@ -21,7 +21,7 @@ h1#article-title {font-size: 2.5em; margin-top: 0px;} -.article-edit {font-size: @font-size-base; padding-left: 8px} +.article-edit-title-link {font-size: @font-size-base; padding-left: 8px} .wiki-label label { font-size: 16px; font-weight: normal; color: #777;} diff --git a/testproject/testproject/settings/base.py b/testproject/testproject/settings/base.py index 7aca03b3..ce967af1 100644 --- a/testproject/testproject/settings/base.py +++ b/testproject/testproject/settings/base.py @@ -47,7 +47,7 @@ INSTALLED_APPS = [ "wiki.plugins.images.apps.ImagesConfig", "wiki.plugins.attachments.apps.AttachmentsConfig", "wiki.plugins.notifications.apps.NotificationsConfig", - 'wiki.plugins.editsection.apps.GlobalHistoryConfig', + 'wiki.plugins.editsection.apps.EditSectionConfig', 'wiki.plugins.globalhistory.apps.GlobalHistoryConfig', 'mptt', ] diff --git a/tests/core/test_models.py b/tests/core/test_models.py index 8cb3d1a8..91639490 100644 --- a/tests/core/test_models.py +++ b/tests/core/test_models.py @@ -134,8 +134,8 @@ class ArticleModelTest(TestCase): ArticleRevision.objects.create( article=a, title="test", content="# header" ) - expected_markdown = ( + expected = ( """

header""" - """[edit]

""" + """.*""" ) - self.assertEqual(a.get_cached_content(), expected_markdown) + self.assertRegexpMatches(a.get_cached_content(), expected) diff --git a/tests/core/test_template_tags.py b/tests/core/test_template_tags.py index 29490832..f7cafefd 100644 --- a/tests/core/test_template_tags.py +++ b/tests/core/test_template_tags.py @@ -195,10 +195,10 @@ class WikiRenderTest(TemplateTestCase): """========\n""" ) - expected_markdown = ( - """

This is a normal paragraph

\n""" + expected = ( + """(?s).*

This is a normal paragraph

\n""" """

Headline""" - """[edit]

""" + """.*.*""" ) # monkey patch @@ -208,14 +208,14 @@ class WikiRenderTest(TemplateTestCase): output = wiki_render({}, article, preview_content=content) self.assertCountEqual(self.keys, output) self.assertEqual(output['article'], article) - self.assertMultiLineEqual(output['content'], expected_markdown) + self.assertRegexpMatches(output['content'], expected) self.assertIs(output['preview'], True) self.assertEqual(output['plugins'], {'spam': 'eggs'}) self.assertEqual(output['STATIC_URL'], django_settings.STATIC_URL) self.assertEqual(output['CACHE_TIMEOUT'], settings.CACHE_TIMEOUT) output = self.render({'article': article, 'pc': content}) - self.assertIn(expected_markdown, output) + self.assertRegexpMatches(output, expected) def test_called_with_preview_content_and_article_dont_have_current_revision( self): diff --git a/tests/plugins/editsection/test_editsection.py b/tests/plugins/editsection/test_editsection.py index cb8b3aa1..d5b4007f 100644 --- a/tests/plugins/editsection/test_editsection.py +++ b/tests/plugins/editsection/test_editsection.py @@ -29,12 +29,12 @@ class EditSectionTests(RequireRootArticleMixin, DjangoClientTestBase): output = urlpath.article.render() expected = ( '(?s)' - 'Title 1\[edit\].*' - 'Title 2\[edit\].*' - 'Title 3\[edit\].*' - 'Title 4\[edit\].*' - 'Title 5\[edit\].*' - 'Title 6\[edit\].*' + 'Title 1\[edit\].*' + 'Title 2\[edit\].*' + 'Title 3\[edit\].*' + 'Title 4\[edit\].*' + 'Title 5\[edit\].*' + 'Title 6\[edit\].*' ) self.assertRegexpMatches(output, expected) @@ -84,12 +84,12 @@ class EditSectionEditTests(EditSectionEditBase, WebTestBase): self.submit('#id_save') expected = ( '(?s)' - 'Title 1\[edit\].*' - 'Title 2\[edit\].*' - 'Header 1\[edit\].*' + 'Title 1\[edit\].*' + 'Title 2\[edit\].*' + 'Header 1\[edit\].*' 'Content of the new section.*' - 'Title 5\[edit\].*' - 'Title 6\[edit\].*' + 'Title 5\[edit\].*' + 'Title 6\[edit\].*' ) self.assertRegexpMatches(self.last_response.content.decode('utf-8'), expected) -- 2.45.2