Merge branch 'feature/stravaapi' into develop
This commit is contained in:
@@ -48,6 +48,9 @@ def analysis_new(request,
|
||||
firstworkout = get_workout(id)
|
||||
if not is_workout_team(request.user, firstworkout): # pragma: no cover
|
||||
raise PermissionDenied("You are not allowed to use this workout")
|
||||
if workout_is_strava(firstworkout):
|
||||
messages.error(request, "You cannot use Strava workouts for analysis")
|
||||
raise PermissionDenied("You cannot use Strava workouts for analysis")
|
||||
firstworkoutquery = Workout.objects.filter(id=encoder.decode_hex(id))
|
||||
|
||||
try:
|
||||
@@ -199,14 +202,14 @@ def analysis_new(request,
|
||||
startdatetime__lte=enddate,
|
||||
workouttype__in=modalities,
|
||||
rankingpiece__in=rankingtypes,
|
||||
)
|
||||
).exclude(workoutsource='strava')
|
||||
elif theteam is not None and theteam.viewing == 'coachonly': # pragma: no cover
|
||||
workouts = Workout.objects.filter(team=theteam, user=r,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
workouttype__in=modalities,
|
||||
rankingpiece__in=rankingtypes,
|
||||
)
|
||||
).exclude(workoutsource='strava')
|
||||
elif thesession is not None:
|
||||
workouts = get_workouts_session(r, thesession)
|
||||
else:
|
||||
@@ -218,6 +221,7 @@ def analysis_new(request,
|
||||
)
|
||||
if firstworkout:
|
||||
workouts = firstworkoutquery | workouts
|
||||
|
||||
workouts = workouts.order_by(
|
||||
"-date", "-starttime"
|
||||
).exclude(boattype__in=negtypes)
|
||||
@@ -253,7 +257,7 @@ def analysis_new(request,
|
||||
else:
|
||||
selectedworkouts = Workout.objects.filter(id__in=ids)
|
||||
|
||||
form.fields["workouts"].queryset = workouts | selectedworkouts
|
||||
form.fields["workouts"].queryset = (workouts | selectedworkouts).exclude(workoutsource='strava')
|
||||
|
||||
optionsform = AnalysisOptionsForm(initial={
|
||||
'modality': modality,
|
||||
@@ -363,6 +367,10 @@ def trendflexdata(workouts, options, userid=0):
|
||||
|
||||
savedata = options.get('savedata',False)
|
||||
|
||||
try:
|
||||
workouts = workouts.exclude(workoutsource='strava')
|
||||
except AttributeError: # pragma: no cover
|
||||
workouts = [w for w in workouts if w.workoutsource != 'strava']
|
||||
|
||||
fieldlist, fielddict = dataprep.getstatsfields()
|
||||
fieldlist = [xparam, yparam, groupby,
|
||||
@@ -566,6 +574,11 @@ def flexalldata(workouts, options):
|
||||
trendline = options['trendline']
|
||||
promember = True
|
||||
|
||||
try:
|
||||
workouts = workouts.exclude(workoutsource='strava')
|
||||
except AttributeError: # pragma: no cover
|
||||
workouts = [w for w in workouts if w.workoutsource != 'strava']
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
userid = options['userid']
|
||||
@@ -612,6 +625,12 @@ def histodata(workouts, options):
|
||||
workmax = options['workmax']
|
||||
userid = options['userid']
|
||||
|
||||
try:
|
||||
workouts = workouts.exclude(workoutsource='strava')
|
||||
except AttributeError: # pragma: no cover
|
||||
workouts = [w for w in workouts if w.workoutsource != 'strava']
|
||||
|
||||
|
||||
if userid == 0: # pragma: no cover
|
||||
extratitle = ''
|
||||
else:
|
||||
@@ -645,7 +664,8 @@ def cpdata(workouts, options):
|
||||
|
||||
u = User.objects.get(id=userid)
|
||||
r = u.rower
|
||||
|
||||
|
||||
|
||||
delta, cpvalue, avgpower, workoutnames, urls = dataprep.fetchcp_new(
|
||||
r, workouts)
|
||||
|
||||
@@ -798,6 +818,11 @@ def cpdata(workouts, options):
|
||||
|
||||
|
||||
def statsdata(workouts, options):
|
||||
try:
|
||||
workouts = workouts.exclude(workoutsource='strava')
|
||||
except AttributeError: # pragma: no cover
|
||||
workouts = [w for w in workouts if w.workoutsource != 'strava']
|
||||
|
||||
includereststrokes = options['includereststrokes']
|
||||
ids = options['ids']
|
||||
|
||||
@@ -872,12 +897,17 @@ def statsdata(workouts, options):
|
||||
|
||||
|
||||
def comparisondata(workouts, options):
|
||||
try:
|
||||
workouts = workouts.exclude(workoutsource='strava')
|
||||
except AttributeError: # pragma: no cover
|
||||
workouts = [w for w in workouts if w.workoutsource != 'strava']
|
||||
|
||||
includereststrokes = options['includereststrokes']
|
||||
xparam = options['xaxis']
|
||||
yparam1 = options['yaxis1']
|
||||
plottype = options['plottype']
|
||||
promember = True
|
||||
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
ids = [w.id for w in workouts]
|
||||
@@ -915,6 +945,10 @@ def comparisondata(workouts, options):
|
||||
|
||||
|
||||
def boxplotdata(workouts, options):
|
||||
try:
|
||||
workouts = workouts.exclude(workoutsource='strava')
|
||||
except AttributeError:
|
||||
workouts = [w for w in workouts if w.workoutsource != 'strava']
|
||||
|
||||
includereststrokes = options['includereststrokes']
|
||||
spmmin = options['spmmin']
|
||||
@@ -926,7 +960,7 @@ def boxplotdata(workouts, options):
|
||||
plotfield = options['plotfield']
|
||||
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
|
||||
datemapping = {
|
||||
w.id: w.date for w in workouts
|
||||
}
|
||||
@@ -1020,11 +1054,14 @@ def analysis_view_data(request, userid=0):
|
||||
|
||||
for id in ids:
|
||||
try:
|
||||
workouts.append(Workout.objects.get(id=id))
|
||||
w = Workout.objects.get(id=id)
|
||||
if w.workoutsource != 'strava':
|
||||
workouts.append(w)
|
||||
except Workout.DoesNotExist: # pragma: no cover
|
||||
pass
|
||||
|
||||
|
||||
|
||||
if function == 'boxplot':
|
||||
script, div = boxplotdata(workouts, options)
|
||||
elif function == 'trendflex': # pragma: no cover
|
||||
@@ -1069,7 +1106,7 @@ def create_marker_workouts_view(request, userid=0,
|
||||
workouts = Workout.objects.filter(user=theuser.rower, date__gte=startdate,
|
||||
date__lte=enddate,
|
||||
workouttype__in=mytypes.rowtypes,
|
||||
duplicate=False).order_by('date')
|
||||
duplicate=False).order_by('date').exclude(workoutsource='strava')
|
||||
|
||||
for workout in workouts:
|
||||
_ = dataprep.check_marker(workout)
|
||||
@@ -1113,7 +1150,7 @@ def goldmedalscores_view(request, userid=0,
|
||||
theuser, startdate=startdate, enddate=enddate,
|
||||
)
|
||||
|
||||
bestworkouts = Workout.objects.filter(id__in=ids).order_by('-date')
|
||||
bestworkouts = Workout.objects.filter(id__in=ids).order_by('-date').exclude(workoutsource='strava')
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
@@ -1311,7 +1348,7 @@ def performancemanager_view(request, userid=0, mode='rower',
|
||||
user = therower, date__gte=startdate-datetime.timedelta(days=90),
|
||||
date__lte=enddate,
|
||||
duplicate=False,
|
||||
rankingpiece=True, workouttype__in=mytypes.rowtypes).order_by('date')
|
||||
rankingpiece=True, workouttype__in=mytypes.rowtypes).order_by('date').exclude(workoutsource='strava')
|
||||
|
||||
ids = [w.id for w in markerworkouts]
|
||||
form = PerformanceManagerForm(initial={
|
||||
@@ -1323,7 +1360,7 @@ def performancemanager_view(request, userid=0, mode='rower',
|
||||
|
||||
ids = pd.Series(ids, dtype='int').dropna().values
|
||||
|
||||
bestworkouts = Workout.objects.filter(id__in=ids).order_by('-date')
|
||||
bestworkouts = Workout.objects.filter(id__in=ids).order_by('-date').exclude(workoutsource='strava')
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
@@ -2276,6 +2313,8 @@ def history_view_data(request, userid=0):
|
||||
ddf = ddf.with_columns(pl.col("time").diff().clip(lower_bound=0).alias("deltat"))
|
||||
except KeyError: # pragma: no cover
|
||||
pass
|
||||
except ColumnNotFoundError:
|
||||
pass
|
||||
|
||||
ddf = dataprep.clean_df_stats_pl(ddf, workstrokesonly=False,
|
||||
ignoreadvanced=True)
|
||||
@@ -2288,6 +2327,8 @@ def history_view_data(request, userid=0):
|
||||
ddict['hrmax'] = int(ddf['hr'].max())
|
||||
except (KeyError, ValueError, AttributeError, ColumnNotFoundError): # pragma: no cover
|
||||
ddict['hrmax'] = 0
|
||||
except ColumnNotFoundError:
|
||||
ddict['hrmax'] = 0
|
||||
|
||||
ddict['powermean'] = int(wavg(ddf, 'power', 'deltat'))
|
||||
try:
|
||||
|
||||
@@ -3397,12 +3397,12 @@ def virtualevent_submit_result_view(request, id=0, workoutid=0):
|
||||
startdatetime__gte=startdatetime,
|
||||
startdatetime__lte=enddatetime,
|
||||
distance__gte=race.approximate_distance,
|
||||
).order_by("-date", "-startdatetime", "id")
|
||||
).order_by("-date", "-startdatetime", "id").exclude(workoutsource='strava')
|
||||
|
||||
if not ws: # pragma: no cover
|
||||
messages.info(
|
||||
request,
|
||||
'You have no workouts executed during the race window. Please upload a result or enter it manually.'
|
||||
'You have no eligible workouts executed during the race window. Please upload a result or enter it manually.'
|
||||
)
|
||||
|
||||
url = reverse('virtualevent_view',
|
||||
@@ -3436,6 +3436,7 @@ def virtualevent_submit_result_view(request, id=0, workoutid=0):
|
||||
splitsecond = 0
|
||||
recordid = w_form.cleaned_data['record']
|
||||
else:
|
||||
messages.error(request,"Error in form")
|
||||
selectedworkout = None
|
||||
|
||||
if selectedworkout is not None:
|
||||
@@ -3518,7 +3519,12 @@ def virtualevent_submit_result_view(request, id=0, workoutid=0):
|
||||
|
||||
else:
|
||||
if workoutid:
|
||||
workoutdata['initial'] = encoder.decode_hex(workoutid)
|
||||
try:
|
||||
w = Workout.objects.get(id=workoutid)
|
||||
if w.workoutsource != 'strava':
|
||||
workoutdata['initial'] = encoder.decode_hex(workoutid)
|
||||
except Workout.DoesNotExist:
|
||||
pass
|
||||
w_form = WorkoutRaceSelectForm(workoutdata, entries)
|
||||
|
||||
breadcrumbs = [
|
||||
|
||||
@@ -28,6 +28,7 @@ from rest_framework.response import Response
|
||||
from rq.job import Job
|
||||
from rules.contrib.views import permission_required, objectgetter
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.utils.crypto import get_random_string
|
||||
from rq.registry import StartedJobRegistry
|
||||
from rq.exceptions import NoSuchJobError
|
||||
@@ -81,7 +82,8 @@ from rowers.rower_rules import (
|
||||
can_add_workout_member, can_plan_user, is_paid_coach,
|
||||
can_start_trial, can_start_plantrial, can_start_coachtrial,
|
||||
can_plan, is_workout_team,
|
||||
is_promember,user_is_basic, is_coachtrial, is_coach
|
||||
is_promember,user_is_basic, is_coachtrial, is_coach,
|
||||
workout_is_strava
|
||||
)
|
||||
|
||||
from django.shortcuts import render
|
||||
|
||||
@@ -2204,25 +2204,25 @@ def workouts_view(request, message='', successmessage='',
|
||||
team=theteam,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
privacy='visible').order_by("-date", "-starttime")
|
||||
privacy='visible').order_by("-date", "-starttime").exclude(workoutsource='strava')
|
||||
g_workouts = Workout.objects.filter(
|
||||
team=theteam,
|
||||
startdatetime__gte=activity_startdate,
|
||||
startdatetime__lte=activity_enddate,
|
||||
duplicate=False,
|
||||
privacy='visible').order_by("-date", "-starttime")
|
||||
privacy='visible').order_by("-date", "-starttime").exclude(workoutsource='strava')
|
||||
elif theteam.viewing == 'coachonly': # pragma: no cover
|
||||
workouts = Workout.objects.filter(
|
||||
team=theteam, user=r,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
privacy='visible').order_by("-startdatetime")
|
||||
privacy='visible').order_by("-startdatetime").exclude(workoutsource='strava')
|
||||
g_workouts = Workout.objects.filter(
|
||||
team=theteam, user=r,
|
||||
startdatetime__gte=activity_startdate,
|
||||
startdatetime__lte=activity_enddate,
|
||||
duplicate=False,
|
||||
privacy='visible').order_by("-startdatetime")
|
||||
privacy='visible').order_by("-startdatetime").exclude(workoutsource='strava')
|
||||
|
||||
elif request.user != r.user:
|
||||
theteam = None
|
||||
@@ -2230,13 +2230,13 @@ def workouts_view(request, message='', successmessage='',
|
||||
user=r,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate,
|
||||
privacy='visible').order_by("-date", "-starttime")
|
||||
privacy='visible').order_by("-date", "-starttime").exclude(workoutsource='strava')
|
||||
g_workouts = Workout.objects.filter(
|
||||
user=r,
|
||||
startdatetime__gte=activity_startdate,
|
||||
startdatetime__lte=activity_enddate,
|
||||
duplicate=False,
|
||||
privacy='visible').order_by("-startdatetime")
|
||||
privacy='visible').order_by("-startdatetime").exclude(workoutsource='strava')
|
||||
else:
|
||||
theteam = None
|
||||
workouts = Workout.objects.filter(
|
||||
@@ -2252,7 +2252,7 @@ def workouts_view(request, message='', successmessage='',
|
||||
if g_workouts.count() == 0:
|
||||
g_workouts = Workout.objects.filter(
|
||||
user=r,
|
||||
startdatetime__gte=timezone.now()-timedelta(days=15)).order_by("-startdatetime")
|
||||
startdatetime__gte=timezone.now()-timedelta(days=15)).order_by("-startdatetime").exclude(workoutsource='strava')
|
||||
g_enddate = timezone.now()
|
||||
g_startdate = (timezone.now()-timedelta(days=15))
|
||||
|
||||
@@ -2266,7 +2266,8 @@ def workouts_view(request, message='', successmessage='',
|
||||
reduce(operator.and_,
|
||||
(Q(name__icontains=q) for q in query_list)) |
|
||||
reduce(operator.and_,
|
||||
(Q(notes__icontains=q) for q in query_list))
|
||||
(Q(notes__icontains=q) for q in query_list)),
|
||||
exclude_strava=False,
|
||||
)
|
||||
searchform = SearchForm(initial={'q': query})
|
||||
else:
|
||||
@@ -4933,7 +4934,7 @@ def workout_upload_api(request):
|
||||
|
||||
# only allow local host
|
||||
hostt = request.get_host().split(':')
|
||||
if hostt[0] not in ['localhost', '127.0.0.1', 'dev.rowsandall.com', 'rowsandall.com']:
|
||||
if hostt[0] not in ['localhost', '127.0.0.1', 'dev.rowsandall.com', 'rowsandall.com','testserver']:
|
||||
message = {'status': 'false',
|
||||
'message': 'permission denied for host '+hostt[0]}
|
||||
return JSONResponse(status=403, data=message)
|
||||
@@ -4986,6 +4987,7 @@ def workout_upload_api(request):
|
||||
boatname = post_data.get('boatName','')
|
||||
portStarboard = post_data.get('portStarboard', 1)
|
||||
empowerside = 'port'
|
||||
stravaid = post_data.get('stravaid','')
|
||||
if portStarboard == 1:
|
||||
empowerside = 'starboard'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user