Private
Public Access
1
0

fixing import errors

This commit is contained in:
Sander Roosendaal
2023-02-20 19:43:50 +01:00
parent 9d49faee69
commit f6c0f878f3
3 changed files with 16 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
from abc import ABCMeta, ABC, abstractmethod from abc import ABCMeta, ABC, abstractmethod
from importlib import import_module from importlib import import_module
from rowers.models import Rower, User from rowers.models import Rower, User
from rowers.utils import NoTokenError from rowers.utils import NoTokenError,dologging
import requests import requests
from django.utils import timezone from django.utils import timezone
@@ -85,6 +85,7 @@ class SyncIntegration(metaclass=ABCMeta):
@abstractmethod @abstractmethod
def get_token(self, code, *args, **kwargs) -> (str, int, str): def get_token(self, code, *args, **kwargs) -> (str, int, str):
logfile = kwargs.get('logfile',None)
redirect_uri = self.oauth_data['redirect_uri'] redirect_uri = self.oauth_data['redirect_uri']
client_secret = self.oauth_data['client_secret'] client_secret = self.oauth_data['client_secret']
client_id = self.oauth_data['client_id'] client_id = self.oauth_data['client_id']
@@ -127,6 +128,9 @@ class SyncIntegration(metaclass=ABCMeta):
try: try:
thetoken = token_json['access_token'] thetoken = token_json['access_token']
except KeyError: # pragma: no cover except KeyError: # pragma: no cover
if logfile:
s = json.dumps(token_json)
dologging(logfile,s)
raise NoTokenError("Failed to obtain token") raise NoTokenError("Failed to obtain token")
try: try:
refresh_token = token_json['refresh_token'] refresh_token = token_json['refresh_token']
@@ -145,6 +149,8 @@ class SyncIntegration(metaclass=ABCMeta):
except (ValueError, TypeError): # pragma: no cover except (ValueError, TypeError): # pragma: no cover
expires_in = 0 expires_in = 0
else: # pragma: no cover else: # pragma: no cover
if logfile:
dologging(logfile,response.text)
raise NoTokenError("Failed to obtain token") raise NoTokenError("Failed to obtain token")
return [thetoken, expires_in, refresh_token] return [thetoken, expires_in, refresh_token]

Binary file not shown.

View File

@@ -455,7 +455,14 @@ def rower_process_stravacallback(request):
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
res = strava_integration.get_token(code) try:
res = strava_integration.get_token(code,logfile='strava_log.log')
except NoTokenError:
message = "Something went wrong with the Strava authorization"
messages.error(request, message)
url = reverse('rower_exportsettings_view')
return HttpResponseRedirect(url)
if res[0]: if res[0]:
access_token = res[0] access_token = res[0]