mirror of
https://github.com/Hopiu/django-rosetta.git
synced 2026-04-18 12:11:12 +00:00
Removed old compatibility code for Django < 1.11
This commit is contained in:
parent
9cd7fd9b27
commit
c7bbf68cf3
7 changed files with 15 additions and 33 deletions
|
|
@ -3,7 +3,7 @@ Installation
|
|||
|
||||
Requirements
|
||||
------------
|
||||
* As of version 0.7.13, Rosetta supports Django 1.8 through 1.11.
|
||||
* As of version 0.9.0, Rosetta supports Django 1.11 and up.
|
||||
|
||||
|
||||
Install Rosetta
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ Usage
|
|||
Generate a batch of files to translate
|
||||
--------------------------------------
|
||||
|
||||
See `Django's documentation on Internationalization <https://docs.djangoproject.com/en/1.8/topics/i18n/translation/>`_ to set up your project to use i18n and create the ``gettext`` catalog files.
|
||||
See `Django's documentation on Internationalization <https://docs.djangoproject.com/en/stable/topics/i18n/translation/>`_ to set up your project to use i18n and create the ``gettext`` catalog files.
|
||||
|
||||
Translate away!
|
||||
---------------
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import hashlib
|
|||
import importlib
|
||||
import time
|
||||
import six
|
||||
import django
|
||||
|
||||
cache = caches[rosetta_settings.ROSETTA_CACHE_NAME]
|
||||
|
||||
|
|
@ -46,8 +45,8 @@ class SessionRosettaStorage(BaseRosettaStorage):
|
|||
def __init__(self, request):
|
||||
super(SessionRosettaStorage, self).__init__(request)
|
||||
|
||||
if 'signed_cookies' in settings.SESSION_ENGINE and django.VERSION[1] >= 6 and 'pickle' not in settings.SESSION_SERIALIZER.lower():
|
||||
raise ImproperlyConfigured("Sorry, but django-rosetta doesn't support the `signed_cookies` SESSION_ENGINE in Django >= 1.6, because rosetta specific session files cannot be serialized.")
|
||||
if 'signed_cookies' in settings.SESSION_ENGINE and 'pickle' not in settings.SESSION_SERIALIZER.lower():
|
||||
raise ImproperlyConfigured("Sorry, but django-rosetta doesn't support the `signed_cookies` SESSION_ENGINE, because rosetta specific session files cannot be serialized.")
|
||||
|
||||
def get(self, key, default=None):
|
||||
if key in self.request.session:
|
||||
|
|
|
|||
|
|
@ -13,15 +13,12 @@ except ImportError:
|
|||
|
||||
from django.conf import settings
|
||||
from django.dispatch import receiver
|
||||
try:
|
||||
from django.urls import reverse, resolve
|
||||
except ImportError:
|
||||
from django.core.urlresolvers import reverse, resolve
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.http import Http404
|
||||
from django.test import TestCase, RequestFactory
|
||||
from django.test.client import Client
|
||||
from django import VERSION
|
||||
from django.urls import reverse, resolve
|
||||
from django.utils.encoding import force_bytes
|
||||
import six
|
||||
|
||||
|
|
@ -43,15 +40,11 @@ class RosettaTestCase(TestCase):
|
|||
def setUp(self):
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
user = User.objects.create_user('test_admin', 'test@test.com', 'test_password')
|
||||
user2 = User.objects.create_user('test_admin2', 'test@test2.com', 'test_password')
|
||||
user3 = User.objects.create_user('test_admin3', 'test@test2.com', 'test_password')
|
||||
user = User.objects.create_superuser('test_admin', 'test@test.com', 'test_password')
|
||||
user2 = User.objects.create_superuser('test_admin2', 'test@test2.com', 'test_password')
|
||||
user3 = User.objects.create_superuser('test_admin3', 'test@test2.com', 'test_password')
|
||||
|
||||
user.is_superuser, user2.is_superuser, user3.is_superuser = True, True, True
|
||||
user.is_staff, user2.is_staff, user3.is_staff = True, True, False
|
||||
|
||||
user.save()
|
||||
user2.save()
|
||||
user3.is_staff = False
|
||||
user3.save()
|
||||
|
||||
self.user = user
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
from django.conf.urls import url
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic.base import RedirectView
|
||||
try:
|
||||
from django.urls import reverse_lazy
|
||||
except ImportError:
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
|
||||
from . import views
|
||||
|
||||
|
|
|
|||
|
|
@ -17,10 +17,7 @@ from django.core.paginator import Paginator
|
|||
from django.http import Http404, HttpResponseRedirect, HttpResponse, JsonResponse
|
||||
from django.views.decorators.cache import never_cache
|
||||
from django.views.generic import TemplateView, View
|
||||
try:
|
||||
from django.urls import reverse
|
||||
except ImportError:
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.urls import reverse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.functional import cached_property
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
|
@ -44,18 +41,14 @@ def get_app_name(path):
|
|||
return path.split('/locale')[0].split('/')[-1]
|
||||
|
||||
|
||||
@method_decorator(never_cache, 'dispatch')
|
||||
@method_decorator(user_passes_test(lambda user: can_translate(user), settings.LOGIN_URL), 'dispatch')
|
||||
class RosettaBaseMixin(object):
|
||||
"""A mixin class for Rosetta's class-based views. It provides:
|
||||
* security (see decorated dispatch() method)
|
||||
* security (see class decorators)
|
||||
* a property for the 'po_filter' url argument
|
||||
"""
|
||||
|
||||
# Handle security in our mixin
|
||||
# NOTE: after we drop support for Django 1.8, we can employ these decorators
|
||||
# more cleanly on the class itself, rather than the dispatch() method. (See
|
||||
# the Django docs: https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-the-class)
|
||||
@method_decorator(never_cache)
|
||||
@method_decorator(user_passes_test(lambda user: can_translate(user), settings.LOGIN_URL))
|
||||
def dispatch(self, *args, **kwargs):
|
||||
return super(RosettaBaseMixin, self).dispatch(*args, **kwargs)
|
||||
|
||||
|
|
|
|||
2
setup.py
2
setup.py
|
|
@ -57,7 +57,7 @@ setup(
|
|||
zip_safe=False,
|
||||
install_requires=[
|
||||
'six >=1.2.0',
|
||||
'Django >= 1.8',
|
||||
'Django >= 1.11',
|
||||
'requests >= 2.1.0',
|
||||
'polib >= 1.1.0'
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue