From d5c8c5dc4a7350a6d59a1166c26eb1c4375ff0b1 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Thu, 13 Oct 2016 01:10:41 +0200 Subject: [PATCH] Remove old deprecated stuff --- wiki/conf/settings.py | 8 +---- wiki/core/compat.py | 34 ++----------------- wiki/decorators.py | 2 +- wiki/forms.py | 10 ++---- wiki/models/article.py | 3 -- wiki/models/pluginbase.py | 22 ------------ wiki/models/urlpath.py | 1 - .../attachments/markdown_extensions.py | 2 +- wiki/plugins/attachments/models.py | 4 --- wiki/plugins/attachments/settings.py | 6 ++-- wiki/plugins/images/markdown_extensions.py | 2 +- wiki/plugins/images/models.py | 4 --- wiki/plugins/images/settings.py | 5 ++- wiki/plugins/macros/mdx/macro.py | 2 +- wiki/plugins/notifications/models.py | 2 -- wiki/plugins/notifications/settings.py | 5 ++- wiki/tests/test_models.py | 17 +++------- 17 files changed, 22 insertions(+), 107 deletions(-) diff --git a/wiki/conf/settings.py b/wiki/conf/settings.py index 8e9699d9..4c4de36f 100644 --- a/wiki/conf/settings.py +++ b/wiki/conf/settings.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, unicode_literals -import django from django.conf import settings as django_settings from django.core.files.storage import default_storage from django.core.urlresolvers import reverse_lazy @@ -10,7 +9,6 @@ from django.utils.translation import ugettext_lazy as _ URL_CASE_SENSITIVE = getattr(django_settings, 'WIKI_URL_CASE_SENSITIVE', False) # Non-configurable (at the moment) -APP_LABEL = 'wiki' WIKI_LANGUAGE = 'markdown' # The editor class to use -- maybe a 3rd party or your own...? You can always @@ -175,11 +173,7 @@ SEARCH_VIEW = getattr( CACHE_TIMEOUT = getattr(django_settings, 'WIKI_CACHE_TIMEOUT', 600) # Choose the Group model to use. Defaults to django's auth.Group -# This requires `django.apps` which was introduced in Django 1.7. -if django.VERSION < (1, 7): - GROUP_MODEL = 'auth.Group' -else: - GROUP_MODEL = getattr(django_settings, 'WIKI_GROUP_MODEL', 'auth.Group') +GROUP_MODEL = getattr(django_settings, 'WIKI_GROUP_MODEL', 'auth.Group') ################### # SPAM PROTECTION # diff --git a/wiki/core/compat.py b/wiki/core/compat.py index 9239ffec..74e3ce27 100644 --- a/wiki/core/compat.py +++ b/wiki/core/compat.py @@ -2,27 +2,16 @@ compatibility with several Django versions simultaneously.""" from __future__ import absolute_import, unicode_literals -from django import VERSION as DJANGO_VERSION from django.conf import settings as django_settings from django.db import transaction -# Django 1.5+ -if DJANGO_VERSION >= (1, 5): - USER_MODEL = getattr(django_settings, 'AUTH_USER_MODEL', 'auth.User') -else: - USER_MODEL = 'auth.User' +USER_MODEL = getattr(django_settings, 'AUTH_USER_MODEL', 'auth.User') def get_user_model(): - if DJANGO_VERSION >= (1, 5): - from django.contrib.auth import get_user_model as gum - return gum() - else: - from django.contrib.auth.models import User - if 'USERNAME_FIELD' not in User.__dict__: - User.USERNAME_FIELD = 'username' - return User + from django.contrib.auth import get_user_model as gum + return gum() # Django 1.6 transaction API, required for 1.8+ @@ -38,20 +27,3 @@ try: except AttributeError: atomic = nop_decorator transaction_commit_on_success = transaction.commit_on_success - - -if DJANGO_VERSION < (1, 8): - from django.template.loader import render_to_string as django_render_to_string - from django.template import Context, RequestContext - - # Similar to 1.8 signature, but with things we can support - # under 1.7 and less. - def render_to_string(template_name, context=None, request=None): - if request is not None: - context_instance = RequestContext(request, context) - else: - context_instance = Context(context) - return django_render_to_string(template_name, - context_instance=context_instance) -else: - from django.template.loader import render_to_string # noqa @UnusedImport diff --git a/wiki/decorators.py b/wiki/decorators.py index 7eadb11a..c94e416b 100644 --- a/wiki/decorators.py +++ b/wiki/decorators.py @@ -8,10 +8,10 @@ from django.core.urlresolvers import reverse from django.http import (HttpResponse, HttpResponseForbidden, HttpResponseNotFound, HttpResponseRedirect) from django.shortcuts import get_object_or_404, redirect +from django.template.loader import render_to_string from django.utils.http import urlquote from six.moves import filter from wiki.conf import settings -from wiki.core.compat import render_to_string from wiki.core.exceptions import NoRootURL diff --git a/wiki/forms.py b/wiki/forms.py index 89438cf0..e5bd634a 100644 --- a/wiki/forms.py +++ b/wiki/forms.py @@ -7,6 +7,7 @@ from datetime import timedelta from itertools import chain from django import forms +from django.apps import apps from django.contrib.auth.forms import UserCreationForm from django.core.urlresolvers import Resolver404, resolve from django.forms.widgets import HiddenInput @@ -32,14 +33,7 @@ except ImportError: User = get_user_model() - -# Backwards compatibility with Django < 1.7 -try: - from django.apps import apps -except ImportError: - from django.contrib.auth.models import Group -else: - Group = apps.get_model(settings.GROUP_MODEL) +Group = apps.get_model(settings.GROUP_MODEL) # Due to deprecation of django.forms.util in Django 1.9 try: diff --git a/wiki/models/article.py b/wiki/models/article.py index 8b612d3c..a8c52de2 100644 --- a/wiki/models/article.py +++ b/wiki/models/article.py @@ -192,7 +192,6 @@ class Article(models.Model): return str(obj_name) class Meta: - app_label = settings.APP_LABEL permissions = ( ("moderate", _("Can edit all articles and lock/unlock/restore")), ("assign", _("Can change ownership of any article")), @@ -253,7 +252,6 @@ class ArticleForObject(models.Model): return "{}".format(self.article) class Meta: - app_label = settings.APP_LABEL verbose_name = _('Article for object') verbose_name_plural = _('Articles for object') # Do not allow several objects @@ -372,7 +370,6 @@ class ArticleRevision(BaseRevisionMixin, models.Model): self.locked = predecessor.locked class Meta: - app_label = settings.APP_LABEL get_latest_by = 'revision_number' ordering = ('created',) unique_together = ('article', 'revision_number') diff --git a/wiki/models/pluginbase.py b/wiki/models/pluginbase.py index 53cb3260..ab95b0f0 100644 --- a/wiki/models/pluginbase.py +++ b/wiki/models/pluginbase.py @@ -24,7 +24,6 @@ from __future__ import absolute_import, unicode_literals from django.db import models from django.db.models import signals from django.utils.translation import ugettext_lazy as _ -from wiki.conf import settings from wiki.decorators import disable_signal_for_loaddata from .article import ArticleRevision, BaseRevisionMixin @@ -62,11 +61,6 @@ class ArticlePlugin(models.Model): """Remove related contents completely, ie. media files.""" pass - class Meta: - # Override this setting with app_label = '' in your extended model - # if it lives outside the wiki app. - app_label = settings.APP_LABEL - class ReusablePlugin(ArticlePlugin): @@ -108,11 +102,6 @@ class ReusablePlugin(ArticlePlugin): def can_moderate(self, user): return self.article.can_moderate(user) if self.article else False - class Meta: - # Override this setting with app_label = '' in your extended model - # if it lives outside the wiki app. - app_label = settings.APP_LABEL - class SimplePluginCreateError(Exception): pass @@ -156,11 +145,6 @@ class SimplePlugin(ArticlePlugin): def get_logmessage(self): return _("A plugin was changed") - class Meta: - # Override this setting with app_label = '' in your extended model - # if it lives outside the wiki app. - app_label = settings.APP_LABEL - class RevisionPlugin(ArticlePlugin): @@ -208,11 +192,6 @@ class RevisionPlugin(ArticlePlugin): if save: self.save() - class Meta: - # Override this setting with app_label = '' in your extended model - # if it lives outside the wiki app. - app_label = settings.APP_LABEL - class RevisionPluginRevision(BaseRevisionMixin, models.Model): @@ -228,7 +207,6 @@ class RevisionPluginRevision(BaseRevisionMixin, models.Model): class Meta: # Override this setting with app_label = '' in your extended model # if it lives outside the wiki app. - app_label = settings.APP_LABEL get_latest_by = 'revision_number' ordering = ('-created',) diff --git a/wiki/models/urlpath.py b/wiki/models/urlpath.py index e3371bf4..a90fc40f 100644 --- a/wiki/models/urlpath.py +++ b/wiki/models/urlpath.py @@ -201,7 +201,6 @@ class URLPath(MPTTModel): verbose_name = _('URL path') verbose_name_plural = _('URL paths') unique_together = ('site', 'parent', 'slug') - app_label = settings.APP_LABEL def clean(self, *args, **kwargs): if self.slug and not self.parent: diff --git a/wiki/plugins/attachments/markdown_extensions.py b/wiki/plugins/attachments/markdown_extensions.py index b1f773a0..87832f33 100644 --- a/wiki/plugins/attachments/markdown_extensions.py +++ b/wiki/plugins/attachments/markdown_extensions.py @@ -5,7 +5,7 @@ import re import markdown from django.contrib.auth.models import AnonymousUser from django.core.urlresolvers import reverse -from wiki.core.compat import render_to_string +from django.template.loader import render_to_string from wiki.core.permissions import can_read from wiki.plugins.attachments import models diff --git a/wiki/plugins/attachments/models.py b/wiki/plugins/attachments/models.py index 81124d5c..3f0bbdb0 100644 --- a/wiki/plugins/attachments/models.py +++ b/wiki/plugins/attachments/models.py @@ -54,8 +54,6 @@ class Attachment(ReusablePlugin): verbose_name_plural = _('attachments') # Matches label of upcoming 0.1 release db_table = 'wiki_attachments_attachment' - if settings.APP_LABEL: - app_label = settings.APP_LABEL def __str__(self): from wiki.models import Article @@ -140,8 +138,6 @@ class AttachmentRevision(BaseRevisionMixin, models.Model): get_latest_by = 'revision_number' # Matches label of upcoming 0.1 release db_table = 'wiki_attachments_attachmentrevision' - if settings.APP_LABEL: - app_label = settings.APP_LABEL def get_filename(self): """Used to retrieve the filename of a revision. diff --git a/wiki/plugins/attachments/settings.py b/wiki/plugins/attachments/settings.py index 9f6d1ec3..174b5a35 100644 --- a/wiki/plugins/attachments/settings.py +++ b/wiki/plugins/attachments/settings.py @@ -1,12 +1,12 @@ from __future__ import absolute_import, unicode_literals -from django import VERSION from django.conf import settings as django_settings from django.core.exceptions import ImproperlyConfigured from wiki.conf import settings as wiki_settings -# This is not used in django 1.7+ -APP_LABEL = 'attachments' if VERSION < (1, 7) else None +# Deprecated +APP_LABEL = None + SLUG = "attachments" # Please see this note about support for UTF-8 files on django/apache: diff --git a/wiki/plugins/images/markdown_extensions.py b/wiki/plugins/images/markdown_extensions.py index 180219ef..9a1bed59 100644 --- a/wiki/plugins/images/markdown_extensions.py +++ b/wiki/plugins/images/markdown_extensions.py @@ -4,7 +4,7 @@ from __future__ import absolute_import, unicode_literals import re import markdown -from wiki.core.compat import render_to_string +from django.template.loader import render_to_string from wiki.plugins.images import models IMAGE_RE = re.compile( diff --git a/wiki/plugins/images/models.py b/wiki/plugins/images/models.py index d70692d2..645fee03 100644 --- a/wiki/plugins/images/models.py +++ b/wiki/plugins/images/models.py @@ -49,8 +49,6 @@ class Image(RevisionPlugin): verbose_name = _('image') verbose_name_plural = _('images') db_table = 'wiki_images_image' # Matches label of upcoming 0.1 release - if settings.APP_LABEL: - app_label = settings.APP_LABEL def __str__(self): if self.current_revision: @@ -114,8 +112,6 @@ class ImageRevision(RevisionPluginRevision): verbose_name_plural = _('image revisions') # Matches label of upcoming 0.1 release db_table = 'wiki_images_imagerevision' - if settings.APP_LABEL: - app_label = settings.APP_LABEL ordering = ('-created',) def __str__(self): diff --git a/wiki/plugins/images/settings.py b/wiki/plugins/images/settings.py index e00a6a54..0b2cd666 100644 --- a/wiki/plugins/images/settings.py +++ b/wiki/plugins/images/settings.py @@ -1,13 +1,12 @@ from __future__ import absolute_import, unicode_literals -from django import VERSION from django.conf import settings as django_settings from wiki.conf import settings as wiki_settings SLUG = 'images' -# This is deprecated in django 1.7+ -APP_LABEL = 'images' if VERSION < (1, 7) else None +# Deprecated +APP_LABEL = None # Where to store images IMAGE_PATH = getattr(django_settings, 'WIKI_IMAGES_PATH', "wiki/images/%aid/") diff --git a/wiki/plugins/macros/mdx/macro.py b/wiki/plugins/macros/mdx/macro.py index b851afca..9912088e 100644 --- a/wiki/plugins/macros/mdx/macro.py +++ b/wiki/plugins/macros/mdx/macro.py @@ -4,9 +4,9 @@ from __future__ import absolute_import, unicode_literals import re import markdown +from django.template.loader import render_to_string from django.utils.translation import ugettext as _ from six import string_types -from wiki.core.compat import render_to_string from wiki.plugins.macros import settings # See: diff --git a/wiki/plugins/notifications/models.py b/wiki/plugins/notifications/models.py index 19e9c106..95406525 100644 --- a/wiki/plugins/notifications/models.py +++ b/wiki/plugins/notifications/models.py @@ -32,8 +32,6 @@ class ArticleSubscription(ArticlePlugin): unique_together = ('subscription', 'articleplugin_ptr') # Matches label of upcoming 0.1 release db_table = 'wiki_notifications_articlesubscription' - if settings.APP_LABEL: - app_label = settings.APP_LABEL def default_url(article, urlpath=None): diff --git a/wiki/plugins/notifications/settings.py b/wiki/plugins/notifications/settings.py index da20f96c..a54aba08 100644 --- a/wiki/plugins/notifications/settings.py +++ b/wiki/plugins/notifications/settings.py @@ -1,9 +1,8 @@ from __future__ import absolute_import, unicode_literals -from django import VERSION -# This is deprecated in django 1.7+ -APP_LABEL = 'notifications' if VERSION < (1, 7) else None +# Deprecated +APP_LABEL = None # Key for django_nyt - changing it will break any existing notifications. ARTICLE_EDIT = "article_edit" diff --git a/wiki/tests/test_models.py b/wiki/tests/test_models.py index 4d86a84b..8f51e65a 100644 --- a/wiki/tests/test_models.py +++ b/wiki/tests/test_models.py @@ -1,26 +1,19 @@ from __future__ import absolute_import, unicode_literals +from django.apps import apps from django.conf.urls import url from django.contrib.auth import get_user_model from django.contrib.sites.models import Site from django.test.testcases import TestCase + +from wiki.conf import settings from wiki.managers import ArticleManager from wiki.models import Article, ArticleRevision, URLPath from wiki.urls import WikiURLPatterns -User = get_user_model() - - - -# Backwards compatibility with Django < 1.7 -try: - from django.apps import apps -except ImportError: - from django.contrib.auth.models import Group -else: - from wiki.conf import settings - Group = apps.get_model(settings.GROUP_MODEL) +User = get_user_model() +Group = apps.get_model(settings.GROUP_MODEL) class WikiCustomUrlPatterns(WikiURLPatterns): -- 2.45.2