This document records all notable changes to fnpdjango.
+## 0.5 (2021-07-05)
+
+- Support for Django up to 3.2.
+- Dropped support for Django < 1.11 and Python < 3.6.
+- GzipPipelineCachedStorage replaced by GzipPipelineManifestStorage
+- Removed `utils.urls.i18n_patterns` and `URLLocaleMiddleware` in favor
+ of stock `i18n_patterns(prefix_default_language=False) and
+ `LocaleMiddleware`.
+
+
## 0.4.5 (2020-03-26)
- Support for Django up do 3.0.
# Source: https://gist.github.com/jeremyjbowers/e8d007446155c12033e6
-from __future__ import unicode_literals
-
import csv
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
-try:
- unicode
-except NameError:
- pass
-else:
- str = unicode
-
def export_as_csv_action(description=_("Export selected objects as CSV file"), fields=None, exclude=None, header=True):
"""
-# -*- coding: utf-8 -*-
# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
-from __future__ import print_function
-
import os
from optparse import make_option
from django.core.management.base import BaseCommand
+from django.utils.deprecation import MiddlewareMixin
from . import app_settings
-try:
- # Django >= 1.10
- from django.utils.deprecation import MiddlewareMixin
-except ImportError:
- # Django <= 1.9
- MiddlewareMixin = object
-
- from django.conf import settings
- from django.http import Http404
- from django.utils import translation
-
- class URLLocaleMiddleware(MiddlewareMixin):
- """Decides which translation to use, based on path only."""
- def process_request(self, request):
- language = translation.get_language_from_path(request.path_info)
- if language:
- translation.activate(language)
- request.LANGUAGE_CODE = translation.get_language()
- if language == settings.LANGUAGE_CODE:
- raise Http404
-
- def process_response(self, request, response):
- language = translation.get_language()
- translation.deactivate()
- if 'Content-Language' not in response:
- response['Content-Language'] = language
- return response
-else:
- # Django >= 1.10
- import warnings
- from django.middleware.locale import LocaleMiddleware
-
- class URLLocaleMiddleware(LocaleMiddleware):
- def __init__(self, *args, **kwargs):
- warnings.warn(
- "As of Django 1.10, fnpdjango.middleware.URLLocaleMiddleware "
- "is deprecated in favor of "
- "django.middleware.locale.LocaleMiddleware.",
- DeprecationWarning)
- super(URLLocaleMiddleware, self).__init__(*args, **kwargs)
-
class SetRemoteAddrFromXRealIP(MiddlewareMixin):
"""Sets REMOTE_ADDR from the X-Real-IP header, as set by Nginx."""
from pipeline.storage import GZIPMixin
-from pipeline.storage import PipelineCachedStorage
+from pipeline.storage import PipelineManifestStorage
-class GzipPipelineCachedStorage(GZIPMixin, PipelineCachedStorage):
+
+class GzipPipelineManifestStorage(GZIPMixin, PipelineManifestStorage):
pass
-# -*- coding: utf-8 -*-
# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
from django.conf import settings
-
-try:
- from django.urls import resolve, reverse, Resolver404
-except ImportError:
- from django.core.urlresolvers import resolve, reverse, Resolver404
-
+from django.urls import resolve, reverse, Resolver404
from django import template
from django.utils import translation
from ..utils.views import get_current_object
from copy import copy
+from urllib.parse import urlencode
from django.template import Library
-try:
- from urllib.parse import urlencode
-except ImportError:
- from urllib import urlencode
-
register = Library()
-# -*- coding: utf-8 -*-
from django.forms import CharField, ValidationError
from .text.textilepl import textile_pl
"""
Utilities for global settings.
"""
-from django.utils.encoding import python_2_unicode_compatible
from django.utils.functional import Promise
-# Use Python3 str.
-try:
- unicode
-except NameError:
- pass
-else:
- str = unicode
-
-@python_2_unicode_compatible
class LazyUGettextLazy(Promise):
"""You can use it to internationalize strings in settings.
-# -*- coding: utf-8 -*-
"""
Text utilities.
"""
+++ /dev/null
-"""
-Utilities for urlconfs.
-"""
-
-import django
-if django.VERSION >= (1, 10):
- import warnings
- from django.conf.urls.i18n import i18n_patterns as django_i18n_patterns
-
- def i18n_patterns(*args):
- warnings.warn(
- "As of Django 1.10, fnpdjango.utils.urls.i18n_patterns "
- "is deprecated in favor of directly using "
- "django.urls.i18n_patterns(prefix_default_language=False).",
- DeprecationWarning)
- return django_i18n_patterns(*args, prefix_default_language=False)
-
-else:
- # Django <= 1.9
- import re
- from django.conf import settings
- from django.core.urlresolvers import LocaleRegexURLResolver
- from django.utils.translation import get_language
-
- class MyLocaleRegexURLResolver(LocaleRegexURLResolver):
- """
- A URL resolver that always matches the active language code as URL prefix.
-
- Rather than taking a regex argument, we just override the ``regex``
- function to always return the active language-code as regex.
- """
- @property
- def regex(self):
- language_code = get_language()
- if language_code == settings.LANGUAGE_CODE:
- return re.compile('')
- if language_code not in self._regex_dict:
- regex_compiled = re.compile('^%s/' % language_code, re.UNICODE)
- self._regex_dict[language_code] = regex_compiled
- return self._regex_dict[language_code]
-
- def i18n_patterns(*args):
- """
- Adds the language code prefix to every URL pattern within this
- function. This may only be used in the root URLconf, not in an included
- URLconf.
- """
- pattern_list = list(args)
- if not settings.USE_I18N:
- return pattern_list
- return pattern_list + [MyLocaleRegexURLResolver(pattern_list)]
#!/usr/bin/env python
-# -*- coding: utf-8
# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
#
"""
Creates a simple Django configuration and runs tests for fnpdjango.
"""
-from __future__ import unicode_literals
-
import sys
import os
from os.path import dirname, abspath
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
+ 'django.contrib.staticfiles',
'fnpdjango',
'tests',
LANGUAGE_CODE='pl',
MEDIA_ROOT=media_root,
STATIC_URL='/static/',
- MIDDLEWARE_CLASSES=[ # Django <= 1.9
- 'django.middleware.common.CommonMiddleware',
- 'fnpdjango.middleware.URLLocaleMiddleware',
- 'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
- ],
+ STATIC_ROOT='./static/',
+ STATICFILES_STORAGE = 'fnpdjango.pipeline_storage.GzipPipelineManifestStorage',
MIDDLEWARE=[
'django.middleware.common.CommonMiddleware',
- 'fnpdjango.middleware.URLLocaleMiddleware',
'fnpdjango.middleware.SetRemoteAddrFromXRealIP',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
SECRET_KEY='x',
DEBUG=True,
SITE_ID=1,
+
+ PIPELINE={}
)
else:
media_root = None
-try:
- from django.test.runner import DiscoverRunner
-except ImportError:
- # Django < 1.6
- from django.test.simple import DjangoTestSuiteRunner as DiscoverRunner
+from django.test.runner import DiscoverRunner
def runtests(*test_args, **kwargs):
parent = dirname(abspath(__file__))
sys.path.insert(0, parent)
- # For Django 1.7+
- try:
- from django import setup
- except ImportError:
- pass
- else:
- setup()
+ from django import setup
+ setup()
test_runner = DiscoverRunner(
verbosity=kwargs.get('verbosity', 1),
#!/usr/bin/env python
-# -*- coding: utf-8 -*-
#
import os.path
from setuptools import setup, find_packages
setup(
name='fnpdjango',
- version='0.4.5',
+ version='0.5',
author='Radek Czajka',
author_email='radekczajka@nowoczesnapolska.org.pl',
url='',
'fnpdjango.management.commands': ['babel.cfg'],
},
install_requires=[
- 'Django>=1.4,<3.1',
+ 'Django>=1.11,<4.0',
],
extras_require={
'textile': [
-# -*- coding: utf-8 -*-
-# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
-#
-"""
-This file works only for django.test.simple.DjangoTestSuiteRunner
-in Django<1.6. The newer django.test.runner.DiscoverRunner finds
-test_* modules by itself.
-
-"""
-from .test_actions import *
-from .test_middleware import *
-from .test_storage import *
-from .test_templatetags_fnp_annoy import *
-from .test_templatetags_fnp_markup import *
-from .test_templatetags_macros import *
-from .test_utils_settings import *
-from .test_utils_urls import *
-# -*- coding: utf-8 -*-
# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
#
-from __future__ import unicode_literals
-
from tempfile import NamedTemporaryFile
from django.core.files.base import ContentFile
from django.test import TestCase
-# -*- coding: utf-8 -*-
# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
#
-from __future__ import unicode_literals
-
from django.test import TestCase
from django.test.utils import override_settings
-# -*- coding: utf-8 -*-
# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
#
-from __future__ import unicode_literals
-
from django.test import TestCase
-from __future__ import unicode_literals
-
from django.test import TestCase
from django.template import Template, Context
-# -*- coding: utf-8 -*-
# This file is part of FNPDjango, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
#
-from __future__ import unicode_literals
-
from django.conf import settings
from django.test import TestCase
-try:
- unicode
-except NameError:
- pass
-else:
- str = unicode
-
class UtilsSettingsTestCase(TestCase):
def test_lazy_ugettext_lazy(self):
+++ /dev/null
-from django.test import TestCase
-
-
-class UrlsTestCase(TestCase):
- def test_i18n_patterns(self):
- self.assertEqual(self.client.get('/').content.decode('latin1'), 'pl')
- self.assertEqual(self.client.get('/en/').content.decode('latin1'), 'en')
from django.conf.urls import url
from django.contrib import admin
-from fnpdjango.utils.urls import i18n_patterns
from . import views
-# For Django < 1.7.
-admin.autodiscover()
-
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^ip/$', views.ip),
-] + i18n_patterns(
- url(r'^$', views.get_lang),
-)
+]
from django.http import HttpResponse
-from django.utils.translation import get_language
-
-
-def get_lang(request):
- return HttpResponse(get_language())
def ip(request):
#
[tox]
envlist=clear,
- d1{4,5,6}-py27,
- d17-py27,
- d{18,19,110}-py{27,35},
- d111-py{27,35,36,37},
- d20-py{35,36,37},
- d21-py{35,36,37},
- d22-py{35,36,37,38},
+ d111-py{36,37},
+ d20-py{36,37},
+ d21-py{36,37},
+ d22-py{36,37,38},
d30-py{36,37,38},
+ d31-py{36,37,38,39},
+ d32-py{36,37,38,39},
stats
[testenv]
commands=coverage run --source=fnpdjango --append --branch runtests.py
deps=
- d14: Django>=1.4,<1.5
- d15: Django>=1.5,<1.6
- d16: Django>=1.6,<1.7
- d17: Django>=1.7,<1.8
- d18: Django>=1.8,<1.9
- d19: Django>=1.9,<1.10
- d110: Django>=1.10,<1.11
+ django-pipeline==2.0.5
d111: Django>=1.11,<2.0
d20: Django>=2.0,<2.1
d21: Django>=2.1,<2.2
d22: Django>=2.2,<3.0
d30: Django>=3.0,<3.1
+ d31: Django>=3.1,<3.2
+ d32: Django>=3.2,<4.0
coverage
extras=
textile