moved user and workout permission checks to rules
updated workoutviews, rest of views not done doesn't pass tests
This commit is contained in:
@@ -38,7 +38,7 @@ from django.contrib.auth.decorators import login_required
|
||||
from rowingdata import rowingdata
|
||||
import pandas as pd
|
||||
from rowers.models import Rower,Workout
|
||||
from rowers.models import checkworkoutuser
|
||||
|
||||
import rowers.dataprep as dataprep
|
||||
from rowers.dataprep import columndict
|
||||
|
||||
@@ -50,7 +50,7 @@ from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
||||
from django_mailbox.models import Message,Mailbox,MessageAttachment
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
POLAR_CLIENT_ID, POLAR_REDIRECT_URI, POLAR_CLIENT_SECRET,
|
||||
POLAR_CLIENT_ID, POLAR_REDIRECT_URI, POLAR_CLIENT_SECRET,
|
||||
)
|
||||
|
||||
#baseurl = 'https://polaraccesslink.com/v3-example'
|
||||
@@ -79,7 +79,7 @@ def get_token(code):
|
||||
except TypeError:
|
||||
headers = { 'Authorization': 'Basic %s' % base64.b64encode(
|
||||
bytes(auth_string,'utf-8')).decode('utf-8') }
|
||||
|
||||
|
||||
response = requests.post("https://polarremote.com/v2/oauth2/token",
|
||||
data=post_data,
|
||||
headers=headers)
|
||||
@@ -110,7 +110,7 @@ def make_authorization_url():
|
||||
import urllib
|
||||
url = "https://flow.polar.com/oauth2/authorization" +urllib.parse.urlencode(params)
|
||||
|
||||
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
def get_polar_notifications():
|
||||
@@ -130,13 +130,13 @@ def get_polar_notifications():
|
||||
response = requests.get(url, headers=headers)
|
||||
|
||||
available_data = []
|
||||
|
||||
|
||||
if response.status_code == 200:
|
||||
available_data = response.json()['available-user-data']
|
||||
|
||||
|
||||
return available_data
|
||||
|
||||
from rowers.utils import isprorower
|
||||
from rowers.rower_rules import ispromember
|
||||
|
||||
def get_all_new_workouts(available_data,testing=False):
|
||||
for record in available_data:
|
||||
@@ -146,7 +146,7 @@ def get_all_new_workouts(available_data,testing=False):
|
||||
try:
|
||||
r = Rower.objects.get(polaruserid=record['user-id'])
|
||||
u = r.user
|
||||
if r.polar_auto_import and isprorower(r):
|
||||
if r.polar_auto_import and ispromember(u):
|
||||
exercise_list = get_polar_workouts(u)
|
||||
if testing:
|
||||
print(exercise_list)
|
||||
@@ -154,13 +154,13 @@ def get_all_new_workouts(available_data,testing=False):
|
||||
pass
|
||||
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
def get_polar_workouts(user):
|
||||
r = Rower.objects.get(user=user)
|
||||
|
||||
exercise_list = []
|
||||
|
||||
|
||||
if (r.polartoken == '') or (r.polartoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
return custom_exception_handler(401,s)
|
||||
@@ -195,7 +195,7 @@ def get_polar_workouts(user):
|
||||
uploadoptions,
|
||||
default_flow_style=False
|
||||
)
|
||||
|
||||
|
||||
transactionid = response.json()['transaction-id']
|
||||
url = baseurl+'/users/{userid}/exercise-transactions/{transactionid}'.format(
|
||||
transactionid = transactionid,
|
||||
@@ -229,11 +229,11 @@ def get_polar_workouts(user):
|
||||
|
||||
a = MessageAttachment(message=msg,document=filename[6:])
|
||||
a.save()
|
||||
|
||||
|
||||
exercise_dict['filename'] = filename
|
||||
else:
|
||||
exercise_dict['filename'] = ''
|
||||
|
||||
|
||||
exercise_list.append(exercise_dict)
|
||||
|
||||
# commit transaction
|
||||
@@ -280,7 +280,7 @@ def get_polar_user_info(user,physical=False):
|
||||
|
||||
|
||||
def get_polar_workout(user,id,transactionid):
|
||||
|
||||
|
||||
r = Rower.objects.get(user=user)
|
||||
if (r.polartoken == '') or (r.polartoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
@@ -326,7 +326,7 @@ def get_polar_workout(user,id,transactionid):
|
||||
)
|
||||
|
||||
response = requests.get(url,headers = headers2)
|
||||
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.text
|
||||
# commit transaction
|
||||
@@ -337,7 +337,3 @@ def get_polar_workout(user,id,transactionid):
|
||||
return result
|
||||
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user