From 965e32884b91f84f79eb6076b385e1b4bf684406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Mon, 29 Aug 2016 17:54:53 +0300 Subject: [PATCH] Django 1.10 --- hc/accounts/admin.py | 4 +-- .../management/commands/createprofiles.py | 13 -------- hc/accounts/middleware.py | 33 ++++++++++--------- hc/accounts/models.py | 2 +- hc/accounts/views.py | 2 +- hc/api/models.py | 2 +- hc/front/views.py | 8 ++--- hc/lib/badges.py | 2 +- hc/payments/context_processors.py | 2 +- hc/payments/models.py | 1 - hc/payments/views.py | 2 +- hc/settings.py | 5 ++- requirements.txt | 2 +- 13 files changed, 33 insertions(+), 45 deletions(-) delete mode 100644 hc/accounts/management/commands/createprofiles.py diff --git a/hc/accounts/admin.py b/hc/accounts/admin.py index 0e79f05f..d3f0a9b1 100644 --- a/hc/accounts/admin.py +++ b/hc/accounts/admin.py @@ -1,8 +1,8 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User -from django.core.urlresolvers import reverse from django.template.loader import render_to_string +from django.urls import reverse from hc.accounts.models import Profile from hc.api.models import Channel, Check @@ -12,7 +12,7 @@ class ProfileAdmin(admin.ModelAdmin): class Media: css = { - 'all': ('css/admin/profiles.css',) + 'all': ('css/admin/profiles.css',) } list_display = ("id", "users", "reports_allowed", "next_report_date", diff --git a/hc/accounts/management/commands/createprofiles.py b/hc/accounts/management/commands/createprofiles.py deleted file mode 100644 index 23dc795d..00000000 --- a/hc/accounts/management/commands/createprofiles.py +++ /dev/null @@ -1,13 +0,0 @@ -from django.core.management.base import BaseCommand -from django.contrib.auth.models import User -from hc.accounts.models import Profile - - -class Command(BaseCommand): - help = 'Make sure all users have profiles' - - def handle(self, *args, **options): - for user in User.objects.all(): - Profile.objects.get_or_create(user_id=user.id) - - print("Done.") diff --git a/hc/accounts/middleware.py b/hc/accounts/middleware.py index 3118e216..b562e98f 100644 --- a/hc/accounts/middleware.py +++ b/hc/accounts/middleware.py @@ -2,21 +2,24 @@ from hc.accounts.models import Profile class TeamAccessMiddleware(object): - def process_request(self, request): - if not request.user.is_authenticated(): - return + def __init__(self, get_response): + self.get_response = get_response - teams_q = Profile.objects.filter(member__user_id=request.user.id) - teams_q = teams_q.select_related("user") - request.teams = list(teams_q) + def __call__(self, request): + if request.user.is_authenticated: + teams_q = Profile.objects.filter(member__user_id=request.user.id) + teams_q = teams_q.select_related("user") + request.teams = list(teams_q) - try: - profile = request.user.profile - except Profile.DoesNotExist: - profile = Profile(user=request.user) - profile.save() + try: + profile = request.user.profile + except Profile.DoesNotExist: + profile = Profile(user=request.user) + profile.save() - if profile.current_team: - request.team = profile.current_team - else: - request.team = profile + if profile.current_team: + request.team = profile.current_team + else: + request.team = profile + + return self.get_response(request) diff --git a/hc/accounts/models.py b/hc/accounts/models.py index 68c1dbd5..63522dde 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -7,8 +7,8 @@ from django.conf import settings from django.contrib.auth.hashers import make_password from django.contrib.auth.models import User from django.core import signing -from django.core.urlresolvers import reverse from django.db import models +from django.urls import reverse from django.utils import timezone from hc.lib import emails diff --git a/hc/accounts/views.py b/hc/accounts/views.py index 9fdbaa88..8d67b218 100644 --- a/hc/accounts/views.py +++ b/hc/accounts/views.py @@ -101,7 +101,7 @@ def set_password_link_sent(request): def check_token(request, username, token): - if request.user.is_authenticated() and request.user.username == username: + if request.user.is_authenticated and request.user.username == username: # User is already logged in return redirect("hc-checks") diff --git a/hc/api/models.py b/hc/api/models.py index a7888362..a1cdd7d4 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -7,8 +7,8 @@ from datetime import timedelta as td from django.conf import settings from django.contrib.auth.models import User -from django.core.urlresolvers import reverse from django.db import models +from django.urls import reverse from django.utils import timezone from hc.api import transports from hc.lib import emails diff --git a/hc/front/views.py b/hc/front/views.py index 555668d6..46015059 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -6,10 +6,10 @@ import requests from django.conf import settings from django.contrib import messages from django.contrib.auth.decorators import login_required -from django.core.urlresolvers import reverse from django.db.models import Count -from django.http import HttpResponseBadRequest, HttpResponseForbidden, Http404 +from django.http import Http404, HttpResponseBadRequest, HttpResponseForbidden from django.shortcuts import get_object_or_404, redirect, render +from django.urls import reverse from django.utils import timezone from django.utils.crypto import get_random_string from django.utils.six.moves.urllib.parse import urlencode @@ -75,7 +75,7 @@ def _welcome_check(request): def index(request): - if request.user.is_authenticated(): + if request.user.is_authenticated: return redirect("hc-checks") check = _welcome_check(request) @@ -390,7 +390,7 @@ def add_pd(request): def add_slack(request): - if not settings.SLACK_CLIENT_ID and not request.user.is_authenticated(): + if not settings.SLACK_CLIENT_ID and not request.user.is_authenticated: return redirect("hc-login") ctx = { diff --git a/hc/lib/badges.py b/hc/lib/badges.py index c735f952..e7ffec7f 100644 --- a/hc/lib/badges.py +++ b/hc/lib/badges.py @@ -1,7 +1,7 @@ from django.conf import settings from django.core.signing import base64_hmac from django.template.loader import render_to_string -from django.core.urlresolvers import reverse +from django.urls import reverse WIDTHS = {"a": 7, "b": 7, "c": 6, "d": 7, "e": 6, "f": 4, "g": 7, "h": 7, "i": 3, "j": 3, "k": 7, "l": 3, "m": 10, "n": 7, "o": 7, "p": 7, diff --git a/hc/payments/context_processors.py b/hc/payments/context_processors.py index d093d25e..fb917081 100644 --- a/hc/payments/context_processors.py +++ b/hc/payments/context_processors.py @@ -4,7 +4,7 @@ from django.conf import settings def payments(request): show_pricing = settings.USE_PAYMENTS - if show_pricing and request.user.is_authenticated(): + if show_pricing and request.user.is_authenticated: profile = request.user.profile if profile.current_team_id and profile.current_team_id != profile.id: show_pricing = False diff --git a/hc/payments/models.py b/hc/payments/models.py index 97ab1c4c..571521a4 100644 --- a/hc/payments/models.py +++ b/hc/payments/models.py @@ -40,7 +40,6 @@ class Subscription(models.Model): return self._pm def pm_is_credit_card(self): - print(self.payment_method_token, self._get_braintree_payment_method()) return isinstance(self._get_braintree_payment_method(), braintree.credit_card.CreditCard) diff --git a/hc/payments/views.py b/hc/payments/views.py index a981a004..79f09038 100644 --- a/hc/payments/views.py +++ b/hc/payments/views.py @@ -28,7 +28,7 @@ def get_client_token(request): def pricing(request): sub = None - if request.user.is_authenticated(): + if request.user.is_authenticated: # Don't use Subscription.objects.for_user method here, so a # subscription object is not created just by viewing a page. sub = Subscription.objects.filter(user_id=request.user.id).first() diff --git a/hc/settings.py b/hc/settings.py index 42fe78b6..adecc237 100644 --- a/hc/settings.py +++ b/hc/settings.py @@ -40,15 +40,14 @@ INSTALLED_APPS = ( 'hc.payments' ) -MIDDLEWARE_CLASSES = ( +MIDDLEWARE = ( + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'django.middleware.security.SecurityMiddleware', 'hc.accounts.middleware.TeamAccessMiddleware', ) diff --git a/requirements.txt b/requirements.txt index d764587e..0da5080d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ django-appconf==1.0.1 django-ses-backend==0.1.1 -Django==1.9 +Django==1.10 django_compressor==2.0 djmail==0.11.0 futures==3.0.3