review duplicates upon delete workout
This commit is contained in:
@@ -1 +0,0 @@
|
|||||||
E408191@CZ27LT9RCGN72.21348:1542056188
|
|
||||||
@@ -999,7 +999,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
|||||||
maxhr = np.nan_to_num(maxhr)
|
maxhr = np.nan_to_num(maxhr)
|
||||||
averagehr = np.nan_to_num(averagehr)
|
averagehr = np.nan_to_num(averagehr)
|
||||||
|
|
||||||
duplicate = True
|
duplicate = False
|
||||||
|
|
||||||
t = datetime.datetime.strptime(duration,"%H:%M:%S.%f")
|
t = datetime.datetime.strptime(duration,"%H:%M:%S.%f")
|
||||||
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
||||||
@@ -1007,7 +1007,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
|||||||
workoutenddatetime = workoutstartdatetime+delta
|
workoutenddatetime = workoutstartdatetime+delta
|
||||||
|
|
||||||
# check for duplicate start times and duration
|
# check for duplicate start times and duration
|
||||||
ws = Workout.objects.filter(user=r,date=workoutdate).exclude(
|
ws = Workout.objects.filter(user=r,date=workoutdate,duplicate=False).exclude(
|
||||||
startdatetime__gt=workoutenddatetime
|
startdatetime__gt=workoutenddatetime
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1019,7 +1019,8 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
|||||||
enddatetime = ww.startdatetime+delta
|
enddatetime = ww.startdatetime+delta
|
||||||
if enddatetime > workoutstartdatetime:
|
if enddatetime > workoutstartdatetime:
|
||||||
ws2.append(ww)
|
ws2.append(ww)
|
||||||
|
|
||||||
|
|
||||||
if (len(ws2) != 0):
|
if (len(ws2) != 0):
|
||||||
message = "Warning: This workout overlaps with an existing one and was marked as a duplicate"
|
message = "Warning: This workout overlaps with an existing one and was marked as a duplicate"
|
||||||
duplicate = True
|
duplicate = True
|
||||||
|
|||||||
@@ -2182,7 +2182,42 @@ def auto_delete_file_on_delete(sender, instance, **kwargs):
|
|||||||
if instance.csvfilename+'.gz':
|
if instance.csvfilename+'.gz':
|
||||||
if os.path.isfile(instance.csvfilename+'.gz'):
|
if os.path.isfile(instance.csvfilename+'.gz'):
|
||||||
os.remove(instance.csvfilename+'.gz')
|
os.remove(instance.csvfilename+'.gz')
|
||||||
|
|
||||||
|
@receiver(models.signals.post_delete,sender=Workout)
|
||||||
|
def update_duplicates_on_delete(sender, instance, **kwargs):
|
||||||
|
if instance.id:
|
||||||
|
|
||||||
|
duplicates = Workout.objects.filter(
|
||||||
|
user=instance.user,date=instance.date,
|
||||||
|
duplicate=True)
|
||||||
|
|
||||||
|
for d in duplicates:
|
||||||
|
t = d.duration
|
||||||
|
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
||||||
|
workoutenddatetime = d.startdatetime+delta
|
||||||
|
ws = Workout.objects.filter(
|
||||||
|
user=d.user,date=d.date,
|
||||||
|
).exclude(
|
||||||
|
pk__in=[instance.pk,d.pk]
|
||||||
|
).exclude(
|
||||||
|
startdatetime__gt=workoutenddatetime
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
ws2 = []
|
||||||
|
|
||||||
|
for ww in ws:
|
||||||
|
t = ww.duration
|
||||||
|
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
||||||
|
enddatetime = ww.startdatetime+delta
|
||||||
|
if enddatetime > d.startdatetime:
|
||||||
|
ws2.append(ww)
|
||||||
|
|
||||||
|
if len(ws2) == 0:
|
||||||
|
d.duplicate=False
|
||||||
|
d.save()
|
||||||
|
|
||||||
|
|
||||||
# Delete stroke data from the database when a workout is deleted
|
# Delete stroke data from the database when a workout is deleted
|
||||||
@receiver(models.signals.post_delete,sender=Workout)
|
@receiver(models.signals.post_delete,sender=Workout)
|
||||||
def auto_delete_strokedata_on_delete(sender, instance, **kwargs):
|
def auto_delete_strokedata_on_delete(sender, instance, **kwargs):
|
||||||
|
|||||||
@@ -9859,6 +9859,11 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
rankingpiece =- Workout.objects.get(id=id).rankingpiece
|
rankingpiece =- Workout.objects.get(id=id).rankingpiece
|
||||||
|
|
||||||
|
try:
|
||||||
|
duplicate = form.cleaned_data['duplicate']
|
||||||
|
except KeyError:
|
||||||
|
duplicate = Workout.objects.get(id=id).duplicate
|
||||||
|
|
||||||
if private:
|
if private:
|
||||||
privacy = 'private'
|
privacy = 'private'
|
||||||
else:
|
else:
|
||||||
@@ -9898,6 +9903,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
|||||||
row.duration = duration
|
row.duration = duration
|
||||||
row.distance = distance
|
row.distance = distance
|
||||||
row.boattype = boattype
|
row.boattype = boattype
|
||||||
|
row.duplicate = duplicate
|
||||||
row.privacy = privacy
|
row.privacy = privacy
|
||||||
row.rankingpiece = rankingpiece
|
row.rankingpiece = rankingpiece
|
||||||
row.timezone = thetimezone
|
row.timezone = thetimezone
|
||||||
|
|||||||
Reference in New Issue
Block a user