Received: from mail.netlandish.com (unknown [10.138.202.29]) by code.netlandish.com (Postfix) with ESMTP id 6A02680B86 for <~petersanchez/public-inbox@lists.code.netlandish.com>; Thu, 19 Nov 2020 09:42:57 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.221.50; helo=mail-wr1-f50.google.com; envelope-from=leo@jacobs-alumni.de; receiver= Authentication-Results: mail.netlandish.com; dkim=pass (2048-bit key; unprotected) header.d=jacobs-alumni.de header.i=@jacobs-alumni.de header.b=sUI+187B Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by mail.netlandish.com (Postfix) with ESMTP id 333793F1D0 for <~petersanchez/public-inbox@lists.code.netlandish.com>; Thu, 19 Nov 2020 01:42:55 -0800 (PST) Received: by mail-wr1-f50.google.com with SMTP id b6so5733224wrt.4 for <~petersanchez/public-inbox@lists.code.netlandish.com>; Thu, 19 Nov 2020 01:42:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jacobs-alumni.de; s=google; h=mime-version:content-transfer-encoding:subject:message-id :user-agent:date:from:to; bh=7y1TY6OXU4DeSC8iwpvggfaP8+ugsGCbc1GyxTGiWVM=; b=sUI+187BtwZ2Zcedy+dPSEEuMr8dALl4BCUpgkJ9jTW4NP+p4P2LUe7nx4QJ/OjJlm FJ5xPv1Lwr6gymM33JpwFAD7qotxu3rpDYM8atzzYkBc31c9GyVQF5xHbFvShanQzsNx DzYCuZAh7jqcIWvveZYF4TDHU+rPBQaaSZVh3HrAfsegP1ZXUiUP36ti7w4GOggUsSlr eVA3evUXqVFFb4mRyCtQV4rcXnQrQD7HLU2kfOeJur57VsSIcG8GcUzn4YhzQJB9DbRp QCd3zFwTPb57ZGkYzHhd+OzC2yRPjtpbxyYeKYaOxtnqP0B6ge59iyHI82EiBqT51st4 NHTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding:subject :message-id:user-agent:date:from:to; bh=7y1TY6OXU4DeSC8iwpvggfaP8+ugsGCbc1GyxTGiWVM=; b=E080szlyJUsI3+HY8nnxZpfIcjDMHPZDp458wiBKGmsVYnwgrI7ULq8ACYqvhN2thr TrMZWeeH3H/s10YZSKzSt0l/RjogRbQQ9b5Z0VrhEFWm7ZpWl/OksDYGUSsyiB9Y2FI+ igxST65aFeXIj+bVKerwLv/c/xOgYjGhU0iQM2m6Y30762ywBNDRcBv0ARudhV/ey+Tm CD8uYZLUWi7+0jImr7Yh+zFqzDBK5HCrm2refviHGbcOTCed2t+fAHcZgTiCcH3yV95I wfCT6ViFsryP6gS8zSDKcyLZnE8WKazATtB0ueP7VAh9ZhivzLgktCkbJaBmUmagQtgs tAjw== X-Gm-Message-State: AOAM533daD85y7J40oReI5pObpnH62qC/BiDaUIPYYjt9kzDnIAAh5Ut mM5yVCJexXcJh0+fEcXrvMWJjrduGVVBb6AfHnE= X-Google-Smtp-Source: ABdhPJybGtCIFlZiD66cVa4D3V0aHPKtEa8aplZAjjoPTES3GFlypgpFOjsZPqjjNpv3F5arDEd9Ag== X-Received: by 2002:adf:dccd:: with SMTP id x13mr9786410wrm.394.1605778974314; Thu, 19 Nov 2020 01:42:54 -0800 (PST) Received: from [127.0.1.1] (p200300c1071e7ceb4ca2621861925fee.dip0.t-ipconnect.de. [2003:c1:71e:7ceb:4ca2:6218:6192:5fee]) by smtp.gmail.com with ESMTPSA id k16sm38965823wrl.65.2020.11.19.01.42.53 for <~petersanchez/public-inbox@lists.code.netlandish.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Nov 2020 01:42:53 -0800 (PST) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Subject: [PATCH django-impersonate] clean up all warnings. mostly Django 4.0 deprecation X-Mercurial-Node: 1553f65e1488b9a3ef560fd8aad0c0c04a2722a5 X-Mercurial-Series-Index: 1 X-Mercurial-Series-Total: 1 Message-Id: <1553f65e1488b9a3ef56.1605778972@red> X-Mercurial-Series-Id: <1553f65e1488b9a3ef56.1605778972@red> User-Agent: Mercurial-patchbomb/5.6 Date: Thu, 19 Nov 2020 10:42:52 +0100 From: =?iso-8859-1?q?Leonhard_Kuboschek?= To: ~petersanchez/public-inbox@lists.code.netlandish.com # HG changeset patch # User Leonhard Kuboschek # Date 1605778760 -3600 # Thu Nov 19 10:39:20 2020 +0100 # Node ID 1553f65e1488b9a3ef560fd8aad0c0c04a2722a5 # Parent 926d80a74d429670db210b36fe9815462f6e4a31 clean up all warnings. mostly Django 4.0 deprecation diff --git a/impersonate/decorators.py b/impersonate/decorators.py --- a/impersonate/decorators.py +++ b/impersonate/decorators.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- +from urllib.parse import quote from django.conf import settings -from django.utils.http import urlquote from django.utils.encoding import force_str from django.shortcuts import redirect, resolve_url from django.contrib.auth import REDIRECT_FIELD_NAME @@ -18,7 +18,7 @@ return redirect(u'{0}?{1}={2}'.format( get_login_url(), REDIRECT_FIELD_NAME, - urlquote(request.get_full_path()), + quote(request.get_full_path()), )) if getattr(request.user, 'is_impersonate', False): diff --git a/impersonate/helpers.py b/impersonate/helpers.py --- a/impersonate/helpers.py +++ b/impersonate/helpers.py @@ -69,7 +69,7 @@ return custom_queryset_func(request) else: qs = User.objects.all() - if not User._meta.ordering: + if not qs.query.order_by: qs = qs.order_by('pk') return qs diff --git a/impersonate/signals.py b/impersonate/signals.py --- a/impersonate/signals.py +++ b/impersonate/signals.py @@ -11,19 +11,18 @@ logger = logging.getLogger(__name__) # signal sent when an impersonation session begins -session_begin = Signal( - providing_args=['impersonator', 'impersonating', 'request'] -) +# providing_args=['impersonator', 'impersonating', 'request'] +session_begin = Signal() # signal sent when an impersonation session ends -session_end = Signal( - providing_args=['impersonator', 'impersonating', 'request'] -) +# providing_args=['impersonator', 'impersonating', 'request'] +session_end = Signal() +ID_LENGTH = 12 def gen_unique_id(): return hashlib.sha1( - u'{0}:{1}'.format(get_random_string(), tz_now()).encode('utf-8') + u'{0}:{1}'.format(get_random_string(ID_LENGTH), tz_now()).encode('utf-8') ).hexdigest() diff --git a/impersonate/tests.py b/impersonate/tests.py --- a/impersonate/tests.py +++ b/impersonate/tests.py @@ -24,7 +24,7 @@ from urllib.parse import urlencode, urlsplit import django -from django.conf.urls import include, url +from django.urls import include, path from django.contrib.admin.sites import AdminSite from django.contrib.auth import get_user_model from django.http import HttpResponse @@ -54,9 +54,9 @@ urlpatterns = [ - url(r'^test-view/$', test_view, name='impersonate-test'), - url(r'^another-view/$', test_view, name='another-test-view'), - url('^', include('impersonate.urls')), + path('test-view/', test_view, name='impersonate-test'), + path('another-view/', test_view, name='another-test-view'), + path('', include('impersonate.urls')), ] @@ -78,7 +78,7 @@ ''' Used via the IMPERSONAT['CUSTOM_USER_QUERYSET'] setting. Simple function to return all users. ''' - return User.objects.all() + return User.objects.all().order_by('pk') class UserFactory(object): @@ -103,8 +103,12 @@ username='superuser', is_superuser=True, ) self.user = UserFactory.create(username='regular') + self.factory = RequestFactory() - self.middleware = ImpersonateMiddleware() + + def dummy_get_response(request): + return None + self.middleware = ImpersonateMiddleware(dummy_get_response) def _impersonated_request(self, use_id=True): request = self.factory.get('/') diff --git a/impersonate/urls.py b/impersonate/urls.py --- a/impersonate/urls.py +++ b/impersonate/urls.py @@ -1,22 +1,22 @@ # -*- coding: utf-8 -*- -from django.conf.urls import url +from django.urls import path from . import views urlpatterns = [ - url(r'^stop/$', + path('stop/', views.stop_impersonate, name='impersonate-stop'), - url(r'^list/$', + path('list/', views.list_users, {'template': 'impersonate/list_users.html'}, name='impersonate-list'), - url(r'^search/$', + path('search/', views.search_users, {'template': 'impersonate/search_users.html'}, name='impersonate-search'), - url(r'^(?P.+)/$', + path('/', views.impersonate, name='impersonate-start'), ]