M src/wiki/compat.py => src/wiki/compat.py +21 -0
@@ 1,3 1,7 @@
+"""Abstraction layer to deal with Django related changes in order to keep
+compatibility with several Django versions simultaneously."""
+
+
try:
from django.urls import include, re_path as url
except ImportError:
@@ 5,5 9,22 @@ except ImportError:
__all__ = [
+ 'BuildAttrsCompat',
'include', 'url'
]
+
+
+# Django 1.11 Widget.build_attrs has a different signature, designed for the new
+# template based rendering. The previous version was more useful for our needs,
+# so we restore that version.
+# When support for Django < 1.11 is dropped, we should look at using the
+# new template based rendering, at which point this probably won't be needed at all.
+class BuildAttrsCompat:
+ def build_attrs_compat(self, extra_attrs=None, **kwargs):
+ "Helper function for building an attribute dictionary."
+ attrs = self.attrs.copy()
+ if extra_attrs is not None:
+ attrs.update(extra_attrs)
+ if kwargs is not None:
+ attrs.update(kwargs)
+ return attrs
D src/wiki/core/compat.py => src/wiki/core/compat.py +0 -22
@@ 1,22 0,0 @@
-"""Abstraction layer to deal with Django related changes in order to keep
-compatibility with several Django versions simultaneously."""
-from django.conf import settings as django_settings
-from urllib.parse import urljoin # noqa
-
-USER_MODEL = getattr(django_settings, 'AUTH_USER_MODEL', 'auth.User')
-
-
-# Django 1.11 Widget.build_attrs has a different signature, designed for the new
-# template based rendering. The previous version was more useful for our needs,
-# so we restore that version.
-# When support for Django < 1.11 is dropped, we should look at using the
-# new template based rendering, at which point this probably won't be needed at all.
-class BuildAttrsCompat:
- def build_attrs_compat(self, extra_attrs=None, **kwargs):
- "Helper function for building an attribute dictionary."
- attrs = self.attrs.copy()
- if extra_attrs is not None:
- attrs.update(extra_attrs)
- if kwargs is not None:
- attrs.update(kwargs)
- return attrs
M src/wiki/editors/markitup.py => src/wiki/editors/markitup.py +1 -1
@@ 4,7 4,7 @@ from django.utils.encoding import force_text
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
-from wiki.core.compat import BuildAttrsCompat
+from wiki.compat import BuildAttrsCompat
from wiki.editors.base import BaseEditor
M src/wiki/forms.py => src/wiki/forms.py +1 -1
@@ 23,8 23,8 @@ from django.utils.translation import gettext_lazy as _
from wiki import models
from wiki.conf import settings
+from wiki.compat import BuildAttrsCompat
from wiki.core import permissions
-from wiki.core.compat import BuildAttrsCompat
from wiki.core.diff import simple_merge
from wiki.core.plugins.base import PluginSettingsFormMixin
from wiki.editors import getEditor
M src/wiki/models/article.py => src/wiki/models/article.py +4 -3
@@ 1,3 1,4 @@
+from django.conf import settings as django_settings
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core.cache import cache
@@ 11,7 12,7 @@ from django.utils.translation import gettext_lazy as _
from mptt.models import MPTTModel
from wiki import managers
from wiki.conf import settings
-from wiki.core import compat, permissions
+from wiki.core import permissions
from wiki.core.markdown import article_markdown
from wiki.decorators import disable_signal_for_loaddata
@@ 37,7 38,7 @@ class Article(models.Model):
help_text=_('Article properties last modified'))
owner = models.ForeignKey(
- compat.USER_MODEL, verbose_name=_('owner'),
+ django_settings.AUTH_USER_MODEL, verbose_name=_('owner'),
blank=True, null=True, related_name='owned_articles',
help_text=_(
'The owner of the article, usually the creator. The owner always has both read and write access.'),
@@ 288,7 289,7 @@ class BaseRevisionMixin(models.Model):
blank=True,
null=True,
editable=False)
- user = models.ForeignKey(compat.USER_MODEL, verbose_name=_('user'),
+ user = models.ForeignKey(django_settings.AUTH_USER_MODEL, verbose_name=_('user'),
blank=True, null=True,
on_delete=models.SET_NULL)
M src/wiki/views/article.py => src/wiki/views/article.py +1 -1
@@ 1,5 1,6 @@
import difflib
import logging
+from urllib.parse import urljoin
from django.contrib import messages
from django.contrib.auth.decorators import login_required
@@ 18,7 19,6 @@ from django.views.generic.list import ListView
from wiki import editors, forms, models
from wiki.conf import settings
from wiki.core import permissions
-from wiki.core.compat import urljoin
from wiki.core.diff import simple_merge
from wiki.core.exceptions import NoRootURL
from wiki.core.paginator import WikiPaginator