-
Notifications
You must be signed in to change notification settings - Fork 51
Additional Versioning Compatibility Changes #79
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
Aiky30
merged 123 commits into
django-cms:support/django-cms-4.0.x
from
adam-murray:feature/versionining-extra-code-tasks
Oct 14, 2021
Merged
Changes from all commits
Commits
Show all changes
123 commits
Select commit
Hold shift + click to select a range
6368d7e
Added cms_config versionable item and grouper
adam-murray 75449d6
Added admin, requirements for testing and requirements for running
adam-murray 9bc367c
Update
adam-murray 7c9455c
Fixed issue in setup.py and added basic first migration
adam-murray 4954ee4
Added migration to cms4
adam-murray 8defe7f
Added migration to cms4
adam-murray b9f822f
Began to implement versioning switch, added migration as part of mana…
adam-murray 49e4bb3
Moved data migration to management command, added util for versioning…
adam-murray dceee9f
Added tests for config as well as util for versioning check
adam-murray 7dfd721
Merge branch 'feature/versioned-snippets' into feature/snippet-data-m…
adam-murray 56adbdb
Updated cms_config
adam-murray 48e125f
Updated management command
adam-murray 5e12a63
Added form, updated model and forms to improve versioned and unversio…
adam-murray fdcde12
Updated migration, removed unecessary plugin
adam-murray 13547ae
Merged
adam-murray 9b73d59
Removed additional copies of files
adam-murray 680ce70
Split migration command into migration and command
adam-murray 8dc7f91
Updates to migration
adam-murray 6e937e8
Updates to migration
adam-murray 2df658b
Update migration for review
adam-murray 11a7d3e
Remove pdb
adam-murray d7c5dbb
Migration upgrade
adam-murray 8898232
Remove plugin from migration 10, added version creation
adam-murray 225b9f9
Implemented proper plugin migration
adam-murray 500cf72
Removed management command
adam-murray 2017d90
Migration 10 now handles lack of versioning gracefully.
adam-murray 25e552e
Add snippet property for backwards compatibility
adam-murray 59f82a8
Remove old foreign key from plugin, and rename new one
adam-murray 25048ff
Cleaned up migration and models
adam-murray 649c4af
Removed unecessary logging
adam-murray 061ebc4
Merged with target changes
adam-murray bc8d60e
Remove redundent comment
adam-murray 4103082
Update djangocms_snippet/migrations/0010_cms4_grouper_version_data_mi…
adam-murray ad25ec8
Update djangocms_snippet/migrations/0010_cms4_grouper_version_data_mi…
adam-murray 929d9d6
Update djangocms_snippet/migrations/0011_cms4_plugin_data_migration.py
adam-murray 8e624d9
Update djangocms_snippet/conf.py
adam-murray f7c848e
Update djangocms_snippet/migrations/0011_cms4_plugin_data_migration.py
adam-murray 85f96f2
Fixed variable name spelling mistake
adam-murray 669d34b
Merge branch 'feature/snippet-data-migration' of github.com:adam-murr…
adam-murray bea0a0a
Use util
adam-murray 9808226
Updated linting in migrations, and versioning enabled check
adam-murray 530e416
Added instructions for DJANGOCMS_SNIPPET_VERSIONING_MIGRATION_USER_ID…
adam-murray a3cdc9b
Added instructions for DJANGOCMS_SNIPPET_VERSIONING_MIGRATION_USER_ID…
adam-murray ce96a1f
Added instructions for DJANGOCMS_SNIPPET_VERSIONING_MIGRATION_USER_ID…
adam-murray c696c67
isort
adam-murray 3e3b736
Removed unecessary plugin
adam-murray 1aec683
Changed to version4 python version compatibility in test suite
adam-murray 7050f88
merge
adam-murray 53609d2
Updated to cms4 based test suite
adam-murray eac5cad
Merged
adam-murray 8dfb6db
Removed redundent abstract model
adam-murray ff5d635
Fixed app config issue
adam-murray c2f62de
Removed unused management command
adam-murray ef314fb
Removed management command
adam-murray 0ad68fe
Updates snippet tests for cms4
adam-murray f3943a3
linting
adam-murray a08485e
Removed unecessary published flag on page creation
adam-murray 7ff44b1
Merged
adam-murray 736b975
Push for testing
adam-murray 9dd2563
Updates to tests
adam-murray 4171e2e
Merged with versioned snippets
adam-murray 96035a3
Added factories, fixed model tests and templatetag tests
adam-murray 5b65538
Updated plugin tests
adam-murray aa62ced
Plugin tests now use factories
adam-murray 9fba572
Linting
adam-murray aeaa52a
Linting
adam-murray bdf4eaa
Fixed old issue with migrations
adam-murray aa5a54c
Fixed old issue with migrations
adam-murray 2d36a3b
Fixed spelling mistake
adam-murray a8f56f3
Updated test to no longer use factoris
adam-murray b87a0d6
Fixed rendering
adam-murray 7375e5b
Fixed migration error
adam-murray 03df8f7
Updated comments
adam-murray f895bf1
Migration linting
adam-murray e16c02c
Merge branch 'feature/snippet-data-migration' into feature/moderation…
adam-murray e4cf009
Made copy function test and started copy function
adam-murray 79eebf4
Remove unique=True from snipept slug field
adam-murray 6bf6557
Merge branch 'feature/snippet-data-migration' into feature/moderation…
adam-murray 38c211d
Removed unique=True on name
adam-murray 0cd495b
Enabled moderation, updates to cms_config
adam-murray 247ae36
Updated config test
adam-murray ee07ad5
Update djangocms_snippet/models.py
adam-murray 9b23fa8
Refactrogin
adam-murray 7cbaaa3
Merged
adam-murray 7cb6cc8
Linting
adam-murray b59a31d
Refactored test_plugin to closer to original
adam-murray 3153940
Refactoring tests
adam-murray 3d97dc8
Updated tests and migration to make grouper mandatory
adam-murray 366739b
Updated models to even with migrations
adam-murray 3853d19
Refactor
adam-murray e958a03
Linting
adam-murray d6b2a59
Merged with migration code
adam-murray dbfb808
Added migration and change for removing unique=True, allowing version…
adam-murray 8e599f3
Added checks for whether moderation is enabled
adam-murray 20ed1c8
Linting
adam-murray 463fd7c
Linting
adam-murray 32117b4
Updated test and versioning admin class generation
adam-murray 868030e
Implemented proper form and tests
adam-murray 5966b48
Remove commented out code
adam-murray f27255a
Fixed tests
adam-murray 1b9ddc7
Merged with release 4 branch
adam-murray 93c450c
Remoce Unique=True on slug and name
adam-murray 8e4db70
Merged with updated moderation integration
adam-murray 65a3175
Linting
adam-murray c61190c
iSort
adam-murray a500c9a
Added test criteria and comments for admin
adam-murray b8f7367
Fixed form save method issue found in manual testing
adam-murray 4ac015d
Push or placeholder problems
adam-murray e251685
Preview view and testcase
adam-murray 426510f
Linting
adam-murray 47dfedf
Linting and additional test case
adam-murray a6919e8
Update djangocms_snippet/views.py
adam-murray 7f65404
PR updates
adam-murray ade6c52
Merge branch 'feature/versionining-extra-code-tasks' of github.com:ad…
adam-murray 7dea453
Linting
adam-murray 7570829
Clean up admin class extension
adam-murray 6cb31ef
PR updates
adam-murray 9e5433f
Linitng
adam-murray 68f537f
Added comment to explain why cms_toolbar_models are required
adam-murray c5dcb04
Update djangocms_snippet/models.py
adam-murray d7e693e
Added commments to make end-to-end test clearer
adam-murray b9fe248
Merged
adam-murray e9e3394
Comment consistency
adam-murray 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 hidden or 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 hidden or 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 hidden or 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,61 @@ | ||
from django import forms | ||
from django.db import transaction | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from djangocms_snippet.cms_config import SnippetCMSAppConfig | ||
from djangocms_snippet.models import Snippet, SnippetGrouper | ||
|
||
|
||
try: | ||
from djangocms_versioning import __version__ # NOQA | ||
is_versioning_installed = True | ||
except ImportError: | ||
is_versioning_installed = False | ||
|
||
djangocms_versioning_enabled = SnippetCMSAppConfig.djangocms_versioning_enabled | ||
|
||
|
||
class SnippetForm(forms.ModelForm): | ||
class Meta: | ||
model = Snippet | ||
fields = ( | ||
"name", | ||
"html", | ||
"slug", | ||
"snippet_grouper", | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.fields["snippet_grouper"].required = False | ||
|
||
def clean(self): | ||
data = super().clean() | ||
name = data.get("name") | ||
slug = data.get("slug") | ||
snippet_grouper = data.get("snippet_grouper") | ||
snippet_queryset = Snippet.objects.all() | ||
|
||
if djangocms_versioning_enabled and is_versioning_installed: | ||
if snippet_grouper: | ||
snippet_queryset = snippet_queryset.exclude(snippet_grouper=snippet_grouper) | ||
|
||
for snippet in snippet_queryset: | ||
if snippet.name == name: | ||
self.add_error( | ||
"name", _("A Snippet with this name already exists") | ||
) | ||
elif snippet.slug == slug: | ||
self.add_error( | ||
"slug", _("A Snippet with this slug already exists") | ||
) | ||
|
||
return data | ||
|
||
@transaction.atomic | ||
def save(self, **kwargs): | ||
if not self.cleaned_data.get("snippet_grouper"): | ||
adam-murray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
super().save(commit=False) | ||
self.save_m2m() | ||
self.instance.snippet_grouper = SnippetGrouper.objects.create() | ||
return super().save() |
This file contains hidden or 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 hidden or 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,7 @@ | ||
from django.template.response import TemplateResponse | ||
|
||
|
||
def render_snippet(request, snippet): | ||
template = 'djangocms_snippet/admin/preview.html' | ||
context = {'snippet': snippet} | ||
return TemplateResponse(request, template, context) |
18 changes: 18 additions & 0 deletions
18
djangocms_snippet/templates/djangocms_snippet/admin/preview.html
This file contains hidden or 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,18 @@ | ||
{% extends "admin/base_site.html" %} | ||
{% load static %} | ||
{{ snippet.html|safe|escape }} | ||
|
||
{% block extrastyle %} | ||
{{ block.super }} | ||
<link rel="stylesheet" type="text/css" href="{% static "admin/css/changelists.css" %}"> | ||
{% endblock %} | ||
|
||
{% block coltype %}flex{% endblock %} | ||
|
||
{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-list{% endblock %} | ||
|
||
{% block content %} | ||
{% autoescape off %} | ||
{{ snippet.html }} | ||
{% endautoescape %} | ||
{% endblock %} |
This file contains hidden or 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,26 @@ | ||
from django.http import Http404 | ||
from django.views.generic import TemplateView | ||
|
||
from djangocms_snippet.models import Snippet | ||
|
||
|
||
class SnippetPreviewView(TemplateView): | ||
template_name = "djangocms_snippet/admin/preview.html" | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
adam-murray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
snippet_id = kwargs.get("snippet_id", None) | ||
|
||
if not snippet_id: | ||
Http404("snippet_id must be provided.") | ||
|
||
try: | ||
snippet = Snippet._base_manager.get(pk=self.kwargs.get("snippet_id")) | ||
except Snippet.DoesNotExist: | ||
raise Http404 | ||
|
||
context.update({ | ||
"snippet": snippet, | ||
"opts": Snippet._meta | ||
}) | ||
return context |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,53 @@ | ||
from importlib import reload | ||
|
||
from django.contrib import admin | ||
from django.test import RequestFactory, override_settings | ||
|
||
from cms.test_utils.testcases import CMSTestCase | ||
|
||
from djangocms_snippet import admin as snippet_admin | ||
from djangocms_snippet import cms_config | ||
from djangocms_snippet.models import Snippet | ||
|
||
from .utils.factories import SnippetWithVersionFactory | ||
|
||
|
||
class SnippetAdminTestCase(CMSTestCase): | ||
def setUp(self): | ||
self.snippet = SnippetWithVersionFactory() | ||
self.snippet_admin = snippet_admin.SnippetAdmin(Snippet, admin) | ||
self.snippet_admin_request = RequestFactory().get("/admin/djangocms_snippet") | ||
|
||
@override_settings(DJANGOCMS_SNIPPET_VERSIONING_ENABLED=False) | ||
adam-murray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def test_admin_list_display_without_versioning(self): | ||
""" | ||
Without versioning enabled, list_display should not be extended with version related items | ||
""" | ||
admin.site.unregister(Snippet) | ||
reload(cms_config) | ||
reload(snippet_admin) | ||
self.snippet_admin = snippet_admin.SnippetAdmin(Snippet, admin) | ||
|
||
list_display = self.snippet_admin.get_list_display(self.snippet_admin_request) | ||
|
||
self.assertEqual(self.snippet_admin.__class__.__bases__, (admin.ModelAdmin, )) | ||
self.assertEqual(list_display, ('slug', 'name')) | ||
|
||
@override_settings(DJANGOCMS_SNIPPET_VERSIONING_ENABLED=True) | ||
def test_admin_list_display_with_versioning(self): | ||
adam-murray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
With versioning enabled, list_display should be populated with both versioning related items, and the | ||
list actions items | ||
""" | ||
from djangocms_versioning.admin import ExtendedVersionAdminMixin | ||
list_display = self.snippet_admin.get_list_display(self.snippet_admin_request) | ||
|
||
# Mixins should always come first in the class bases | ||
self.assertEqual( | ||
self.snippet_admin.__class__.__bases__, (ExtendedVersionAdminMixin, admin.ModelAdmin) | ||
) | ||
self.assertEqual( | ||
list_display[:-1], ('slug', 'name', 'get_author', 'get_modified_date', 'get_versioning_state') | ||
) | ||
self.assertEqual(list_display[-1].short_description, 'actions') | ||
self.assertIn("function ExtendedVersionAdminMixin._list_actions", list_display[-1].__str__()) |
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.
Uh oh!
There was an error while loading. Please reload this page.