Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Django 2.0 #33

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions accountsplus/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.core.exceptions
import django.shortcuts
import django.http
Expand All @@ -21,8 +19,8 @@
from django.conf import settings
from django.apps import apps

import signals
import models
from accountsplus import signals
from accountsplus import models


sensitive_post_parameters_m = django.utils.decorators.method_decorator(
Expand Down Expand Up @@ -185,7 +183,7 @@ def reset_passwords(self, request, queryset):
reset_passwords.short_description = 'Send password reset emails to selected Users'

def get_timezone(self, obj):
return unicode(obj.timezone)
return str(obj.timezone)

def masquerade(self, obj):
return '<a href="{}">sign in</a>'.format(django.urls.reverse('masquerade', kwargs={'user_id': obj.id}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@waseem-omar I think we need to mark this as SafeString so that it appears as hyperlink in the table

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should look like this django.utils.html.mark_safe('<a href="{}">sign in</a>'.format(django.urls.reverse('masquerade', kwargs={'user_id': obj.id})))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done @nasief, I have also refactored Masquerading views as you suggested above.

Expand Down
2 changes: 0 additions & 2 deletions accountsplus/apps.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

from django.apps import AppConfig


Expand Down
5 changes: 1 addition & 4 deletions accountsplus/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import unicode_literals


def masquerade_info(request):
if request.user.is_authenticated():
if request.user.is_authenticated:
return {
'is_masquerading': request.session.get('is_masquerading', False),
}
Expand Down
2 changes: 0 additions & 2 deletions accountsplus/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.forms
from django.conf import settings
from django.apps import apps
Expand Down
3 changes: 1 addition & 2 deletions accountsplus/middleware.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from __future__ import unicode_literals
import django.utils.timezone
from django.utils.deprecation import MiddlewareMixin


class TimezoneMiddleware(MiddlewareMixin):
def process_request(self, request):
if request.user.is_authenticated() and request.user.timezone:
if request.user.is_authenticated and request.user.timezone:
django.utils.timezone.activate(request.user.timezone)
else:
django.utils.timezone.deactivate()
4 changes: 1 addition & 3 deletions accountsplus/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import logging

from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -176,4 +174,4 @@ def delete(self, using=None, keep_parents=False):

@property
def is_masquerading(self):
return self.masquerading_user_id > 0
return self.masquerading_user_id is not None and self.masquerading_user_id > 0
2 changes: 0 additions & 2 deletions accountsplus/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.contrib.auth.signals
from django.dispatch import receiver, Signal
from django.conf import settings
Expand Down
1 change: 0 additions & 1 deletion accountsplus/templatetags/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from __future__ import unicode_literals
2 changes: 0 additions & 2 deletions accountsplus/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.test
import django.contrib.admin

Expand Down
2 changes: 0 additions & 2 deletions accountsplus/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.test
import django.core.mail
import django.db.models
Expand Down
2 changes: 0 additions & 2 deletions accountsplus/tests/test_signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.test
import django.test.utils

Expand Down
2 changes: 0 additions & 2 deletions accountsplus/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.test
import django.shortcuts
import django.conf.urls
Expand Down
2 changes: 0 additions & 2 deletions accountsplus/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.test
import django.test.utils
import django.test.client
Expand Down
31 changes: 15 additions & 16 deletions accountsplus/urls.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
from __future__ import unicode_literals

import django.conf.urls
from django.contrib.auth.urls import url
import django.contrib.auth.urls
import django.contrib.auth.views

import views
import forms

from accountsplus import views
from accountsplus import forms

urlpatterns = [
url(r'^logout/$', views.logout_then_login, name='logout'),
url(r'^password_change/$', views.password_change, name='password_change'),
url(r'^password_reset/$', views.password_reset, name='password_reset'),
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
django.contrib.auth.views.password_reset_confirm, name='password_reset_confirm'),
django.conf.urls.url(r'^logout/$', views.logout_then_login, name='logout'),
django.conf.urls.url(r'^password_change/$', views.password_change, name='password_change'),
django.conf.urls.url(r'^password_reset/$', django.contrib.auth.views.PasswordResetView.as_view(), name='password_reset'),
django.conf.urls.url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
django.contrib.auth.views.PasswordResetConfirmView.as_view(), name='password_reset_confirm'),

# override the admin password reset flow to use the normal site password
# reset flow
url(r'^password_reset/$', views.password_reset, name='admin_password_reset'),
django.conf.urls.url(r'^password_reset/$', views.password_reset, name='admin_password_reset'),

url(r'^login/$',
django.contrib.auth.views.login,
django.conf.urls.url(r'^login/$',
django.contrib.auth.views.LoginView.as_view(),
kwargs={'authentication_form': forms.EmailBasedAuthenticationForm, 'redirect_authenticated_user': True},
name='login'),
url(r'^', django.conf.urls.include(django.contrib.auth.urls)),
django.conf.urls.url(r'^', django.conf.urls.include(django.contrib.auth.urls)),

# masquerade views
url(r'^admin/masquerade/end/$', views.end_masquerade, name='end_masquerade'),
url(r'^admin/masquerade/(?P<user_id>\d+)/$', views.masquerade, name='masquerade'),
django.conf.urls.url(r'^admin/masquerade/end/$', views.end_masquerade, name='end_masquerade'),
django.conf.urls.url(r'^admin/masquerade/(?P<user_id>\d+)/$', views.masquerade, name='masquerade'),
]
17 changes: 8 additions & 9 deletions accountsplus/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import logging

from django.utils.translation import ugettext as _
Expand All @@ -14,28 +13,28 @@
import django.http
import django.template.response
import django.utils.module_loading
import django.core.urlresolvers
import django.urls
from django.conf import settings as app_settings

from axes import utils

import signals
import forms
import settings
from accountsplus import signals
from accountsplus import forms
from accountsplus import settings


logger = logging.getLogger(__name__)


def logout_then_login(request, login_url=None, extra_context=None):
def logout_then_login(request, login_url=None):
"""
Logs out the user if they are logged in. Then redirects to the log-in page.
"""
# if a user is masquerading, don't log them out, just kill the masquerade
if request.session.get('is_masquerading'):
return django.shortcuts.redirect('end_masquerade')
else:
return django.contrib.auth.views.logout_then_login(request, login_url, extra_context)
return django.contrib.auth.views.logout_then_login(request, login_url)


@django.views.decorators.cache.never_cache
Expand Down Expand Up @@ -130,7 +129,7 @@ def password_change(request,
PasswordChangeForm,
current_app=None, extra_context=None):
if post_change_redirect is None:
post_change_redirect = django.core.urlresolvers.reverse(
post_change_redirect = django.urls.reverse(
'password_change_done')
else:
post_change_redirect = django.shortcuts.resolve_url(
Expand Down Expand Up @@ -173,7 +172,7 @@ def password_reset(request,
extra_email_context=None):
User = django.contrib.auth.get_user_model()

response = django.contrib.auth.views.password_reset(
response = django.contrib.auth.views.PasswordResetView(
request, template_name, email_template_name,
subject_template_name, password_reset_form, token_generator,
post_reset_redirect, from_email, extra_context,
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
setuptools
Django==1.10.1
Django==2.2.1
flake8
pep8
pyflakes
Expand Down
1 change: 0 additions & 1 deletion settings_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import unicode_literals
import os


Expand Down
2 changes: 0 additions & 2 deletions urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import unicode_literals

import django.conf.urls
import django.contrib.admin

Expand Down