adding sessions sync
This commit is contained in:
@@ -1455,6 +1455,9 @@ def plannedsessions_view(request,
|
||||
except PermissionDenied: # pragma: no cover
|
||||
r = request.user.rower
|
||||
|
||||
do_intervals_icu_sync = request.GET.get('icu_sync', False)
|
||||
|
||||
|
||||
if startdatestring: # pragma: no cover
|
||||
try:
|
||||
startdate = iso8601.parse_date(startdatestring)
|
||||
@@ -1475,6 +1478,14 @@ def plannedsessions_view(request,
|
||||
startdate = startdate.date()
|
||||
enddate = enddate.date()
|
||||
|
||||
if do_intervals_icu_sync: # pragma: no cover
|
||||
integration = IntervalsIntegration(request.user)
|
||||
newids = integration.get_plannedsessions(kwargs={'newest':startdate.strftime('%Y-%m-%d'),
|
||||
'oldest':enddate.strftime('%Y-%m-%d')})
|
||||
for id in newids:
|
||||
messages.info(request, "Session {id} imported from ICU".format(id=id))
|
||||
|
||||
|
||||
try:
|
||||
trainingplan = TrainingPlan.objects.filter(
|
||||
startdate__lte=startdate,
|
||||
@@ -1573,6 +1584,11 @@ def plannedsessions_view(request,
|
||||
totals['plannedtrimp'] += ps.sessionvalue
|
||||
else:
|
||||
totals['plannedtrimp'] += ps.approximate_rscore*2
|
||||
if ps.intervals_icu_id is None and do_intervals_icu_sync: # pragma: no cover
|
||||
intervals = IntervalsIntegration(request.user)
|
||||
result = intervals.plannedsession_create(ps)
|
||||
messages.info(request, "Session {id} synced to ICU".format(id=ps.id))
|
||||
|
||||
|
||||
totals['time'] = int(totals['time']/60.)
|
||||
totals['actualtime'] = int(totals['actualtime']/60.)
|
||||
|
||||
Reference in New Issue
Block a user