Skip to content

Commit

Permalink
Drop support for Django 1.7, Python 3.2; remove misc. compat hacks (#…
Browse files Browse the repository at this point in the history
…1625)

* Remove account_emailconfirmationmigration command

Closes #1620

* Drop support for Django 1.7 (and Python 3.2)

* Drop Django 1.6 compatibility hack

* Use urllib imports from allauth.compat instead of try/excepting

* Drop support for ACCOUNT_EMAIL_AUTHENTICATION (deprecated since 2012)

* Remove references to ACCOUNT_PASSWORD_MIN_LENGTH

Was removed a long time ago

* Drop support for account_tags and socialaccount_tags

Deprecated since 2012-08-24

* Drop support for `site` context variable (deprecated in 2015)
  • Loading branch information
jleclanche authored and pennersr committed Feb 22, 2017
1 parent 4229f6d commit b0c6d5d
Show file tree
Hide file tree
Showing 38 changed files with 81 additions and 360 deletions.
15 changes: 2 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ sudo: false
language: python
python:
- "2.7"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
env:
matrix:
- DJANGO="Django<1.8"
- DJANGO="Django<1.9"
- DJANGO="Django<1.10"
- DJANGO="Django<1.11"
cache:
directories:
- $HOME/.cache/pip
install:
# pip >=8 dropped Python 3.2 support
- pip install "pip<8.0.0" wheel
- pip install --upgrade pip wheel
- pip install "$DJANGO" "coverage==3.7.1" coveralls "mock>=1.0.1"
- pip install .
- pip install flake8
Expand All @@ -27,17 +24,9 @@ install:
- npm install standard
matrix:
exclude:
- python: "3.5"
env: DJANGO="Django<1.8"
- python: "3.6"
env: DJANGO="Django<1.8"
# Django 1.9+ no longer supports python 3.2/3.3
- python: "3.2"
env: DJANGO="Django<1.10"
# Django 1.9+ no longer supports python 3.3
- python: "3.3"
env: DJANGO="Django<1.10"
- python: "3.2"
env: DJANGO="Django<1.11"
- python: "3.3"
env: DJANGO="Django<1.11"
branches:
Expand Down
5 changes: 0 additions & 5 deletions allauth/account/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# Ok, this is really weird but, in python3.2 we must import
# app_settings before django imports apps; otherwise the module-class
# hack doesn't work as expected
from . import app_settings # noqa

default_app_config = 'allauth.account.apps.AccountConfig'
4 changes: 2 additions & 2 deletions allauth/account/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
logout as django_logout,
)
from django.contrib.auth.models import AbstractUser
from django.contrib.sites.shortcuts import get_current_site
from django.core.cache import cache
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import resolve_url
from django.template import TemplateDoesNotExist
from django.template.loader import render_to_string
from django.utils import timezone
Expand All @@ -29,10 +31,8 @@
build_absolute_uri,
email_address_exists,
generate_unique_username,
get_current_site,
get_user_model,
import_attribute,
resolve_url,
)


Expand Down
15 changes: 2 additions & 13 deletions allauth/account/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,8 @@ def EMAIL_VERIFICATION(self):

@property
def AUTHENTICATION_METHOD(self):
from django.conf import settings
if hasattr(settings, "ACCOUNT_EMAIL_AUTHENTICATION"):
import warnings
warnings.warn("ACCOUNT_EMAIL_AUTHENTICATION is deprecated,"
" use ACCOUNT_AUTHENTICATION_METHOD",
DeprecationWarning)
if getattr(settings, "ACCOUNT_EMAIL_AUTHENTICATION"):
ret = self.AuthenticationMethod.EMAIL
else:
ret = self.AuthenticationMethod.USERNAME
else:
ret = self._setting("AUTHENTICATION_METHOD",
self.AuthenticationMethod.USERNAME)
ret = self._setting("AUTHENTICATION_METHOD",
self.AuthenticationMethod.USERNAME)
return ret

@property
Expand Down
1 change: 0 additions & 1 deletion allauth/account/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# require django >= 1.7
from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _

Expand Down
16 changes: 5 additions & 11 deletions allauth/account/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

from django import forms
from django.contrib.auth.tokens import default_token_generator
from django.contrib.sites.shortcuts import get_current_site
from django.core import exceptions, validators
from django.utils.translation import pgettext, ugettext, ugettext_lazy as _

from . import app_settings
from ..compat import reverse
from ..utils import (
build_absolute_uri,
get_current_site,
get_username_max_length,
set_form_field_order,
)
Expand Down Expand Up @@ -116,7 +116,7 @@ def __init__(self, *args, **kwargs):
"Login"),
widget=login_widget)
self.fields["login"] = login_field
set_form_field_order(self, ["login", "password", "remember"])
set_form_field_order(self, ["login", "password", "remember"])
if app_settings.SESSION_REMEMBER is not None:
del self.fields['remember']

Expand Down Expand Up @@ -461,8 +461,8 @@ class ResetPasswordForm(forms.Form):
"type": "email",
"size": "30",
"placeholder": _("E-mail address"),
})
)
})
)

def clean_email(self):
email = self.cleaned_data["email"]
Expand All @@ -479,11 +479,6 @@ def save(self, request, **kwargs):
token_generator = kwargs.get("token_generator",
default_token_generator)

def deprecated_site():
warnings.warn("Context variable `site` deprecated, use"
"`current_site` instead", DeprecationWarning)
return current_site

for user in self.users:

temp_key = token_generator.make_token(user)
Expand All @@ -499,8 +494,7 @@ def deprecated_site():
url = build_absolute_uri(
request, path)

context = {"site": deprecated_site,
"current_site": current_site,
context = {"current_site": current_site,
"user": user,
"password_reset_url": url,
"request": request}
Expand Down

This file was deleted.

9 changes: 0 additions & 9 deletions allauth/account/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
# The `account` app never had any South migrations, as the data models
# (specifically email uniqueness) depend on the settings, which is
# something that collides with South freezing mechanism. For Django
# 1.7, we are able to provide migrations, but to stay backwards
# compatible we still need to make sure South does not pick up this
# `migrations` package. Therefore, let's do a bogus import which
# raises an ImportError in case South is used.

from django.db import migrations # noqa
7 changes: 0 additions & 7 deletions allauth/account/templatetags/account_tags.py

This file was deleted.

21 changes: 9 additions & 12 deletions allauth/account/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import django
from django.conf import settings
from django.contrib.auth.models import AbstractUser, AnonymousUser
from django.contrib.sites.models import Site
from django.core import mail, validators
from django.core.exceptions import ValidationError
from django.db import models
Expand All @@ -22,11 +23,7 @@
EmailConfirmationHMAC,
)
from allauth.tests import TestCase, patch
from allauth.utils import (
get_current_site,
get_user_model,
get_username_max_length,
)
from allauth.utils import get_user_model, get_username_max_length

from . import app_settings
from ..compat import is_authenticated, reverse
Expand Down Expand Up @@ -63,7 +60,7 @@ def setUp(self):
from ..socialaccount.models import SocialApp
sa = SocialApp.objects.create(name='testfb',
provider='facebook')
sa.sites.add(get_current_site())
sa.sites.add(Site.objects.get_current())

@override_settings(
ACCOUNT_AUTHENTICATION_METHOD=app_settings.AuthenticationMethod
Expand All @@ -80,7 +77,7 @@ def test_username_containing_at(self):
{'login': '@raymond.penners',
'password': 'psst'})
self.assertRedirects(resp,
'http://testserver'+settings.LOGIN_REDIRECT_URL,
'http://testserver' + settings.LOGIN_REDIRECT_URL,
fetch_redirect_response=False)

def test_signup_same_email_verified_externally(self):
Expand Down Expand Up @@ -391,11 +388,11 @@ def test_email_verification_mandatory(self):
{'login': 'johndoe',
'password': 'johndoe'})
self.assertRedirects(resp,
'http://testserver'+settings.LOGIN_REDIRECT_URL,
'http://testserver' + settings.LOGIN_REDIRECT_URL,
fetch_redirect_response=False)

def test_email_escaping(self):
site = get_current_site()
site = Site.objects.get_current()
site.name = '<enc&"test>'
site.save()
u = get_user_model().objects.create(
Expand All @@ -421,7 +418,7 @@ def test_login_unverified_account_optional(self):
{'login': 'john',
'password': 'doe'})
self.assertRedirects(resp,
'http://testserver'+settings.LOGIN_REDIRECT_URL,
'http://testserver' + settings.LOGIN_REDIRECT_URL,
fetch_redirect_response=False)

@override_settings(
Expand Down Expand Up @@ -609,8 +606,8 @@ def test_account_authenticated_login_redirects_is_false(self):
'django.contrib.auth.password_validation.MinimumLengthValidator',
'OPTIONS': {
'min_length': 9,
}
}])
}
}])
def test_django_password_validation(self):
if django.VERSION < (1, 9, ):
return
Expand Down
17 changes: 5 additions & 12 deletions allauth/account/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from collections import OrderedDict
from datetime import timedelta

from django.conf import settings
from django.contrib import messages
from django.contrib.auth import update_session_auth_hash
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Q
Expand All @@ -10,8 +12,6 @@
from django.utils.http import base36_to_int, int_to_base36, urlencode
from django.utils.timezone import now

from allauth.compat import OrderedDict

from . import app_settings, signals
from ..exceptions import ImmediateHttpResponse
from ..utils import (
Expand All @@ -23,12 +23,6 @@
from .adapter import get_adapter
from .app_settings import EmailVerificationMethod


try:
from django.contrib.auth import update_session_auth_hash
except ImportError:
update_session_auth_hash = None

try:
from django.utils.encoding import force_text
except ImportError:
Expand Down Expand Up @@ -67,8 +61,7 @@ def logout_on_password_change(request, user):
# Since it is the default behavior of Django to invalidate all sessions on
# password change, this function actually has to preserve the session when
# logout isn't desired.
if (update_session_auth_hash is not None and
not app_settings.LOGOUT_ON_PASSWORD_CHANGE):
if not app_settings.LOGOUT_ON_PASSWORD_CHANGE:
update_session_auth_hash(request, user)


Expand Down Expand Up @@ -356,15 +349,15 @@ def sync_user_email_addresses(user):
def filter_users_by_username(*username):
if app_settings.PRESERVE_USERNAME_CASING:
qlist = [
Q(**{app_settings.USER_MODEL_USERNAME_FIELD+'__iexact': u})
Q(**{app_settings.USER_MODEL_USERNAME_FIELD + '__iexact': u})
for u in username]
q = qlist[0]
for q2 in qlist[1:]:
q = q | q2
ret = get_user_model().objects.filter(q)
else:
ret = get_user_model().objects.filter(
**{app_settings.USER_MODEL_USERNAME_FIELD+'__in':
**{app_settings.USER_MODEL_USERNAME_FIELD + '__in':
[u.lower() for u in username]})
return ret

Expand Down
3 changes: 2 additions & 1 deletion allauth/account/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.sites.shortcuts import get_current_site
from django.http import (
Http404,
HttpResponsePermanentRedirect,
Expand All @@ -14,7 +15,7 @@
from . import app_settings, signals
from ..compat import is_anonymous, is_authenticated, reverse, reverse_lazy
from ..exceptions import ImmediateHttpResponse
from ..utils import get_current_site, get_form_class, get_request_param
from ..utils import get_form_class, get_request_param
from .adapter import get_adapter
from .forms import (
AddEmailForm,
Expand Down
Loading

0 comments on commit b0c6d5d

Please sign in to comment.