Skip to content

fix: form initialisation error in read-only mode #83

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
6b142d1
Added missing field for form
adam-murray Oct 14, 2021
253cddc
Fixed form
adam-murray Oct 15, 2021
a6f8329
Fixed form save method
adam-murray Oct 15, 2021
291bc94
Added model property for snippet grouper
adam-murray Oct 15, 2021
1fe4fbf
Added fix for bug in demo
adam-murray Oct 15, 2021
b281e45
Update djangocms_snippet/forms.py
adam-murray Oct 15, 2021
3c8fa93
Added test case for verisoning state machine snippet/page
adam-murray Oct 15, 2021
7032daf
added test case for snippet version rendering
adam-murray Oct 15, 2021
6723e57
Fixed issue with form save method and updated tests.
adam-murray Oct 15, 2021
62d1c2f
Removed unused factories
adam-murray Oct 15, 2021
3451165
Updated plugin test cases
adam-murray Oct 15, 2021
bfc3b6e
Remove unused import in factories
adam-murray Oct 15, 2021
c779f3f
Simplified from unecessary helpers
adam-murray Oct 18, 2021
d0b975e
Removed unused helpers
adam-murray Oct 18, 2021
4d926f2
added test case for forms with commit=False
adam-murray Oct 18, 2021
f3609a6
updated test case
adam-murray Oct 18, 2021
5862325
Remove debugger
adam-murray Oct 18, 2021
c5a97cd
Refactored plugin tests
adam-murray Oct 18, 2021
3f1fbb2
Updated snippet fetch method to get return appropriate snipper versio…
adam-murray Oct 19, 2021
c9cb424
Linting
adam-murray Oct 19, 2021
8900700
Updated old comments
adam-murray Oct 19, 2021
3acf07f
Updated to check requests in models
adam-murray Oct 19, 2021
2b0331c
Updated snippet grouper snippet method
adam-murray Oct 19, 2021
333f5cb
remove unused code
adam-murray Oct 19, 2021
928c738
Updated endpoint logic
adam-murray Oct 19, 2021
3bc134b
Linting
adam-murray Oct 19, 2021
77a6080
Updated SnipeptGrouper snippet method, and added comments
adam-murray Oct 19, 2021
d8aad53
Add additional logic to prevent archived content being returned befor…
adam-murray Oct 20, 2021
59f3b6a
Updated Comment
adam-murray Oct 20, 2021
d67d31a
Updated Comment
adam-murray Oct 20, 2021
c31fca7
Comment Update tests/test_plugins.py
adam-murray Oct 20, 2021
6f579ea
Suggestions from code review
adam-murray Oct 20, 2021
7fd5e40
Updated comment in models.
adam-murray Oct 20, 2021
82962b4
Added filtering for correct version states in grouper snippet return …
adam-murray Oct 20, 2021
35456da
Update model so we don't have to pass the request object to the grouper
adam-murray Oct 20, 2021
4e4d840
Updated render method to prevent request object being passed to models.
adam-murray Oct 20, 2021
08c5939
removed unused property, added __str__ method back on grouper
adam-murray Oct 20, 2021
cc60686
Updated test criteria to reflect removal of property on plugin
adam-murray Oct 20, 2021
def0196
Fixed test criteria
adam-murray Oct 20, 2021
b180d62
Added solution and test case for form save method
adam-murray Oct 21, 2021
001c0bc
Merged in updates
adam-murray Oct 21, 2021
4da7894
Removed test which made incorrect assumption about versioning admin
adam-murray Oct 21, 2021
71b129b
Added back test, but with appropriate criteria
adam-murray Oct 21, 2021
41dac36
Linting
adam-murray Oct 21, 2021
01aefd3
Updated test criteria
adam-murray Oct 21, 2021
315292e
fix: form initialisation in read-only mode throwing error
adam-murray Oct 21, 2021
34a33ff
Merge branch 'support/django-cms-4.0.x' into bugfix/form-initialisati…
adam-murray Oct 21, 2021
4d5d133
fix: Updated comments explaining admin form test
adam-murray Oct 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions djangocms_snippet/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ class Meta:

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["snippet_grouper"].required = False
self.fields["snippet_grouper"].widget = forms.HiddenInput()
if self.fields.get("snippet_grouper"):
self.fields["snippet_grouper"].required = False
self.fields["snippet_grouper"].widget = forms.HiddenInput()

def clean(self):
data = super().clean()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,19 @@ def test_admin_form_save_method(self):
# We should have 2 groupers and snippets, due to the creation of the others in setUp
self.assertEqual(Snippet._base_manager.count(), 2)
self.assertEqual(SnippetGrouper._base_manager.count(), 2)

@override_settings(DJANGOCMS_SNIPPET_VERSIONING_ENABLED=True)
def test_admin_form_edit_when_locked(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this test exist, when you can answer that please add it to the test.

"""
When a form is initialised in read-only mode, it should not require self.fields to be populated, and
should return a read-only form.
"""
self.snippet_version.publish(user=self.superuser)
with self.login_user_context(self.superuser):
edit_url = reverse("admin:djangocms_snippet_snippet_change", args=(self.snippet.id,),)
response = self.client.get(edit_url)

# Check that we are loading in readonly mode
self.assertContains(response, '<div class="readonly">Test Snippet</div>')
# We should have the same number of snippets as before
self.assertEqual(Snippet.objects.count(), 1)