-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pass current revision to Editor.get_widget/get_admin_widget - #1249
* Pass current revision to Editor.get_widget()/get_admin_widget() Sometimes it is useful to have the current revision in the editor widget instance, for example to create preview and upload links, autocomplete, etc. <textarea name="content" data-upload-url='/wiki/my-page/_plugin/attachments/...'> Previously, EditorBase had an instance attribute "instance", but that doesn't make sense (there is only one global instance of Editor) and wasn't ever filled anyway. This patch removes that, renames the "instance" parameter in get_widget()/get_admin_widget() to "revision" (to make clear what this parameter is) and fills it appropriately and also add tests to improve coverage.
- Loading branch information
Showing
5 changed files
with
87 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import wiki.editors | ||
from django.forms import Textarea | ||
from wiki.editors.base import BaseEditor | ||
|
||
from ..base import RequireRootArticleMixin | ||
from ..base import WebTestBase | ||
from ..base import wiki_override_settings | ||
|
||
|
||
class CustomEditor(BaseEditor): | ||
def get_widget(self, revision=None): | ||
return Textarea(attrs={"data-revision": revision.pk}) | ||
|
||
def get_admin_widget(self, revision=None): | ||
return Textarea(attrs={"data-revision": revision.pk}) | ||
|
||
|
||
class EditorTest(RequireRootArticleMixin, WebTestBase): | ||
def setUp(self): | ||
super().setUp() | ||
# reset the cached editor class and instance | ||
wiki.editors._editor, wiki.editors._EditorClass = None, None | ||
|
||
def test_editor_widget_markitup(self): | ||
response = self.get_url("wiki:edit", path="") | ||
self.assertContains( | ||
response, | ||
'<textarea name="content" class="markItUp" rows="10" cols="40" id="id_content">', | ||
) | ||
|
||
def test_admin_widget_markitup(self): | ||
response = self.get_url( | ||
"admin:wiki_articlerevision_change", | ||
object_id=self.root_article.current_revision.id, | ||
) | ||
self.assertContains( | ||
response, | ||
'<textarea name="content" class="markItUp" rows="10" cols="40" id="id_content">', | ||
) | ||
|
||
@wiki_override_settings(WIKI_EDITOR="wiki.editors.base.BaseEditor") | ||
def test_editor_widget_base(self): | ||
response = self.get_url("wiki:edit", path="") | ||
self.assertContains( | ||
response, '<textarea name="content" cols="40" rows="10" id="id_content">' | ||
) | ||
|
||
@wiki_override_settings(WIKI_EDITOR="wiki.editors.base.BaseEditor") | ||
def test_admin_widget_base(self): | ||
response = self.get_url( | ||
"admin:wiki_articlerevision_change", | ||
object_id=self.root_article.current_revision.id, | ||
) | ||
self.assertContains( | ||
response, '<textarea name="content" cols="40" rows="10" id="id_content">' | ||
) | ||
|
||
@wiki_override_settings(WIKI_EDITOR="tests.core.test_editor.CustomEditor") | ||
def test_editor_widget_custom(self): | ||
response = self.get_url("wiki:edit", path="") | ||
self.assertContains( | ||
response, | ||
'<textarea name="content" cols="40" rows="10" data-revision="{}" id="id_content">'.format( | ||
self.root_article.current_revision.id | ||
), | ||
) | ||
|
||
@wiki_override_settings(WIKI_EDITOR="tests.core.test_editor.CustomEditor") | ||
def test_admin_widget_custom(self): | ||
response = self.get_url( | ||
"admin:wiki_articlerevision_change", | ||
object_id=self.root_article.current_revision.id, | ||
) | ||
self.assertContains( | ||
response, | ||
'<textarea name="content" cols="40" rows="10" data-revision="{}" id="id_content">'.format( | ||
self.root_article.current_revision.id | ||
), | ||
) |