-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CopyView not prefilling the form data for snippets #11943
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
) | ||
from .models import ( # noqa: F401 | ||
CopyView, | ||
CopyViewMixin, | ||
CreateView, | ||
DeleteView, | ||
EditView, | ||
|
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 |
---|---|---|
|
@@ -35,7 +35,6 @@ | |
) | ||
from wagtail.snippets.blocks import SnippetChooserBlock | ||
from wagtail.snippets.models import SNIPPET_MODELS, register_snippet | ||
from wagtail.snippets.views.snippets import CopyView | ||
from wagtail.snippets.widgets import ( | ||
AdminSnippetChooser, | ||
SnippetChooserAdapter, | ||
|
@@ -974,20 +973,29 @@ def setUp(self): | |
StandardSnippet.snippet_viewset.get_url_name("copy"), | ||
args=(self.snippet.pk,), | ||
) | ||
self.login() | ||
self.user = self.login() | ||
|
||
def test_without_permission(self): | ||
self.user.is_superuser = False | ||
self.user.save() | ||
admin_permission = Permission.objects.get( | ||
content_type__app_label="wagtailadmin", codename="access_admin" | ||
) | ||
self.user.user_permissions.add(admin_permission) | ||
|
||
def test_simple(self): | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertRedirects(response, reverse("wagtailadmin_home")) | ||
|
||
def test_form_is_prefilled(self): | ||
response = self.client.get(self.url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTemplateUsed(response, "wagtailsnippets/snippets/create.html") | ||
|
||
def test_form_prefilled(self): | ||
request = RequestFactory().get(self.url) | ||
view = CopyView() | ||
view.model = StandardSnippet | ||
view.setup(request, pk=self.snippet.pk) | ||
|
||
self.assertEqual(view._get_initial_form_instance(), self.snippet) | ||
# Ensure form is prefilled | ||
soup = self.get_soup(response.content) | ||
text_input = soup.select_one('input[name="text"]') | ||
self.assertEqual(text_input.attrs.get("value"), "Test snippet") | ||
Comment on lines
+978
to
+998
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This copies the same test from |
||
|
||
|
||
@override_settings(WAGTAIL_I18N_ENABLED=True) | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract this into a mixin so the snippets view can just mix this into its
CreateView
.Would be nice to unify this along with how we do our "detail" views, which currently does this in different ways...
Comparison
EditView
falls back into the first positional arg if the URL conf does not provide thepk_url_kwarg
:wagtail/wagtail/admin/views/generic/models.py
Lines 737 to 741 in a09bba6
DeleteView
has an optimisation since it loads the object so soon insetup()
:wagtail/wagtail/admin/views/generic/models.py
Lines 951 to 958 in a09bba6
InspectView
:wagtail/wagtail/admin/views/generic/models.py
Lines 1054 to 1061 in a09bba6
RevisionCompareView
:wagtail/wagtail/admin/views/generic/models.py
Lines 1183 to 1191 in a09bba6
UnpublishView
:wagtail/wagtail/admin/views/generic/models.py
Lines 1286 to 1298 in a09bba6
RevisionUnscheduleView
:wagtail/wagtail/admin/views/generic/models.py
Lines 1394 to 1404 in a09bba6
#10746 and #11590 would be something to consider as well. Although, I'm wondering, if we're going to refactor
PermissionCheckedMixin
to make use ofModelPermissionTester
when possible (to allow instance-specific application-level permission checks) when wagtail/rfcs#92 is implemented, how would that affect where we put db call...