Merge branch 'release/v12.42'
This commit is contained in:
@@ -481,6 +481,12 @@ def join_workouts(r,ids,title='Joined Workout',
|
||||
for w in ws:
|
||||
w.delete()
|
||||
|
||||
w = Workout.objects.get(id=id)
|
||||
w.duplicate = False
|
||||
w.save()
|
||||
if message is not None and "duplicate" in message:
|
||||
message = ""
|
||||
|
||||
return (id, message)
|
||||
|
||||
|
||||
|
||||
65
rowers/management/commands/autojoin.py
Normal file
65
rowers/management/commands/autojoin.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import sys
|
||||
import os
|
||||
|
||||
import requests
|
||||
import datetime
|
||||
import arrow
|
||||
from django.utils import timezone
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from rowers.models import Rower,Workout
|
||||
import re
|
||||
from django.db.models import Q
|
||||
from rowers.dataprep import join_workouts
|
||||
|
||||
def name_short(name):
|
||||
expr = '(.*)\s.*\(\d+\)'
|
||||
match = re.findall(expr,name)
|
||||
|
||||
if match:
|
||||
return match[0]
|
||||
|
||||
return name
|
||||
|
||||
def get_duplicates(a):
|
||||
seen = {}
|
||||
dupes = []
|
||||
|
||||
for x in a:
|
||||
if x not in seen:
|
||||
seen[x] = 1
|
||||
else:
|
||||
if seen[x] == 1:
|
||||
dupes.append(x)
|
||||
seen[x] += 1
|
||||
|
||||
return seen
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
rs = (r for r in Rower.objects.all() if r.ispaid and r.autojoin)
|
||||
now = timezone.now()
|
||||
|
||||
for r in rs:
|
||||
workouts = Workout.objects.filter(user=r,
|
||||
duplicate=False,
|
||||
startdatetime__gte=timezone.now()-datetime.timedelta(days=2))
|
||||
|
||||
|
||||
duplicates = get_duplicates(name_short(w.name) for w in workouts)
|
||||
|
||||
for name, count in duplicates.items():
|
||||
if count > 1:
|
||||
workouts2 = workouts.filter(
|
||||
Q(name__contains=name)
|
||||
)
|
||||
|
||||
duplicates2 = get_duplicates(w.date for w in workouts)
|
||||
for dd, count in duplicates2.items():
|
||||
if count > 1:
|
||||
workouts3 = workouts2.filter(date=dd)
|
||||
ids = [w.id for w in workouts3]
|
||||
id, message = join_workouts(r,ids,title=name,
|
||||
parent=workouts3[0],
|
||||
killparents=True)
|
||||
@@ -901,6 +901,9 @@ class Rower(models.Model):
|
||||
slowpaceotw = models.DurationField(default=otwpaceslow,verbose_name='Slowest OTW Pace')
|
||||
fastpaceotw = models.DurationField(default=otwpacefast,verbose_name='Fastest OTW Pace')
|
||||
|
||||
# Auto Join
|
||||
autojoin = models.BooleanField(default=False,verbose_name='Auto Join Workout Segments')
|
||||
|
||||
def __str__(self):
|
||||
return self.user.first_name+' '+self.user.last_name
|
||||
|
||||
@@ -935,6 +938,10 @@ class Rower(models.Model):
|
||||
|
||||
return coaches
|
||||
|
||||
@property
|
||||
def ispaid(self):
|
||||
return self.rowerplan in ['pro','plan','coach']
|
||||
|
||||
class DeactivateUserForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
@@ -3446,7 +3453,7 @@ class AccountRowerForm(ModelForm):
|
||||
'getimportantemails',
|
||||
'defaulttimezone','showfavoritechartnotes',
|
||||
'defaultlandingpage',
|
||||
'offercoaching']
|
||||
'offercoaching','autojoin']
|
||||
|
||||
widgets = {
|
||||
'birthdate': SelectDateWidget(
|
||||
|
||||
@@ -127,7 +127,12 @@ def get_polar_notifications():
|
||||
headers = { 'Authorization': 'Basic %s' % base64.b64encode(
|
||||
bytes(auth_string,'utf-8')).decode('utf-8') }
|
||||
|
||||
response = requests.get(url, headers=headers)
|
||||
try:
|
||||
response = requests.get(url, headers=headers)
|
||||
except ConnectionError:
|
||||
response = {
|
||||
'status_code':400,
|
||||
}
|
||||
|
||||
available_data = []
|
||||
|
||||
|
||||
@@ -368,6 +368,7 @@ def rower_edit_view(request,rowerid=0,userid=0,message=""):
|
||||
offercoaching = cd['offercoaching']
|
||||
except KeyError:
|
||||
offercoaching = False
|
||||
autojoin = cd['autojoin']
|
||||
adaptiveclass = cd['adaptiveclass']
|
||||
defaultlandingpage = cd['defaultlandingpage']
|
||||
weightcategory = cd['weightcategory']
|
||||
@@ -400,6 +401,7 @@ def rower_edit_view(request,rowerid=0,userid=0,message=""):
|
||||
r.showfavoritechartnotes = showfavoritechartnotes
|
||||
r.sex = sex
|
||||
r.birthdate = birthdate
|
||||
r.autojoin = autojoin
|
||||
|
||||
if resetbounce and r.emailbounced:
|
||||
r.emailbounced = False
|
||||
|
||||
Reference in New Issue
Block a user