-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from joehybird/upgrade_dj22
Refs #88 Fix contrib app for django 2.1 (Rebase)
- Loading branch information
Showing
23 changed files
with
220 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,20 @@ | ||
dist: xenial | ||
dist: bionic | ||
sudo: true | ||
language: python | ||
matrix: | ||
include: | ||
# Python version is just for the look on travis. | ||
- python: 2.7 | ||
env: TOX_ENV=py27-django111 | ||
|
||
- python: 3.5 | ||
env: TOX_ENV=py35-django111 | ||
- python: 3.5 | ||
env: TOX_ENV=py35-django20 | ||
- python: 3.5 | ||
env: TOX_ENV=py35-django21 | ||
- python: 3.5 | ||
env: TOX_ENV=py35-django22 | ||
|
||
- python: 3.6 | ||
env: TOX_ENV=py36-django111 | ||
- python: 3.6 | ||
env: TOX_ENV=py36-django20 | ||
- python: 3.6 | ||
env: TOX_ENV=py36-django21 | ||
- python: 3.6 | ||
env: TOX_ENV=py36-django22 | ||
|
||
- python: 3.7 | ||
env: TOX_ENV=py37-django20 | ||
- python: 3.7 | ||
env: TOX_ENV=py37-django21 | ||
- python: 3.7 | ||
env: TOX_ENV=py37-django22 | ||
- python: 3.7 | ||
env: TOX_ENV=py37-djangostable | ||
|
||
- env: TOX_ENV=flake8 | ||
python: | ||
- 2.7 | ||
- 3.5 | ||
- 3.6 | ||
- 3.7 | ||
- 3.8 | ||
stages: | ||
- lint | ||
- test | ||
jobs: | ||
include: | ||
- { stage: lint, env: TOXENV=lint, python: 3.6 } | ||
|
||
script: | ||
- tox -e $TOX_ENV | ||
- tox | ||
install: | ||
- pip install tox | ||
- pip install tox tox-travis |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,51 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.conf import settings | ||
from django.contrib.auth.forms import PasswordResetForm | ||
from django.contrib.sites.models import get_current_site | ||
|
||
from django.contrib.auth.forms import \ | ||
PasswordResetForm as DjangoPasswordResetForm | ||
from django.contrib.auth.tokens import default_token_generator | ||
from django.utils.http import int_to_base36 | ||
from django.contrib.sites.shortcuts import get_current_site | ||
from django.utils.encoding import force_bytes, force_text | ||
from django.utils.http import urlsafe_base64_encode | ||
|
||
from .mails import PasswordResetMail | ||
from mail_factory import factory | ||
|
||
from .mails import PasswordResetMail | ||
|
||
|
||
class PasswordResetForm(PasswordResetForm): | ||
class PasswordResetForm(DjangoPasswordResetForm): | ||
"""MailFactory PasswordReset alternative.""" | ||
|
||
def save(self, domain_override=None, | ||
subject_template_name=None, # Not used anymore | ||
email_template_name=None, # Mail Factory template name | ||
mail_object=None, # Mail Factory Mail object | ||
use_https=False, token_generator=default_token_generator, | ||
from_email=None, request=None): | ||
def mail_factory_email( | ||
self, domain_override=None, email_template_name=None, | ||
use_https=False, token_generator=default_token_generator, | ||
from_email=None, request=None, extra_email_context=None): | ||
""" | ||
Generates a one-use only link for resetting password and sends to the | ||
user. | ||
""" | ||
for user in self.users_cache: | ||
email = self.cleaned_data["email"] | ||
for user in self.get_users(email): | ||
if not domain_override: | ||
current_site = get_current_site(request) | ||
site_name = current_site.name | ||
domain = current_site.domain | ||
else: | ||
site_name = domain = domain_override | ||
|
||
context_params = { | ||
'email': user.email, | ||
context = { | ||
'email': email, | ||
'domain': domain, | ||
'site_name': site_name, | ||
'uid': int_to_base36(user.pk), | ||
'uid': force_text(urlsafe_base64_encode(force_bytes(user.pk))), | ||
'user': user, | ||
'token': token_generator.make_token(user), | ||
'protocol': use_https and 'https' or 'http', | ||
'protocol': 'https' if use_https else 'http', | ||
} | ||
|
||
from_email = from_email or settings.DEFAULT_FROM_EMAIL | ||
if extra_email_context is not None: | ||
context.update(extra_email_context) | ||
|
||
if email_template_name is not None: | ||
mail = factory.get_mail_object(email_template_name, | ||
context_params) | ||
mail = factory.get_mail_object(email_template_name, context) | ||
else: | ||
if mail_object is None: | ||
mail_object = PasswordResetMail | ||
mail = mail_object(context_params) | ||
mail = PasswordResetMail(context) | ||
|
||
mail.send(emails=[user.email], | ||
from_email=from_email) | ||
mail.send(emails=[user.email], from_email=from_email) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.contrib.auth.views import password_reset as django_password_reset | ||
|
||
from django.contrib.auth.views import \ | ||
PasswordResetView as DjangoPasswordResetView | ||
from django.http import HttpResponseRedirect | ||
|
||
from .forms import PasswordResetForm | ||
|
||
|
||
def password_reset(request, **kwargs): | ||
class PasswordResetView(DjangoPasswordResetView): | ||
"""Substitute with the mail_factory PasswordResetForm.""" | ||
if 'password_reset_form' not in kwargs: | ||
kwargs['password_reset_form'] = PasswordResetForm | ||
if 'email_template_name' not in kwargs: | ||
kwargs['email_template_name'] = None | ||
form_class = PasswordResetForm | ||
email_template_name = None | ||
|
||
def form_valid(self, form): | ||
opts = { | ||
'use_https': self.request.is_secure(), | ||
'token_generator': self.token_generator, | ||
'from_email': self.from_email, | ||
'email_template_name': self.email_template_name, | ||
'request': self.request, | ||
'extra_email_context': self.extra_email_context, | ||
} | ||
form.mail_factory_email(**opts) | ||
return HttpResponseRedirect(self.get_success_url()) | ||
|
||
|
||
return django_password_reset(request, **kwargs) | ||
password_reset = PasswordResetView.as_view() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
import base64 | ||
|
||
from . import exceptions | ||
from .forms import MailForm | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.