Skip to content
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

Additional Versioning Compatibility Changes #79

Conversation

adam-murray
Copy link
Contributor

This PR includes additional changes required to implement versioning and moderation, as well as making it fully compatible without.

adam-murray and others added 30 commits August 9, 2021 13:12
@codecov-commenter
Copy link

codecov-commenter commented Sep 17, 2021

Codecov Report

Merging #79 (c5dcb04) into support/django-cms-4.0.x (4fd5662) will decrease coverage by 1.96%.
The diff coverage is 84.09%.

Impacted file tree graph

@@                     Coverage Diff                      @@
##           support/django-cms-4.0.x      #79      +/-   ##
============================================================
- Coverage                     92.18%   90.21%   -1.97%     
============================================================
  Files                            21       24       +3     
  Lines                           243      327      +84     
  Branches                         13       21       +8     
============================================================
+ Hits                            224      295      +71     
- Misses                           14       25      +11     
- Partials                          5        7       +2     
Impacted Files Coverage Δ
djangocms_snippet/rendering.py 40.00% <40.00%> (ø)
djangocms_snippet/models.py 94.28% <75.00%> (-5.72%) ⬇️
djangocms_snippet/forms.py 87.17% <87.17%> (ø)
djangocms_snippet/views.py 87.50% <87.50%> (ø)
djangocms_snippet/admin.py 93.10% <88.23%> (-6.90%) ⬇️
djangocms_snippet/cms_config.py 84.21% <100.00%> (+9.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4fd5662...c5dcb04. Read the comment docs.

Copy link
Collaborator

@Aiky30 Aiky30 left a comment

Choose a reason for hiding this comment

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

I haven't had chance to look at the tests yet due to the support issues that are still open.

)

snippet_admin_classes = [
AbstractSnippetAdmin,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused as to why we have an abstract class that is not reused, could this not be:

Suggested change
AbstractSnippetAdmin,
admin.ModelAdmin,

abstract = True


djangocms_versioning_enabled = getattr(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is normally done by the cms_config, you can then just call the config for the package and see if it's enabled rather than repeat the settings implementation: https://github.com/divio/djangocms-alias/blob/master/djangocms_alias/cms_config.py#L22

except ImportError:
is_versioning_installed = False

djangocms_versioning_enabled = getattr(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, this is set in the cms config. If we just had a setting it would live in conf.py but as this is in the cms_config we should use that as the centralised control.

name = data.get("name")
slug = data.get("slug")
snippet_grouper = data.get("snippet_grouper")
published_snippet_queryset = Snippet.objects.all()
Copy link
Collaborator

Choose a reason for hiding this comment

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

The phrase published_snippet_queryset is misleading because this is not a published queryset if versioning is not enabled.

djangocms_snippet/forms.py Show resolved Hide resolved
from djangocms_snippet.views import SnippetPreviewView


urlpatterns = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

djangocms_snippet/views.py Show resolved Hide resolved
Copy link
Collaborator

@Aiky30 Aiky30 left a comment

Choose a reason for hiding this comment

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

Overall a really good effort and good test coverage.

A few minor points:

  • Some reworking of the logic for visual
  • I don't think that the settings overrides are actually working. I tend to have to patch to get them to work. Changing the default settings will confirm this.
  • An additional integration test

djangocms_snippet/admin.py Show resolved Hide resolved
tests/test_admin.py Show resolved Hide resolved
tests/test_admin.py Show resolved Hide resolved
tests/test_forms.py Show resolved Hide resolved
tests/test_forms.py Show resolved Hide resolved
tests/test_forms.py Show resolved Hide resolved
tests/test_forms.py Show resolved Hide resolved
tests/test_views.py Show resolved Hide resolved
djangocms_snippet/models.py Outdated Show resolved Hide resolved
"""
Snippet forms should be valid regardless of the versions, or states which already exist within its grouper.
"""
snippet_to_archive = SnippetWithVersionFactory()
Copy link
Collaborator

@Aiky30 Aiky30 Oct 14, 2021

Choose a reason for hiding this comment

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

I'm confused by this logic. snippet_to_publish is draft with the same grouper and there is then another draft created on line 23.

The same grouper has 1 published version and 2 drafts which doesn't make sense.

It's easier to follow if you force the version state:
archived = SnippetWithVersionFactory(version__state=ARCHIVED)
published = SnippetWithVersionFactory(version__state=PUBLISHED, snippet_grouper=archived.snippet_grouper)
draft = SnippetWithVersionFactory(version__state=DRAFT, snippet_grouper=archived.snippet_grouper)

The test should also prove when using the slug is invalid too, it would go on to add:

    # Another grouper tries to use the same slug value
    new_grouper_published = SnippetWithVersionFactory(version__state=PUBLISHED)

    form_data = {
        "name": new_grouper_published.name,
        "slug": draft.slug,
        "html": new_grouper_published.html,
        "snippet_grouper": new_grouper_published.snippet_grouper.id,
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that's actually the case, I tested in the debugger. The created Snippets have the correct states.

Copy link
Collaborator

@Aiky30 Aiky30 Oct 14, 2021

Choose a reason for hiding this comment

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

# snippet_to_archive starts draft
snippet_to_archive = SnippetWithVersionFactory()

# snippet_to_archive then gets published
snippet_to_archive.versions.first().publish(user=self.get_superuser())

# snippet_to_publish is a new draft
snippet_to_publish = SnippetWithVersionFactory(snippet_grouper=snippet_to_archive.snippet_grouper)

# We now create another new draft int he same grouper
SnippetWithVersionFactory(snippet_grouper=snippet_to_publish.snippet_grouper)

Copy link
Collaborator

@Aiky30 Aiky30 Oct 14, 2021

Choose a reason for hiding this comment

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

Also in none of the new versions are the slugs the same

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also missed that before, the slug should be the same in each version.


form = SnippetForm(form_data)

self.assertTrue(form.is_valid())
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test should also prove when using the slug is invalid too, it would go on to add:

# Another grouper tries to use the same slug value
new_grouper_published = SnippetWithVersionFactory(version__state=PUBLISHED)

form_data = {
    "name": new_grouper_published.name,
    "slug": draft.slug,
    "html": new_grouper_published.html,
    "snippet_grouper": new_grouper_published.snippet_grouper.id,
}

@Aiky30 Aiky30 merged commit e215e01 into django-cms:support/django-cms-4.0.x Oct 14, 2021
fsbraun added a commit that referenced this pull request Aug 20, 2024
* djangocms-versioning compatibility - Initial Model and cms_config implementation (#75)

* feat: Snippet CMS 4.0 and djangocms-versioning Data migration (#74)

* feat: Moderation compatibility and version copy method implementation (#77)

* feat: Versioning Compatibility Changes (#79)

* fix: Fixed bug that causes ChangeView not to use SnippetForm (#80)

* feat: Reworked form fields and added the ability to show draft snippets (#81)

* fix: Adding valid HTML to the add snippet form throws an error (#82)

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

* fix: History URL button broken link on the Snippets change form (#84)

* fix: Draft snippet render error due to draft snippets (#86)

* feat: Default versioning import user id setting can be set via environment variable (#89)

* Release 4.0.0.dev1 (#91)

* fix: django-cms 4.0.x - Remove breaking django-treebeard pinning issue (#93)

* Release 4.0.0.dev2 (#95)

* feat: Removing slug field and hyperlink from list display when versioning is enabled (#98)

* fix: Snippet plugin showing ID instead of name(#100)

* Fix: Compare view removed unnecessary template logic (#101)

* Release 4.0.0.dev3 (#103)

* feat: Preview icon renders content in read only  (#102)

* Release 4.0.0.dev4 (#109)

* fix: Added test coverage to admin preview view (#96)

* port-feat: pre-commit config added from the v3 workstream (#117)

Changes partially taken from this change: a56091c

Requires additional work when the django-cms 4.0 workstream is official, the version bump code has been ignored because it would generate official releases only: #116

* feat: django-cms 4.0.x - django 3.2 and Python 3.9 compatibility  (#92)

* Release 4.0.1.dev1 (#119)

* feat: Enable add button on the SnippetPluginForm (#127)

* Release 4.0.1.dev2 (#128)

* init support for django4.2 (#150)

* init support for django4.2

* add change log for add compatiable for django 4.2 and python 3.10

* Update CHANGELOG.rst

* Update .pre-commit-config.yaml

* fix lint config issue

* remove test code

* add blackline for flake8

* add pyproject.toml file

* add requirement files

* fix ci failed issue

* format setup.py import section

* upgrade isort version to fix pre commit ci issue

* upgrade the django-upgrade package to pass through the pre commit ci test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* upgrade packages in pre commit

* resort init file changes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* comment the django-upgrade from ci

* fix: add missing migration file

* fix: update previous file instead of creating new file

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Josh Peng Yu <[email protected]>

* fix pyproject.toml config error (#151)

* Added site field in models n site filter in admin (#159)

* Added site field in models n site filter in admin

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* updated versioning branch

* Add test cases and updated the implementation

* Update CHANGELOG.rst

Co-authored-by: Mark Walker <[email protected]>

* corrected formatting

* fixed flake8 issues

* removed list_filter

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Mark Walker <[email protected]>

* Release/4.1.0 (#155)

* bump version to 4.1.0

* bump version to 4.1.0 pyproject.toml

* replace test requirement url

* update changelog date

* update release date.

* Update README.rst

* Update README.rst

* Create PULL_REQUEST_TEMPLATE.md (#85)

Add PR template

* Only include badges at the top to avoid confusion & removed old badges like travis. (#106)

* Added pypi github actions (#108)

* FEATURE: adjust setup metadata (#110)

* correct doc about default value of DJANGOCMS_SNIPPET_CACHE (#120)

* Update to ace 1.9.6, load ace editor from static files if djangocms_static_ace is installed, add dark mode (#123)

Fix:		Load ace editor from static files if `djangocms-static-ace` is installed
Fix:		Respect if user has set dark mode
Add:	Weak dependency on djangocms-static-ace
Doc:	optional static-ace dependency

* ci: Update pypi action branch names (#125)

* Bump version: 3.0.0 → 3.1.0 (#126)

* fix: django-cms 3.x - Remove breaking django-treebeard pinning issue (#94)

* Removed pinning.

* Update setup.py

---------

Co-authored-by: Fabian Braun <[email protected]>

* fix: add noop django 4 migration (#134)

* fix: add noop django 4 migration

* fix: isort

* ci: Prepare release of version 3.1.1 (#139)

* Update CHANGELOG.rst

* Bump version

* Pin treebeard for Django CMS 3.7 tests

* Update dj30_cms37.txt

* chore: Package overhaul (#140)

* ci: Update pre-commit

* ci: Run ruff formatter

* build: Move package in to src dir

* test: Update requirements building

* chore: Keeping git happy after moving to src

* ci: Add dependabot config

* ci: Update tests to run tox

* build: Project config

* test: Update tox setup

* build: Update setup to build_meta

* ci: Update pypi workflows

* ci: Update linter to ruff

* chore: Fix RUF012

* ci: Update linter trigger

* chore: Drop python 3.8

* chore: Drop python 3.8

* chore: Adjust coverage config

* fix: Test pypi workflow

* Bump actions/setup-python from 4 to 5 (#148)

Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](actions/setup-python@v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: Test only for migrations within package

* Update tests

* run tests on all branches

* fix tests

* Update readme, changelog

* Fix common test suite for django CMS 3.11, 4.0, and 4.1

* Update CHANGELOG

* Merge branches together

* Update precommit-config

* fix: ruff precommit

* ci: auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

* fix: ruff issues

* More ruff fixes

* Update pyproject.toml

* ci: auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

* fix: Remove isort and flake8 from setup.cfg

* ci: auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

* Update setup.cfg

* Fix: universal branch (#167)

* fix: manifest.in

* fix: SnippetAdmin use overrdden change_form_template

* ci: auto fixes from pre-commit hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Update lint workflow

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Adam Murray <[email protected]>
Co-authored-by: Aiky30 <[email protected]>
Co-authored-by: Bernard Van Der Vyver <[email protected]>
Co-authored-by: Michael Collins <[email protected]>
Co-authored-by: 傅瑞曼 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Josh Peng Yu <[email protected]>
Co-authored-by: Vipul Narang <[email protected]>
Co-authored-by: Mark Walker <[email protected]>
Co-authored-by: Nicolai <[email protected]>
Co-authored-by: Kaushal Dhungel <[email protected]>
Co-authored-by: Simon Krull <[email protected]>
Co-authored-by: Liumeo <[email protected]>
Co-authored-by: Mark Walker <[email protected]>
Co-authored-by: Patrik <[email protected]>
Co-authored-by: Mark Walker <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Josh Yu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants