Skip to content

Commit

Permalink
fix: Fixed bug that causes ChangeView not to use SnippetForm (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-murray authored Oct 14, 2021
1 parent e215e01 commit d2b1b63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion djangocms_snippet/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.forms import Textarea

from .cms_config import SnippetCMSAppConfig
from .forms import SnippetForm
from .models import Snippet
from .views import SnippetPreviewView

Expand Down Expand Up @@ -33,7 +34,7 @@ class SnippetAdmin(*snippet_admin_classes):
'data-mode': getattr(settings, 'DJANGOCMS_SNIPPET_THEME', 'html'),
'data-theme': getattr(settings, 'DJANGOCMS_SNIPPET_MODE', 'github'),
}

form = SnippetForm
formfield_overrides = {
models.TextField: {'widget': Textarea(attrs=text_area_attrs)}
}
Expand Down
1 change: 1 addition & 0 deletions djangocms_snippet/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Meta:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["snippet_grouper"].required = False
self.fields["snippet_grouper"].widget = forms.HiddenInput()

def clean(self):
data = super().clean()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from djangocms_snippet import admin as snippet_admin
from djangocms_snippet import cms_config
from djangocms_snippet.forms import SnippetForm
from djangocms_snippet.models import Snippet

from .utils.factories import SnippetWithVersionFactory
Expand Down Expand Up @@ -51,3 +52,10 @@ def test_admin_list_display_with_versioning(self):
)
self.assertEqual(list_display[-1].short_description, 'actions')
self.assertIn("function ExtendedVersionAdminMixin._list_actions", list_display[-1].__str__())

def test_admin_uses_form(self):
"""
The SnippetForm provides functionality to make SnippetGroupers irrelevant to the user,
ensure the admin uses this.
"""
self.assertEqual(self.snippet_admin.form, SnippetForm)

0 comments on commit d2b1b63

Please sign in to comment.