removing some duplicate code
This commit is contained in:
@@ -34,40 +34,15 @@ from rowers.models import Rower,Workout,checkworkoutuser
|
||||
|
||||
from rowsandall_app.settings import C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET, STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET, SPORTTRACKS_CLIENT_SECRET, SPORTTRACKS_CLIENT_ID, SPORTTRACKS_REDIRECT_URI
|
||||
|
||||
# Custom error class - to raise a NoTokenError
|
||||
class SportTracksNoTokenError(Exception):
|
||||
def __init__(self,value):
|
||||
self.value=value
|
||||
from utils import NoTokenError, custom_exception_handler
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.value)
|
||||
|
||||
|
||||
# Custom exception handler, returns a 401 HTTP message
|
||||
# with exception details in the json data
|
||||
def custom_exception_handler(exc,message):
|
||||
|
||||
response = {
|
||||
"errors": [
|
||||
{
|
||||
"code": str(exc),
|
||||
"detail": message,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
res = HttpResponse(message)
|
||||
res.status_code = 401
|
||||
res.json = json.dumps(response)
|
||||
|
||||
return res
|
||||
|
||||
# Checks if user has SportTracks token, renews them if they are expired
|
||||
def sporttracks_open(user):
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.sporttrackstoken == '') or (r.sporttrackstoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
raise SportTracksNoTokenError("User has no token")
|
||||
raise NoTokenError("User has no token")
|
||||
else:
|
||||
if (timezone.now()>r.sporttrackstokenexpirydate):
|
||||
thetoken = rower_sporttracks_token_refresh(user)
|
||||
|
||||
Reference in New Issue
Block a user