diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b4f6752..a3bf1414 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,13 +8,10 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ 3.7, 3.8, 3.9, ] # latest release minus two + python-version: [ 3.6, 3.7, ] requirements-file: [ - dj22_cms37.txt, - dj22_cms38.txt, - dj30_cms37.txt, - dj30_cms38.txt, - dj31_cms38.txt, + dj11_cms40.txt, + dj22_cms40.txt, ] os: [ ubuntu-20.04, diff --git a/djangocms_snippet/cms_config.py b/djangocms_snippet/cms_config.py new file mode 100644 index 00000000..cf87874d --- /dev/null +++ b/djangocms_snippet/cms_config.py @@ -0,0 +1,24 @@ +from django.conf import settings + +from cms.app_base import CMSAppConfig + +from .models import Snippet + + +class SnippetCMSAppConfig(CMSAppConfig): + djangocms_versioning_enabled = getattr( + settings, 'DJANGOCMS_SNIPPET_VERSIONING_ENABLED', False + ) + + if djangocms_versioning_enabled: + from djangocms_versioning.datastructures import ( + VersionableItem, default_copy, + ) + + versioning = [ + VersionableItem( + content_model=Snippet, + grouper_field_name="snippet_grouper", + copy_function=default_copy, + ) + ] diff --git a/djangocms_snippet/migrations/0009_auto_20210811_0942.py b/djangocms_snippet/migrations/0009_auto_20210811_0942.py new file mode 100644 index 00000000..2107cc34 --- /dev/null +++ b/djangocms_snippet/migrations/0009_auto_20210811_0942.py @@ -0,0 +1,25 @@ +# Generated by Django 2.2.24 on 2021-08-11 09:42 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangocms_snippet', '0008_auto_change_name'), + ] + + operations = [ + migrations.CreateModel( + name='SnippetGrouper', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + ), + migrations.AddField( + model_name='snippet', + name='snippet_grouper', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='djangocms_snippet.SnippetGrouper'), + ), + ] diff --git a/djangocms_snippet/models.py b/djangocms_snippet/models.py index 23f27144..83c18a38 100644 --- a/djangocms_snippet/models.py +++ b/djangocms_snippet/models.py @@ -9,6 +9,10 @@ SEARCH_ENABLED = getattr(settings, 'DJANGOCMS_SNIPPET_SEARCH', False) +class SnippetGrouper(models.Model): + pass + + # Stores the actual data class Snippet(models.Model): """ @@ -19,6 +23,11 @@ class Snippet(models.Model): unique=True, max_length=255, ) + snippet_grouper = models.ForeignKey( + SnippetGrouper, + on_delete=models.PROTECT, + null=True, + ) html = models.TextField( verbose_name=_('HTML'), blank=True, @@ -62,8 +71,7 @@ class SnippetPtr(CMSPlugin): parent_link=True, on_delete=models.CASCADE, ) - - snippet = models.ForeignKey(Snippet, on_delete=models.CASCADE,) + snippet = models.ForeignKey(Snippet, on_delete=models.CASCADE) search_fields = ['snippet__html'] if SEARCH_ENABLED else [] diff --git a/setup.py b/setup.py index 9e41005e..566bc2cb 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ REQUIREMENTS = [ - 'django-cms>=3.7', + 'django-cms', 'django-treebeard>=4.3,<4.5', ] diff --git a/tests/requirements/dj11_cms40.txt b/tests/requirements/dj11_cms40.txt new file mode 100644 index 00000000..4c9d6c95 --- /dev/null +++ b/tests/requirements/dj11_cms40.txt @@ -0,0 +1,4 @@ +-r base.txt + +https://github.com/django-cms/django-cms/tarball/release/4.0.x#egg=django-cms +https://github.com/divio/djangocms-versioning/tarball/master/#egg=djangocms-versioning diff --git a/tests/requirements/dj22_cms40.txt b/tests/requirements/dj22_cms40.txt new file mode 100644 index 00000000..c84c4174 --- /dev/null +++ b/tests/requirements/dj22_cms40.txt @@ -0,0 +1,5 @@ +-r base.txt + +Django>=2.2,<3.0 +https://github.com/django-cms/django-cms/tarball/release/4.0.x#egg=django-cms +https://github.com/divio/djangocms-versioning/tarball/master/#egg=djangocms-versioning diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 6e4e6767..2e971d10 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -13,14 +13,13 @@ def setUp(self): template="page.html", language=self.language, ) - self.home.publish(self.language) self.page = create_page( title="help", template="page.html", language=self.language, ) - self.page.publish(self.language) - self.placeholder = self.page.placeholders.get(slot="content") + self.pagecontent = self.page.pagecontent_set.first() + self.placeholder = self.pagecontent.placeholders.get(slot="content") self.superuser = self.get_superuser() def tearDown(self): @@ -36,12 +35,12 @@ def test_html_rendering(self): slug="plugin_snippet", ) plugin = add_plugin( - self.page.placeholders.get(slot="content"), + self.pagecontent.placeholders.get(slot="content"), "SnippetPlugin", self.language, snippet=snippet, ) - self.page.publish(self.language) + self.assertEqual(plugin.snippet.name, "plugin_snippet") self.assertEqual(plugin.snippet.html, "
Hello World
") self.assertEqual(plugin.snippet.slug, "plugin_snippet") @@ -59,12 +58,11 @@ def test_failing_html_rendering(self): slug="plugin_snippet", ) add_plugin( - self.page.placeholders.get(slot="content"), + self.pagecontent.placeholders.get(slot="content"), "SnippetPlugin", self.language, snippet=snippet, ) - self.page.publish(self.language) with self.login_user_context(self.superuser): response = self.client.get(request_url) @@ -82,12 +80,11 @@ def test_template_rendering(self): ) snippet.save() plugin = add_plugin( - self.page.placeholders.get(slot="content"), + self.pagecontent.placeholders.get(slot="content"), "SnippetPlugin", self.language, snippet=snippet, ) - self.page.publish(self.language) self.assertEqual(plugin.snippet.name, "plugin_snippet") self.assertEqual(plugin.snippet.slug, "plugin_snippet") @@ -109,12 +106,11 @@ def test_failing_template_rendering(self): ) snippet.save() add_plugin( - self.page.placeholders.get(slot="content"), + self.pagecontent.placeholders.get(slot="content"), "SnippetPlugin", self.language, snippet=snippet, ) - self.page.publish(self.language) with self.login_user_context(self.superuser): response = self.client.get(request_url)