From 487d86bee3f4ea10c7d8d5db166182ab2ad9fdc8 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sat, 10 Mar 2018 10:54:13 -0500 Subject: [PATCH] Fix that HttpServerError now takes a request as parameter --- pgweb/account/views.py | 12 ++++++------ pgweb/core/views.py | 4 ++-- pgweb/downloads/views.py | 10 +++++----- pgweb/survey/views.py | 4 ++-- pgweb/util/helpers.py | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pgweb/account/views.py b/pgweb/account/views.py index 07944554..b9db6265 100644 --- a/pgweb/account/views.py +++ b/pgweb/account/views.py @@ -142,7 +142,7 @@ def change_email(request): if request.user.password == OAUTH_PASSWORD_STORE: # Link shouldn't exist in this case, so just throw an unfriendly # error message. - return HttpServerError("This account cannot change email address as it's connected to a third party login site.") + return HttpServerError(request, "This account cannot change email address as it's connected to a third party login site.") if request.method == 'POST': form = ChangeEmailForm(request.user, data=request.POST) @@ -181,7 +181,7 @@ def confirm_change_email(request, tokenhash): if request.user.password == OAUTH_PASSWORD_STORE: # Link shouldn't exist in this case, so just throw an unfriendly # error message. - return HttpServerError("This account cannot change email address as it's connected to a third party login site.") + return HttpServerError(request, "This account cannot change email address as it's connected to a third party login site.") if token: # Valid token find, so change the email address @@ -227,7 +227,7 @@ def logout(request): def changepwd(request): if hasattr(request.user, 'password') and request.user.password == OAUTH_PASSWORD_STORE: - return HttpServerError("This account cannot change password as it's connected to a third party login site.") + return HttpServerError(request, "This account cannot change password as it's connected to a third party login site.") log.info("Initiating password change from {0}".format(get_client_ip(request))) return authviews.password_change(request, @@ -239,7 +239,7 @@ def resetpwd(request): try: u = User.objects.get(email__iexact=request.POST['email']) if u.password == OAUTH_PASSWORD_STORE: - return HttpServerError("This account cannot change password as it's connected to a third party login site.") + return HttpServerError(request, "This account cannot change password as it's connected to a third party login site.") except User.DoesNotExist: log.info("Attempting to reset password of {0}, user not found".format(request.POST['email'])) log.info("Initiating password set from {0}".format(get_client_ip(request))) @@ -269,7 +269,7 @@ def reset_complete(request): def signup(request): if request.user.is_authenticated(): - return HttpServerError("You must log out before you can sign up for a new account") + return HttpServerError(request, "You must log out before you can sign up for a new account") if request.method == 'POST': # Attempt to create user then, eh? @@ -328,7 +328,7 @@ def signup_oauth(request): if not request.session.has_key('oauth_email') \ or not request.session.has_key('oauth_firstname') \ or not request.session.has_key('oauth_lastname'): - return HttpServerError('Invalid redirect received') + return HttpServerError(request, 'Invalid redirect received') if request.method == 'POST': # Second stage, so create the account. But verify that the diff --git a/pgweb/core/views.py b/pgweb/core/views.py index 249506fa..ef3380b8 100644 --- a/pgweb/core/views.py +++ b/pgweb/core/views.py @@ -284,9 +284,9 @@ def admin_purge(request): @csrf_exempt def api_varnish_purge(request): if not request.META['REMOTE_ADDR'] in settings.VARNISH_PURGERS: - return HttpServerError("Invalid client address") + return HttpServerError(request, "Invalid client address") if request.method != 'POST': - return HttpServerError("Can't use this way") + return HttpServerError(request, "Can't use this way") n = int(request.POST['n']) curs = connection.cursor() for i in range(0, n): diff --git a/pgweb/downloads/views.py b/pgweb/downloads/views.py index 76003369..26bdc793 100644 --- a/pgweb/downloads/views.py +++ b/pgweb/downloads/views.py @@ -41,7 +41,7 @@ def ftpbrowser(request, subpath): allnodes = pickle.load(f) f.close() except Exception, e: - return HttpServerError("Failed to load ftp site information: %s" % e) + return HttpServerError(request, "Failed to load ftp site information: %s" % e) # An incoming subpath may either be canonical, or have one or more elements # present that are actually symlinks. For each element of the path, test to @@ -129,9 +129,9 @@ def ftpbrowser(request, subpath): @csrf_exempt def uploadftp(request): if request.method != 'PUT': - return HttpServerError("Invalid method") + return HttpServerError(request, "Invalid method") if not request.META['REMOTE_ADDR'] in settings.FTP_MASTERS: - return HttpServerError("Invalid client address") + return HttpServerError(request, "Invalid client address") # We have the data in request.body. Attempt to load it as # a pickle to make sure it's properly formatted pickle.loads(request.body) @@ -159,9 +159,9 @@ def uploadftp(request): @csrf_exempt def uploadyum(request): if request.method != 'PUT': - return HttpServerError("Invalid method") + return HttpServerError(request, "Invalid method") if not request.META['REMOTE_ADDR'] in settings.FTP_MASTERS: - return HttpServerError("Invalid client address") + return HttpServerError(request, "Invalid client address") # We have the data in request.body. Attempt to load it as # json to ensure correct format. json.loads(request.body) diff --git a/pgweb/survey/views.py b/pgweb/survey/views.py index eb5cad2a..d4ca26fd 100644 --- a/pgweb/survey/views.py +++ b/pgweb/survey/views.py @@ -28,7 +28,7 @@ def vote(request, surveyid): try: ansnum = int(request.POST['answer']) if ansnum < 1 or ansnum > 8: - return HttpServerError("Invalid answer") + return HttpServerError(request, "Invalid answer") except: # When no answer is given, redirect to results instead return HttpResponseRedirect("/community/survey/%s-%s" % (surv.id, slugify(surv.question))) @@ -44,7 +44,7 @@ def vote(request, surveyid): # Check if we are locked lock = SurveyLock.objects.filter(ipaddr=addr) if len(lock) > 0: - return HttpServerError("Too many requests from your IP in the past 15 minutes") + return HttpServerError(request, "Too many requests from your IP in the past 15 minutes") # Generate a new lock item, and store it lock = SurveyLock(ipaddr=addr) diff --git a/pgweb/util/helpers.py b/pgweb/util/helpers.py index 15632b3e..0b17a6c1 100644 --- a/pgweb/util/helpers.py +++ b/pgweb/util/helpers.py @@ -78,7 +78,7 @@ def simple_form(instancetype, itemid, request, formclass, formtemplate='base/for def template_to_string(templatename, attrs = {}): return get_template(templatename).render(Context(attrs)) -def HttpServerError(msg): +def HttpServerError(request, msg): r = render(request, 'errors/500.html', { 'message': msg, }) -- 2.39.5