C2 upload tested and working
This commit is contained in:
@@ -741,6 +741,25 @@ def getsmallrowdata_db(columns,ids=[],debug=False):
|
||||
|
||||
return df
|
||||
|
||||
def update_workout_field_sql(workoutid,fieldname,value,debug=False):
|
||||
if debug:
|
||||
engine = create_engine(database_url_debug, echo=False)
|
||||
else:
|
||||
engine = create_engine(database_url, echo=False)
|
||||
|
||||
table = 'rowers_workout'
|
||||
|
||||
query = "UPDATE %s SET %s = %s WHERE `id` = %s;" % (table,fieldname,value,workoutid)
|
||||
|
||||
|
||||
with engine.connect() as conn, conn.begin():
|
||||
result = conn.execute(query)
|
||||
|
||||
conn.close()
|
||||
engine.dispose()
|
||||
|
||||
return 1
|
||||
|
||||
def update_c2id_sql(id,c2id):
|
||||
engine = create_engine(database_url, echo=False)
|
||||
table = 'rowers_workout'
|
||||
|
||||
@@ -76,6 +76,7 @@ def strip_tags(html):
|
||||
from rowers.dataprepnodjango import (
|
||||
update_strokedata, new_workout_from_file,
|
||||
getsmallrowdata_db, updatecpdata_sql,update_c2id_sql,
|
||||
update_workout_field_sql,
|
||||
update_agegroup_db,fitnessmetric_to_sql,
|
||||
add_c2_stroke_data_db,totaltime_sec_to_string,
|
||||
create_c2_stroke_data_db,update_empower,
|
||||
@@ -122,7 +123,7 @@ def add(x, y):
|
||||
|
||||
|
||||
@app.task
|
||||
def handle_c2_sync(workoutid,url,headers,data,debug=True,**kwargs):
|
||||
def handle_c2_sync(workoutid,url,headers,data,debug=False,**kwargs):
|
||||
response = requests.post(url,headers=headers,data=data)
|
||||
if response.status_code not in [200,201]:
|
||||
return 0
|
||||
@@ -130,7 +131,7 @@ def handle_c2_sync(workoutid,url,headers,data,debug=True,**kwargs):
|
||||
s = response.json()
|
||||
c2id = s['data']['id']
|
||||
|
||||
res = update_c2id_sql(workoutid,c2id)
|
||||
res = update_workout_field_sql(workoutid,'uploadedtoc2',c2id,debug=debug)
|
||||
|
||||
return res
|
||||
|
||||
|
||||
@@ -4810,7 +4810,7 @@ def workout_upload_view(request,
|
||||
# upload to C2
|
||||
if (upload_to_c2):
|
||||
try:
|
||||
message,id = c2stuff.workout_c2_upload(request.user,w)
|
||||
message,id = c2stuff.workout_c2_upload(request.user,w,asynchron=True)
|
||||
except NoTokenError:
|
||||
id = 0
|
||||
message = "Something went wrong with the Concept2 sync"
|
||||
|
||||
Reference in New Issue
Block a user