Skip to content

Commit

Permalink
fix: Adds compatibility for User models with no username field [#292] (
Browse files Browse the repository at this point in the history
…#293)

* fix: Compatibility with User models which have no `username` field. #292
* Update changelog

Co-authored-by: Fabian Braun <fsbraun@gmx.de>
  • Loading branch information
marksweb and fsbraun authored Dec 9, 2022
1 parent 4e5b1c4 commit 3e6fb53
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Unreleased
* ci: Update actions to v3 where possible, and coverage to v2 due to v1 sunset in Feb
* ci: Remove ``os`` from test workflow matrix because it's unused
* ci: Added concurrency option to cancel in progress runs when new changes occur
* fix: Added setting to make the field to identify a user configurable in ``ExtendedVersionAdminMixin.get_queryset()`` to fix issue for custom user models with no ``username``
* ci: Run tests on sqlite, mysql and postgres db

* feat: Compatibility with page content extension changes to django-cms
Expand Down
4 changes: 3 additions & 1 deletion djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from cms.utils.urlutils import add_url_parameters

from . import versionables
from .conf import USERNAME_FIELD
from .constants import DRAFT, PUBLISHED
from .exceptions import ConditionFailed
from .forms import grouper_form_factory
Expand Down Expand Up @@ -137,7 +138,8 @@ def get_queryset(self, request):
queryset = super().get_queryset(request)
# Due to django admin ordering using unicode, to alphabetically order regardless of case, we must
# annotate the queryset, with the usernames all lower case, and then order based on that!
queryset = queryset.annotate(created_by_username_ordering=Lower("versions__created_by__username"))

queryset = queryset.annotate(created_by_username_ordering=Lower(f"versions__created_by__{USERNAME_FIELD}"))
return queryset

def get_version(self, obj):
Expand Down
4 changes: 4 additions & 0 deletions djangocms_versioning/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
ENABLE_MENU_REGISTRATION = getattr(
settings, "DJANGOCMS_VERSIONING_ENABLE_MENU_REGISTRATION", True
)

USERNAME_FIELD = getattr(
settings, "DJANGOCMS_VERSIONING_USERNAME_FIELD", 'username'
)
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ exclude =
__pycache__,
**/migrations/,
build/,
.env,
env,
.tox/,
.venv,
venv,

[isort]
Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ skip_missing_interpreters=True
deps =
-r{toxinidir}/tests/requirements/requirements_base.txt

dj22: -r{toxinidir}/tests/requirements/django_22.txt
dj32: -r{toxinidir}/tests/requirements/django_32.txt
dj22: -r{toxinidir}/tests/requirements/dj22_cms40.txt
dj32: -r{toxinidir}/tests/requirements/dj32_cms40.txt

basepython =
py37: python3.7
Expand Down

0 comments on commit 3e6fb53

Please sign in to comment.