Change are-we-logged-in detection to be less hackish.
- has matching changes in controller staff_grading view.
This commit is contained in:
@@ -77,15 +77,16 @@ class StaffGradingService(object):
|
|||||||
def _try_with_login(self, operation):
|
def _try_with_login(self, operation):
|
||||||
"""
|
"""
|
||||||
Call operation(), which should return a requests response object. If
|
Call operation(), which should return a requests response object. If
|
||||||
the response status code is 302, call _login() and try the operation
|
the request fails with a 'login_required' error, call _login() and try
|
||||||
again. NOTE: use requests.get(..., allow_redirects=False) to have
|
the operation again.
|
||||||
requests not auto-follow redirects.
|
|
||||||
|
|
||||||
Returns the result of operation(). Does not catch exceptions.
|
Returns the result of operation(). Does not catch exceptions.
|
||||||
"""
|
"""
|
||||||
response = operation()
|
response = operation()
|
||||||
if response.status_code == 302:
|
if (response.json
|
||||||
# redirect means we aren't logged in
|
and response.json.get('success') == False
|
||||||
|
and response.json.get('error') == 'login_required'):
|
||||||
|
# apparrently we aren't logged in. Try to fix that.
|
||||||
r = self._login()
|
r = self._login()
|
||||||
if r and not r.get('success'):
|
if r and not r.get('success'):
|
||||||
log.warning("Couldn't log into staff_grading backend. Response: %s",
|
log.warning("Couldn't log into staff_grading backend. Response: %s",
|
||||||
|
|||||||
Reference in New Issue
Block a user