diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index 7f3d0abe..9641a41a 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -32,6 +32,7 @@ oauth_data = { 'expirydatename': 'tokenexpirydate', 'bearer_auth': True, 'base_url': "https://log.concept2.com/oauth/access_token", + 'scope':'write', } diff --git a/rowers/dataprepnodjango.py b/rowers/dataprepnodjango.py index 8e830138..92dccaa2 100644 --- a/rowers/dataprepnodjango.py +++ b/rowers/dataprepnodjango.py @@ -1251,8 +1251,11 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, data.to_sql('strokedata',engine,if_exists='append',index=False) except: data.drop(columns=['rhythm'],inplace=True) - data.to_sql('strokedata',engine,if_exists='append',index=False) - + try: + data.to_sql('strokedata',engine,if_exists='append',index=False) + except: + pass + conn.close() engine.dispose() return data diff --git a/rowers/imports.py b/rowers/imports.py index 0c7e3640..4fdea563 100644 --- a/rowers/imports.py +++ b/rowers/imports.py @@ -216,6 +216,8 @@ def imports_get_token( if 'grant_type' in oauth_data: if oauth_data['grant_type']: post_data['grant_type'] = oauth_data['grant_type'] + if 'strava' in oauth_data['autorization_uri']: + post_data['grant_type'] = "authorization_code" else: grant_type = post_data.pop('grant_type',None) @@ -265,7 +267,7 @@ def imports_make_authorization_url(oauth_data): params = {"client_id": oauth_data['client_id'], "response_type": "code", "redirect_uri": oauth_data['redirect_uri'], - "scope":"write", + "scope":oauth_data['scope'], "state":state} diff --git a/rowers/models.py b/rowers/models.py index a07bbc68..f5d03383 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -2091,7 +2091,8 @@ class Workout(models.Model): user = models.ForeignKey(Rower) team = models.ManyToManyField(Team,blank=True) - plannedsession = models.ForeignKey(PlannedSession, blank=True,null=True) + plannedsession = models.ForeignKey(PlannedSession, blank=True,null=True, + verbose_name='Session') name = models.CharField(max_length=150,blank=True,null=True) date = models.DateField() workouttype = models.CharField(choices=workouttypes,max_length=50, @@ -2452,7 +2453,7 @@ class WorkoutForm(ModelForm): # duration = forms.TimeInput(format='%H:%M:%S.%f') class Meta: model = Workout - fields = ['name','date','starttime','timezone','duration','distance','workouttype','boattype','weightcategory','notes','rankingpiece','duplicate'] + fields = ['name','date','starttime','timezone','duration','distance','workouttype','boattype','weightcategory','notes','rankingpiece','duplicate','plannedsession'] widgets = { 'date': AdminDateWidget(), 'notes': forms.Textarea, @@ -2474,6 +2475,21 @@ class WorkoutForm(ModelForm): self.fields['private'].initial = False else: self.fields['private'].initial = True + + workout = self.instance + sps = PlannedSession.objects.filter( + rower__in=[workout.user], + startdate__lte=workout.date, + enddate__gte=workout.date, + ).order_by("preferreddate","startdate","enddate").exclude( + sessiontype='race') + + if not sps: + del self.fields['plannedsession'] + else: + self.fields['plannedsession'].queryset = sps + else: + del self.fields['plannedsession'] # Used for the rowing physics calculations class AdvancedWorkoutForm(ModelForm): diff --git a/rowers/runkeeperstuff.py b/rowers/runkeeperstuff.py index 151bb5bc..850da57a 100644 --- a/rowers/runkeeperstuff.py +++ b/rowers/runkeeperstuff.py @@ -19,7 +19,8 @@ oauth_data = { 'expirydatename': None, 'bearer_auth': True, 'base_url': "https://runkeeper.com/apps/token", - 'headers': {'user-agent': 'sanderroosendaal'} + 'headers': {'user-agent': 'sanderroosendaal'}, + 'scope':'write', } diff --git a/rowers/sporttracksstuff.py b/rowers/sporttracksstuff.py index 1f52367f..c88d47df 100644 --- a/rowers/sporttracksstuff.py +++ b/rowers/sporttracksstuff.py @@ -20,6 +20,7 @@ oauth_data = { 'expirydatename': 'sporttrackstokenexpirydate', 'bearer_auth': False, 'base_url': "https://api.sporttracks.mobi/oauth2/token", + 'scope':'write', } # Checks if user has SportTracks token, renews them if they are expired diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 30835e14..dc131868 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -33,6 +33,12 @@ except ImportError: from rowers.imports import * +headers = {'Accept': 'application/json', + 'Api-Key': STRAVA_CLIENT_ID, + 'Content-Type': 'application/json', + 'user-agent': 'sanderroosendaal'} + + oauth_data = { 'client_id': STRAVA_CLIENT_ID, 'client_secret': STRAVA_CLIENT_SECRET, @@ -45,6 +51,8 @@ oauth_data = { 'bearer_auth': True, 'base_url': "https://www.strava.com/oauth/token", 'grant_type': 'refresh_token', + 'headers': headers, + 'scope':'activity:write,activity:read_all', } diff --git a/rowers/tasks.py b/rowers/tasks.py index c7219c3d..ef36460c 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -610,6 +610,7 @@ def handle_calctrimp(id, intensityfactor = normp/float(ftp) tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp)) + if sex == 'male': f = 1.92 else: @@ -646,6 +647,24 @@ def handle_calctrimp(id, if not np.isfinite(normw): normw = 0 + try: + dum = int(tss) + except ValueError: + tss = 0 + + try: + dum = int(normp) + except ValueError: + normp = 0 + try: + dump = int(trimp) + except ValueError: + trimp = 0 + try: + dump = int(hrtss) + except ValueError: + hrtss = 0 + query = 'UPDATE rowers_workout SET rscore = {tss}, normp = {normp}, trimp={trimp}, hrtss={hrtss}, normv={normv}, normw={normw} WHERE id={id}'.format( tss = int(tss), normp = int(normp), diff --git a/rowers/templates/gdpr_optin.html b/rowers/templates/gdpr_optin.html index bc2bb898..19255535 100644 --- a/rowers/templates/gdpr_optin.html +++ b/rowers/templates/gdpr_optin.html @@ -5,13 +5,18 @@ {% block title %}GDPR Opt-In{% endblock %} {% block main %} +

+ We know you are eager to start using rowsandall.com, but we must + ask you to read and agree with the below first. +

+

GDPR Opt-In

To comply with the European Union General Data Protection Regulation, we need to record your consent to use personal data on this website. Please take some time to review our data policies. If you agree and - opt in, click the green button at the bottom to be taken to the site. + opt in, click the "opt in" button at the bottom to be taken to the site. If you do not agree, please use the red button to delete your account. This will irreversibly delete all your data on rowsandall.com and remove your account. @@ -32,7 +37,7 @@

- Opt in and continue + Opt in and continue

diff --git a/rowers/templates/list_workouts.html b/rowers/templates/list_workouts.html index 5214ee8a..a46e7fdd 100644 --- a/rowers/templates/list_workouts.html +++ b/rowers/templates/list_workouts.html @@ -6,7 +6,7 @@ {% block scripts %}