diff --git a/rowers/admin.py b/rowers/admin.py index e814d391..ea7a79ce 100644 --- a/rowers/admin.py +++ b/rowers/admin.py @@ -4,7 +4,8 @@ from django.contrib.auth.models import User from .models import ( Rower, Workout,GraphImage,FavoriteChart,SiteAnnouncement, - Team,TeamInvite,TeamRequest + Team,TeamInvite,TeamRequest, + WorkoutComment, ) # Register your models here so you can use them in the Admin module @@ -36,6 +37,9 @@ class TeamInviteAdmin(admin.ModelAdmin): class TeamRequestAdmin(admin.ModelAdmin): list_display = ('issuedate','team','user','code') + +class WorkoutCommentAdmin(admin.ModelAdmin): + list_display = ('created','user','workout') admin.site.unregister(User) admin.site.register(User,UserAdmin) @@ -46,3 +50,4 @@ admin.site.register(FavoriteChart,FavoriteChartAdmin) admin.site.register(SiteAnnouncement,SiteAnnouncementAdmin) admin.site.register(TeamInvite,TeamInviteAdmin) admin.site.register(TeamRequest,TeamRequestAdmin) +admin.site.register(WorkoutComment,WorkoutCommentAdmin) diff --git a/rowers/models.py b/rowers/models.py index cc8883d9..c1dd3bbb 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -855,6 +855,7 @@ class RowerForm(ModelForm): if an>=max: raise forms.ValidationError("AN should be lower than Max") + # An announcement that goes to the right of the workouts list # optionally sends a tweet to our twitter account class SiteAnnouncement(models.Model): @@ -878,3 +879,28 @@ class SiteAnnouncement(models.Model): except: pass return super(SiteAnnouncement,self).save(*args, **kwargs) + +# A comment by a user on a training +class WorkoutComment(models.Model): + comment = models.TextField(max_length=300) + created = models.DateTimeField(default=timezone.now) + read = models.BooleanField(default=False) + user = models.ForeignKey(User) + workout = models.ForeignKey(Workout) + + def __unicode__(self): + return u'Comment to: {w} by {u1} {u2}'.format( + w=self.workout.name, + u1 = self.user.first_name, + u2 = self.user.last_name, + ) + + +class WorkoutCommentForm(ModelForm): + class Meta: + model = WorkoutComment + fields = ['comment',] + widgets = { + 'comment': forms.Textarea, + } + diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 113d088f..6328d065 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -85,8 +85,11 @@ def get_token(code): response = requests.post("https://www.strava.com/oauth/token", data=post_data, headers=headers) - token_json = response.json() - thetoken = token_json['access_token'] + try: + token_json = response.json() + thetoken = token_json['access_token'] + except KeyError: + thetoken = 0 return [thetoken] diff --git a/rowers/tasks.py b/rowers/tasks.py index 055dd524..e0367862 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -273,6 +273,35 @@ def handle_sendemail_invite(email,name,code,teamname,manager): return 1 +@app.task +def handle_sendemailnewcomment(first_name, + last_name, + email, + commenter_first_name, + commenter_last_name, + comment,workoutname, + workoutid): + fullemail = first_name+' '+last_name+' <'+email+'>' + subject = 'New comment on workout '+workoutname + message = 'Dear '+first_name+',\n\n' + message += commenter_first_name+' '+commenter_last_name + message += ' has written a new comment on your workout ' + message += workoutname+'\n\n' + message += comment + message += '\n\n' + message += 'You can read the comment here:\n' + message += 'https://rowsandall.com/rowers/workout/'+str(workoutid)+'/comment' + + email = EmailMessage(subject, message, + 'Rowsandall ', + [fullemail]) + + + res = email.send() + + return 1 + + @app.task def handle_sendemail_request(email,name,code,teamname,requestor,id): fullemail = name+' <'+email+'>' diff --git a/rowers/templates/list_workouts.html b/rowers/templates/list_workouts.html index 7a1d58ea..891e596b 100644 --- a/rowers/templates/list_workouts.html +++ b/rowers/templates/list_workouts.html @@ -5,6 +5,12 @@ {% block title %}Workouts{% endblock %} {% block content %} + + + +
Select start and end date for a date range: @@ -27,7 +33,7 @@
-
+
{% if team %}

{{ team.name }} Team Workouts

{% else %} diff --git a/rowers/templates/workout_comments.html b/rowers/templates/workout_comments.html new file mode 100644 index 00000000..438388a5 --- /dev/null +++ b/rowers/templates/workout_comments.html @@ -0,0 +1,183 @@ +{% extends "base.html" %} +{% load staticfiles %} +{% load rowerfilters %} +{% load tz %} + +{% block title %}Change Workout {% endblock %} + +{% block content %} +
+
+ {% if form.errors %} +

+ Please correct the error{{ form.errors|pluralize }} below. +

+ {% endif %} + +

Comments {{ workout.name }}

+ + {% localtime on %} + + + + + + + + + + + + + + +
Rower:{{ first_name }} {{ last_name }}
Date/Time:{{ workout.startdatetime }}
Distance:{{ workout.distance }}m
Duration:{{ workout.duration |durationprint:"%H:%M:%S.%f" }}
Public link to this workout + https://rowsandall.com/rowers/workout/{{ workout.id }} + +
Public link to interactive chart + https://rowsandall.com/rowers/workout/{{ workout.id }}/interactiveplot + +
+ {% endlocaltime %} +
+ {% for c in comments %} +
+
+ {{ c.created }} + {{ c.user.first_name }} {{ c.user.last_name }} +
+
+
+
+ {{ c.comment }} +
+
+
+
+ {% endfor %} + +
+
+ + {{ form.as_table }} +
+ {% csrf_token %} +
+ +
+
+
+ +
+ +
+

Images linked to this workout

+ + {% if graphs1 %} + + {% for graph in graphs1 %} + {% if forloop.counter == 1 %} +
+ + {{ graph.filename }} +
+ {% elif forloop.counter == 3 %} +
+ + {{ graph.filename }} +
+ + {% else %} +
+ + {{ graph.filename }} +
+ {% endif %} + {% endfor %} + + + {% for graph in graphs2 %} + {% if forloop.counter == 1 %} +
+ + {{ graph.filename }} +
+ {% elif forloop.counter == 3 %} +
+ + {{ graph.filename }} +
+ + {% else %} +
+ + {{ graph.filename }} +
+ {% endif %} + {% endfor %} + + + + + {% else %} +

No graphs found

+ {% endif %} +
+ + + +
+

Workout Summary

+ +

+

+      {{ workout.summary }}
+    
+

+ +
+ + + +
+ + + + {{ gmscript |safe }} + + +
+ {{ gmdiv|safe }} +
+
+ +{% endblock %} diff --git a/rowers/templates/workout_form.html b/rowers/templates/workout_form.html index 356a245a..9c611295 100644 --- a/rowers/templates/workout_form.html +++ b/rowers/templates/workout_form.html @@ -14,7 +14,7 @@

{% endif %} -

Edit Workout Data

+

Edit Workout {{ workout.name }}

@@ -54,8 +54,14 @@ Public link to this workout - https://rowsandall.com/rowers/workout/{{ workout.id }} - + https://rowsandall.com/rowers/workout/{{ workout.id }} + + + Comments + + Comment + + Public link to interactive chart diff --git a/rowers/templates/workout_view.html b/rowers/templates/workout_view.html index 2bee8359..38f0687e 100644 --- a/rowers/templates/workout_view.html +++ b/rowers/templates/workout_view.html @@ -8,7 +8,7 @@

-

Workout Data

+

{{ workout.name }}

@@ -29,6 +29,12 @@ + + + +
Rower:{{ first_name }} {{ last_name }}
Weight Category:{{ workout.weightcategory }}
Comments + Comment +

Workout Summary

diff --git a/rowers/testdata/logcard.csv b/rowers/testdata/logcard.csv new file mode 100644 index 00000000..35d39e46 --- /dev/null +++ b/rowers/testdata/logcard.csv @@ -0,0 +1,255 @@ +Concept2 Utility - Version 7.06.15,,,,,,,,,,,,,,,,,, +,,,,,,,,,,,,,,,,,, +Log Data for:,F,,,,,,,,,,,,,,,,, +,,,,,Total Workout Results,,,,Split or Work Interval Results,,,,Results Calculated by Formulas,,,Interval Rest Results,, +,Name,Date,Time of Day,Workout Name,Time,Meters,Avg SPM,Avg Heart Rate,Time,Meters,SPM,Heart Rate,/500m,Cal/hr,Watt,Time,Meters,Heart Rate +,,,,,,,,,,,,,,,,,, +,F,2/3/2017,7:48,0:25:03,25:03.6,6326,23,163,,,,,01:58.8,1017,209,,, +,F,2/3/2017,7:48,0:25:03,,,,,06:00.0,1484,23,150,02:01.2,975,196,,, +,F,2/3/2017,7:48,0:25:03,,,,,12:00.0,1532,24,161,01:57.4,1042,216,,, +,F,2/3/2017,7:48,0:25:03,,,,,18:00.0,1504,23,163,01:59.6,1002,204,,, +,F,2/3/2017,7:48,0:25:03,,,,,24:00.0,1535,23,171,01:57.2,1047,217,,, +,F,2/3/2017,7:48,0:25:03,,,,,25:03.6,271,23,170,01:57.3,1045,217,,, +,,,,,,,,,,,,,,,,,, +,F,2/3/2017,7:21,0:01:23,01:23.7,312,20,116,,,,,02:14.1,799,145,,, +,F,2/3/2017,7:21,0:01:23,,,,,01:23.7,313,20,116,02:13.7,803,146,,, +,,,,,,,,,,,,,,,,,, +,F,1/13/2017,8:42,0:45:00,45:00.0,11437,23,168,,,,,01:58.0,1032,213,,, +,F,1/13/2017,8:42,0:45:00,,,,,03:00.0,773,24,155,01:56.4,1063,222,,, +,F,1/13/2017,8:42,0:45:00,,,,,06:00.0,769,24,161,01:57.0,1051,218,,, +,F,1/13/2017,8:42,0:45:00,,,,,09:00.0,769,24,164,01:57.0,1051,218,,, +,F,1/13/2017,8:42,0:45:00,,,,,12:00.0,770,24,165,01:56.8,1054,219,,, +,F,1/13/2017,8:42,0:45:00,,,,,15:00.0,765,24,168,01:57.6,1039,215,,, +,F,1/13/2017,8:42,0:45:00,,,,,18:00.0,753,23,165,01:59.5,1005,205,,, +,F,1/13/2017,8:42,0:45:00,,,,,21:00.0,770,24,171,01:56.8,1054,219,,, +,F,1/13/2017,8:42,0:45:00,,,,,24:00.0,764,24,167,01:57.8,1036,214,,, +,F,1/13/2017,8:42,0:45:00,,,,,27:00.0,763,24,169,01:57.9,1033,213,,, +,F,1/13/2017,8:42,0:45:00,,,,,30:00.0,770,24,173,01:56.8,1054,219,,, +,F,1/13/2017,8:42,0:45:00,,,,,33:00.0,764,23,173,01:57.8,1036,214,,, +,F,1/13/2017,8:42,0:45:00,,,,,36:00.0,739,23,172,02:01.7,966,194,,, +,F,1/13/2017,8:42,0:45:00,,,,,39:00.0,723,22,171,02:04.4,924,181,,, +,F,1/13/2017,8:42,0:45:00,,,,,42:00.0,759,23,175,01:58.5,1022,210,,, +,F,1/13/2017,8:42,0:45:00,,,,,45:00.0,787,23,179,01:54.3,1105,234,,, +,,,,,,,,,,,,,,,,,, +,F,1/13/2017,7:57,0:04:53,04:53.6,1080,20,71,,,,,02:15.9,779,139,,, +,F,1/13/2017,7:57,0:04:53,,,,,04:53.6,1081,20,71,02:15.8,780,140,,, +,,,,,,,,,,,,,,,,,, +,F,1/10/2017,8:29,0:45:00,45:00.0,11260,21,170,,,,,01:59.8,998,203,,, +,F,1/10/2017,8:29,0:45:00,,,,,09:00.0,2320,22,168,01:56.3,1064,222,,, +,F,1/10/2017,8:29,0:45:00,,,,,18:00.0,2275,22,168,01:58.6,1020,209,,, +,F,1/10/2017,8:29,0:45:00,,,,,27:00.0,2142,21,167,02:06.0,901,175,,, +,F,1/10/2017,8:29,0:45:00,,,,,36:00.0,2243,21,173,02:00.3,990,201,,, +,F,1/10/2017,8:29,0:45:00,,,,,45:00.0,2281,22,177,01:58.3,1026,211,,, +,,,,,,,,,,,,,,,,,, +,F,1/10/2017,7:43,0:04:36,04:36.1,1048,21,113,,,,,02:11.7,826,153,,, +,F,1/10/2017,7:43,0:04:36,,,,,04:36.1,1049,21,113,02:11.6,828,154,,, +,,,,,,,,,,,,,,,,,, +,F,1/8/2017,8:29,0:45:00,45:00.0,10960,21,167,,,,,02:03.1,944,187,,, +,F,1/8/2017,8:29,0:45:00,,,,,09:00.0,2033,20,160,02:12.8,814,149,,, +,F,1/8/2017,8:29,0:45:00,,,,,18:00.0,2182,21,168,02:03.7,935,185,,, +,F,1/8/2017,8:29,0:45:00,,,,,27:00.0,2251,22,167,01:59.9,998,203,,, +,F,1/8/2017,8:29,0:45:00,,,,,36:00.0,2221,21,168,02:01.5,970,195,,, +,F,1/8/2017,8:29,0:45:00,,,,,45:00.0,2273,22,176,01:58.7,1018,209,,, +,,,,,,,,,,,,,,,,,, +,F,1/8/2017,7:43,0:05:01,05:01.3,1119,20,106,,,,,02:14.6,793,143,,, +,F,1/8/2017,7:43,0:05:01,,,,,05:00.0,1117,20,106,02:14.2,797,145,,, +,F,1/8/2017,7:43,0:05:01,,,,,05:01.3,3,0,106,03:36.6,418,34,,, +,,,,,,,,,,,,,,,,,, +,F,1/4/2017,9:03,v5:00/2:00r...3,55:00.0,12799,18,157,,,,,02:08.9,862,163,,, +,F,1/4/2017,9:03,v5:00/2:00r...3,,,,,05:00.0,879,16,130,02:50.6,542,70,,, +,F,1/4/2017,9:03,v5:00/2:00r...3,,,,,,,,,,,,02:00.0,128,124 +,F,1/4/2017,9:03,v5:00/2:00r...3,,,,,45:00.0,10953,22,176,02:03.2,943,187,,, +,F,1/4/2017,9:03,v5:00/2:00r...3,,,,,,,,,,,,00:00.0,0,0 +,F,1/4/2017,9:03,v5:00/2:00r...3,,,,,05:00.0,971,18,165,02:34.4,626,95,,, +,F,1/4/2017,9:03,v5:00/2:00r...3,,,,,,,,,,,,00:00.0,0,0 +,,,,,,,,,,,,,,,,,, +,F,1/2/2017,7:56,v5:00/1:00r...2,22:14.2,5280,22,152,,,,,02:06.3,897,174,,, +,F,1/2/2017,7:56,v5:00/1:00r...2,,,,,05:00.0,1224,23,147,02:02.5,954,190,,, +,F,1/2/2017,7:56,v5:00/1:00r...2,,,,,,,,,,,,01:00.0,23,132 +,F,1/2/2017,7:56,v5:00/1:00r...2,,,,,17:14.2,4060,21,158,02:07.3,883,169,,, +,F,1/2/2017,7:56,v5:00/1:00r...2,,,,,,,,,,,,01:00.0,0,0 +,,,,,,,,,,,,,,,,,, +,F,10/6/2016,8:53,10000m,40:30.8,10000,21,173,,,,,02:01.5,970,195,,, +,F,10/6/2016,8:53,10000m,,,,,07:52.1,2000,23,169,01:58.0,1032,213,,, +,F,10/6/2016,8:53,10000m,,,,,08:03.3,4000,22,164,02:00.8,982,198,,, +,F,10/6/2016,8:53,10000m,,,,,08:19.4,6000,21,175,02:04.8,918,180,,, +,F,10/6/2016,8:53,10000m,,,,,08:10.7,8000,21,176,02:02.6,952,190,,, +,F,10/6/2016,8:53,10000m,,,,,08:05.3,10000,21,181,02:01.3,974,196,,, +,,,,,,,,,,,,,,,,,, +,F,10/6/2016,8:12,0:03:02,03:02.3,713,21,142,,,,,02:07.8,876,168,,, +,F,10/6/2016,8:12,0:03:02,,,,,03:02.3,714,21,142,02:07.6,878,168,,, +,,,,,,,,,,,,,,,,,, +,F,9/27/2016,16:39,0:10:19,10:19.2,2110,22,0,,,,,02:26.7,681,111,,, +,F,9/27/2016,16:39,0:10:19,,,,,05:00.0,1029,24,0,02:25.7,688,113,,, +,F,9/27/2016,16:39,0:10:19,,,,,10:00.0,1020,25,0,02:27.0,678,110,,, +,F,9/27/2016,16:39,0:10:19,,,,,10:19.2,61,19,0,02:37.3,609,90,,, +,,,,,,,,,,,,,,,,,, +,F,9/27/2016,16:26,0:01:20,01:20.8,259,22,0,,,,,02:35.9,617,92,,, +,F,9/27/2016,16:26,0:01:20,,,,,01:20.8,259,22,0,02:35.9,617,92,,, +,,,,,,,,,,,,,,,,,, +,F,9/23/2016,7:59,0:30:00,30:00.0,7142,21,163,,,,,02:06.0,901,175,,, +,F,9/23/2016,7:59,0:30:00,,,,,06:00.0,1473,22,160,02:02.1,960,192,,, +,F,9/23/2016,7:59,0:30:00,,,,,12:00.0,1409,20,162,02:07.7,877,168,,, +,F,9/23/2016,7:59,0:30:00,,,,,18:00.0,1393,21,163,02:09.2,858,162,,, +,F,9/23/2016,7:59,0:30:00,,,,,24:00.0,1429,22,158,02:05.9,902,175,,, +,F,9/23/2016,7:59,0:30:00,,,,,30:00.0,1439,21,173,02:05.0,915,179,,, +,,,,,,,,,,,,,,,,,, +,F,9/23/2016,7:29,0:03:08,03:08.0,744,21,147,,,,,02:06.3,897,174,,, +,F,9/23/2016,7:29,0:03:08,,,,,03:08.0,744,21,147,02:06.3,897,174,,, +,,,,,,,,,,,,,,,,,, +,F,9/21/2016,16:09,0:34:16,34:16.9,6512,20,0,,,,,02:37.9,605,89,,, +,F,9/21/2016,16:09,0:34:16,,,,,05:00.0,980,22,0,02:33.0,635,98,,, +,F,9/21/2016,16:09,0:34:16,,,,,10:00.0,989,20,0,02:31.6,645,100,,, +,F,9/21/2016,16:09,0:34:16,,,,,15:00.0,966,21,0,02:35.2,621,93,,, +,F,9/21/2016,16:09,0:34:16,,,,,20:00.0,938,20,0,02:39.9,594,86,,, +,F,9/21/2016,16:09,0:34:16,,,,,25:00.0,946,21,0,02:38.5,602,88,,, +,F,9/21/2016,16:09,0:34:16,,,,,30:00.0,909,21,0,02:45.0,568,78,,, +,F,9/21/2016,16:09,0:34:16,,,,,34:16.9,785,20,0,02:43.6,574,80,,, +,,,,,,,,,,,,,,,,,, +,F,9/20/2016,17:11,0:33:19,33:19.3,6519,21,0,,,,,02:33.3,634,97,,, +,F,9/20/2016,17:11,0:33:19,,,,,05:00.0,991,22,0,02:31.3,647,101,,, +,F,9/20/2016,17:11,0:33:19,,,,,10:00.0,994,21,0,02:30.9,650,102,,, +,F,9/20/2016,17:11,0:33:19,,,,,15:00.0,977,21,0,02:33.5,632,97,,, +,F,9/20/2016,17:11,0:33:19,,,,,20:00.0,968,21,0,02:34.9,623,94,,, +,F,9/20/2016,17:11,0:33:19,,,,,25:00.0,982,21,0,02:32.7,637,98,,, +,F,9/20/2016,17:11,0:33:19,,,,,30:00.0,971,21,0,02:34.4,626,95,,, +,F,9/20/2016,17:11,0:33:19,,,,,33:19.3,637,20,0,02:36.4,614,91,,, +,,,,,,,,,,,,,,,,,, +,F,9/20/2016,8:12,0:22:32,22:32.5,4731,18,158,,,,,02:22.9,712,120,,, +,F,9/20/2016,8:12,0:22:32,,,,,09:00.0,2197,22,171,02:02.8,948,189,,, +,F,9/20/2016,8:12,0:22:32,,,,,18:00.0,1781,18,136,02:31.6,645,100,,, +,F,9/20/2016,8:12,0:22:32,,,,,22:32.5,753,15,168,03:00.9,503,59,,, +,,,,,,,,,,,,,,,,,, +,F,9/20/2016,7:48,v5:00...1,05:00.0,758,14,115,,,,,03:17.8,455,45,,, +,F,9/20/2016,7:48,v5:00...1,,,,,05:00.0,759,14,115,03:17.6,456,45,,, +,F,9/20/2016,7:48,v5:00...1,,,,,,,,,,,,00:00.0,0,0 +,,,,,,,,,,,,,,,,,, +,F,9/19/2016,15:28,0:31:15,31:15.4,6511,22,0,,,,,02:24.0,703,117,,, +,F,9/19/2016,15:28,0:31:15,,,,,05:00.0,1040,24,0,02:24.2,701,117,,, +,F,9/19/2016,15:28,0:31:15,,,,,10:00.0,1037,23,0,02:24.6,698,116,,, +,F,9/19/2016,15:28,0:31:15,,,,,15:00.0,1067,23,0,02:20.5,733,126,,, +,F,9/19/2016,15:28,0:31:15,,,,,20:00.0,1046,23,0,02:23.4,708,119,,, +,F,9/19/2016,15:28,0:31:15,,,,,25:00.0,1025,21,0,02:26.3,684,112,,, +,F,9/19/2016,15:28,0:31:15,,,,,30:00.0,1045,22,0,02:23.5,707,118,,, +,F,9/19/2016,15:28,0:31:15,,,,,31:15.4,252,19,0,02:29.6,659,105,,, +,,,,,,,,,,,,,,,,,, +,F,9/15/2016,18:01,0:32:53,32:53.1,6694,22,0,,,,,02:27.3,676,109,,, +,F,9/15/2016,18:01,0:32:53,,,,,05:00.0,1055,24,0,02:22.1,719,122,,, +,F,9/15/2016,18:01,0:32:53,,,,,10:00.0,1042,23,0,02:23.9,703,117,,, +,F,9/15/2016,18:01,0:32:53,,,,,15:00.0,1017,22,0,02:27.4,675,109,,, +,F,9/15/2016,18:01,0:32:53,,,,,20:00.0,1030,23,0,02:25.6,690,113,,, +,F,9/15/2016,18:01,0:32:53,,,,,25:00.0,996,23,0,02:30.6,652,102,,, +,F,9/15/2016,18:01,0:32:53,,,,,30:00.0,983,22,0,02:32.5,639,99,,, +,F,9/15/2016,18:01,0:32:53,,,,,32:53.1,572,22,0,02:31.3,647,101,,, +,,,,,,,,,,,,,,,,,, +,F,9/13/2016,16:52,0:35:12,35:12.4,6740,23,0,,,,,02:36.7,613,91,,, +,F,9/13/2016,16:52,0:35:12,,,,,10:00.0,1928,28,0,02:35.6,619,93,,, +,F,9/13/2016,16:52,0:35:12,,,,,20:00.0,1955,26,0,02:33.4,633,97,,, +,F,9/13/2016,16:52,0:35:12,,,,,30:00.0,1958,23,0,02:33.2,634,97,,, +,F,9/13/2016,16:52,0:35:12,,,,,35:12.4,900,18,0,02:53.5,530,67,,, +,,,,,,,,,,,,,,,,,, +,F,9/3/2016,11:33,0:01:26,01:26.7,113,28,0,,,,,06:23.6,321,6,,, +,F,9/3/2016,11:33,0:01:26,,,,,01:26.7,114,28,0,06:20.2,321,6,,, +,,,,,,,,,,,,,,,,,, +,F,8/8/2016,7:45,0:24:18,24:18.4,4438,15,136,,,,,02:44.3,571,79,,, +,F,8/8/2016,7:45,0:24:18,,,,,11:00.0,2322,19,147,02:22.1,719,122,,, +,F,8/8/2016,7:45,0:24:18,,,,,22:00.0,1830,15,0,03:00.3,505,60,,, +,F,8/8/2016,7:45,0:24:18,,,,,24:18.4,287,11,126,04:01.1,385,25,,, +,,,,,,,,,,,,,,,,,, +,F,7/6/2016,7:49,0:45:00,45:00.0,10872,21,164,,,,,02:04.1,929,183,,, +,F,7/6/2016,7:49,0:45:00,,,,,09:00.0,2186,22,151,02:03.5,939,186,,, +,F,7/6/2016,7:49,0:45:00,,,,,18:00.0,2222,22,163,02:01.5,971,195,,, +,F,7/6/2016,7:49,0:45:00,,,,,27:00.0,2048,20,158,02:11.8,825,153,,, +,F,7/6/2016,7:49,0:45:00,,,,,36:00.0,2146,21,169,02:05.8,904,176,,, +,F,7/6/2016,7:49,0:45:00,,,,,45:00.0,2271,22,179,01:58.8,1016,208,,, +,,,,,,,,,,,,,,,,,, +,F,7/5/2016,8:18,0:45:00,45:00.0,10900,21,168,,,,,02:03.8,934,184,,, +,F,7/5/2016,8:18,0:45:00,,,,,09:00.0,2285,23,166,01:58.1,1030,212,,, +,F,7/5/2016,8:18,0:45:00,,,,,18:00.0,2256,22,168,01:59.6,1002,204,,, +,F,7/5/2016,8:18,0:45:00,,,,,27:00.0,2156,21,174,02:05.2,913,178,,, +,F,7/5/2016,8:18,0:45:00,,,,,36:00.0,2016,20,155,02:13.9,801,146,,, +,F,7/5/2016,8:18,0:45:00,,,,,45:00.0,2188,21,177,02:03.4,941,186,,, +,,,,,,,,,,,,,,,,,, +,F,7/2/2016,7:14,0:35:17,35:17.2,8855,22,167,,,,,01:59.5,1005,205,,, +,F,7/2/2016,7:14,0:35:17,,,,,11:01.6,2800,24,161,01:58.1,1030,212,,, +,F,7/2/2016,7:14,0:35:17,,,,,10:57.7,5600,23,171,01:57.4,1043,216,,, +,F,7/2/2016,7:14,0:35:17,,,,,11:24.5,8400,22,169,02:02.2,959,192,,, +,F,7/2/2016,7:14,0:35:17,,,,,01:53.4,8855,21,167,02:04.6,922,181,,, +,,,,,,,,,,,,,,,,,, +,F,7/1/2016,7:32,10000m,40:15.0,10000,23,176,,,,,02:00.7,984,199,,, +,F,7/1/2016,7:32,10000m,,,,,07:54.1,2000,24,168,01:58.5,1023,210,,, +,F,7/1/2016,7:32,10000m,,,,,07:50.3,4000,24,174,01:57.5,1041,215,,, +,F,7/1/2016,7:32,10000m,,,,,08:24.4,6000,22,177,02:06.1,900,175,,, +,F,7/1/2016,7:32,10000m,,,,,08:02.3,8000,23,180,02:00.5,987,200,,, +,F,7/1/2016,7:32,10000m,,,,,08:03.9,10000,22,182,02:00.9,980,198,,, +,,,,,,,,,,,,,,,,,, +,F,7/1/2016,6:51,0:02:29,02:29.5,529,20,130,,,,,02:21.3,726,124,,, +,F,7/1/2016,6:51,0:02:29,,,,,02:29.5,529,20,130,02:21.3,726,124,,, +,,,,,,,,,,,,,,,,,, +,F,6/28/2016,6:45,0:30:00,30:00.0,7434,22,173,,,,,02:01.0,978,197,,, +,F,6/28/2016,6:45,0:30:00,,,,,06:00.0,1534,23,0,01:57.3,1045,217,,, +,F,6/28/2016,6:45,0:30:00,,,,,12:00.0,1342,21,166,02:14.1,799,145,,, +,F,6/28/2016,6:45,0:30:00,,,,,18:00.0,1523,24,172,01:58.1,1029,212,,, +,F,6/28/2016,6:45,0:30:00,,,,,24:00.0,1484,22,173,02:01.2,975,196,,, +,F,6/28/2016,6:45,0:30:00,,,,,30:00.0,1552,23,184,01:55.9,1072,224,,, +,,,,,,,,,,,,,,,,,, +,F,6/25/2016,7:10,0:30:00,30:00.0,7675,23,171,,,,,01:57.2,1047,217,,, +,F,6/25/2016,7:10,0:30:00,,,,,06:00.0,1542,24,159,01:56.7,1057,220,,, +,F,6/25/2016,7:10,0:30:00,,,,,12:00.0,1527,24,165,01:57.8,1035,214,,, +,F,6/25/2016,7:10,0:30:00,,,,,18:00.0,1550,24,174,01:56.1,1069,223,,, +,F,6/25/2016,7:10,0:30:00,,,,,24:00.0,1502,23,179,01:59.8,999,203,,, +,F,6/25/2016,7:10,0:30:00,,,,,30:00.0,1556,23,181,01:55.6,1078,226,,, +,,,,,,,,,,,,,,,,,, +,F,6/9/2016,7:17,0:30:00,30:00.0,7299,22,166,,,,,02:03.3,942,187,,, +,F,6/9/2016,7:17,0:30:00,,,,,06:00.0,1563,24,168,01:55.1,1088,229,,, +,F,6/9/2016,7:17,0:30:00,,,,,12:00.0,1463,22,166,02:03.0,946,188,,, +,F,6/9/2016,7:17,0:30:00,,,,,18:00.0,1371,21,160,02:11.2,832,155,,, +,F,6/9/2016,7:17,0:30:00,,,,,24:00.0,1434,22,165,02:05.5,909,177,,, +,F,6/9/2016,7:17,0:30:00,,,,,30:00.0,1468,22,174,02:02.6,953,190,,, +,,,,,,,,,,,,,,,,,, +,F,5/24/2016,7:42,0:30:00,30:00.0,7612,23,168,,,,,01:58.2,1028,212,,, +,F,5/24/2016,7:42,0:30:00,,,,,06:00.0,1534,24,158,01:57.3,1045,217,,, +,F,5/24/2016,7:42,0:30:00,,,,,12:00.0,1491,23,167,02:00.7,984,199,,, +,F,5/24/2016,7:42,0:30:00,,,,,18:00.0,1507,23,169,01:59.4,1006,205,,, +,F,5/24/2016,7:42,0:30:00,,,,,24:00.0,1532,23,171,01:57.4,1042,216,,, +,F,5/24/2016,7:42,0:30:00,,,,,30:00.0,1548,23,175,01:56.2,1066,223,,, +,,,,,,,,,,,,,,,,,, +,F,5/7/2016,9:14,0:30:00,30:00.0,7540,23,164,,,,,01:59.3,1008,206,,, +,F,5/7/2016,9:14,0:30:00,,,,,06:00.0,1493,23,162,02:00.5,987,200,,, +,F,5/7/2016,9:14,0:30:00,,,,,12:00.0,1517,23,161,01:58.6,1021,210,,, +,F,5/7/2016,9:14,0:30:00,,,,,18:00.0,1498,23,165,02:00.1,994,202,,, +,F,5/7/2016,9:14,0:30:00,,,,,24:00.0,1506,23,164,01:59.5,1005,205,,, +,F,5/7/2016,9:14,0:30:00,,,,,30:00.0,1526,23,169,01:57.9,1033,213,,, +,,,,,,,,,,,,,,,,,, +,F,4/23/2016,8:17,10000m,39:24.5,10000,23,166,,,,,01:58.2,1028,212,,, +,F,4/23/2016,8:17,10000m,,,,,07:47.0,2000,24,161,01:56.7,1056,220,,, +,F,4/23/2016,8:17,10000m,,,,,07:44.2,4000,24,171,01:56.0,1070,224,,, +,F,4/23/2016,8:17,10000m,,,,,07:50.7,6000,23,165,01:57.6,1039,215,,, +,F,4/23/2016,8:17,10000m,,,,,08:09.4,8000,22,165,02:02.3,957,191,,, +,F,4/23/2016,8:17,10000m,,,,,07:53.1,10000,23,170,01:58.2,1028,212,,, +,,,,,,,,,,,,,,,,,, +,F,4/20/2016,8:12,0:30:00,30:00.0,7961,24,170,,,,,01:53.0,1133,242,,, +,F,4/20/2016,8:12,0:30:00,,,,,06:00.0,1583,24,160,01:53.7,1119,238,,, +,F,4/20/2016,8:12,0:30:00,,,,,12:00.0,1590,24,163,01:53.2,1130,241,,, +,F,4/20/2016,8:12,0:30:00,,,,,18:00.0,1594,24,173,01:52.9,1136,243,,, +,F,4/20/2016,8:12,0:30:00,,,,,24:00.0,1589,25,174,01:53.2,1128,241,,, +,F,4/20/2016,8:12,0:30:00,,,,,30:00.0,1607,24,182,01:52.0,1157,249,,, +,,,,,,,,,,,,,,,,,, +,F,4/18/2016,8:24,0:30:00,30:00.0,7608,22,167,,,,,01:58.2,1027,211,,, +,F,4/18/2016,8:24,0:30:00,,,,,06:00.0,1508,22,154,01:59.3,1008,206,,, +,F,4/18/2016,8:24,0:30:00,,,,,12:00.0,1468,21,161,02:02.6,953,190,,, +,F,4/18/2016,8:24,0:30:00,,,,,18:00.0,1542,23,171,01:56.7,1057,220,,, +,F,4/18/2016,8:24,0:30:00,,,,,24:00.0,1544,23,172,01:56.5,1060,221,,, +,F,4/18/2016,8:24,0:30:00,,,,,30:00.0,1546,23,179,01:56.4,1063,222,,, +,,,,,,,,,,,,,,,,,, +,F,4/17/2016,9:32,0:35:33,35:33.4,8406,21,152,,,,,02:06.8,889,171,,, +,F,4/17/2016,9:32,0:35:33,,,,,11:25.3,2800,22,162,02:02.3,957,191,,, +,F,4/17/2016,9:32,0:35:33,,,,,11:02.1,5600,22,171,01:58.2,1028,212,,, +,F,4/17/2016,9:32,0:35:33,,,,,13:03.3,8400,19,138,02:19.8,740,128,,, +,F,4/17/2016,9:32,0:35:33,,,,,00:02.7,8406,0,138,03:45.0,405,31,,, +,,,,,,,,,,,,,,,,,, +,F,4/11/2016,8:29,0:37:24,37:24.9,9267,22,170,,,,,02:01.1,977,197,,, +,F,4/11/2016,8:29,0:37:24,,,,,11:03.9,2800,23,169,01:58.5,1022,210,,, +,F,4/11/2016,8:29,0:37:24,,,,,11:21.7,5600,22,171,02:01.7,967,194,,, +,F,4/11/2016,8:29,0:37:24,,,,,11:30.7,8400,22,170,02:03.3,941,187,,, +,F,4/11/2016,8:29,0:37:24,,,,,03:28.8,9267,22,170,02:00.4,989,200,,, diff --git a/rowers/tests.py b/rowers/tests.py index 50adfc20..589a8bde 100644 --- a/rowers/tests.py +++ b/rowers/tests.py @@ -671,6 +671,34 @@ class ViewTest(TestCase): f_to_be_deleted = w.csvfilename os.remove(f_to_be_deleted+'.gz') + def test_upload_view_logcard(self): + self.c.login(username='john',password='koeinsloot') + + filename = 'rowers/testdata/logcard.csv' + f = open(filename,'rb') + file_data = {'file': f} + form_data = { + 'title':'', + 'workouttype':'rower', + 'notes':'aap noot mies', + 'make_plot':False, + 'upload_to_c2':False, + 'plottype':'timeplot', + 'file': f, + } + + form = DocumentsForm(form_data,file_data) + + response = self.c.post('/rowers/workout/upload/', form_data, follow=True) + + f.close() + + self.assertRedirects(response, expected_url='/rowers/workout/upload/This%20C2%20logbook%20summary%20does%20not%20contain%20stroke%20data.%20Please%20download%20the%20Export%20Stroke%20Data%20file%20from%20the%20workout%20details%20on%20the%20C2%20logbook.', + status_code=302,target_status_code=200) + + self.assertEqual(response.status_code, 200) + + def test_upload_view_TCX_CN(self): diff --git a/rowers/urls.py b/rowers/urls.py index 37ec074b..e54bbac2 100644 --- a/rowers/urls.py +++ b/rowers/urls.py @@ -148,6 +148,7 @@ urlpatterns = [ url(r'^workout/(?P\d+)/export/c/(?P\w+.*)$',views.workout_export_view), url(r'^workout/(?P\d+)/export/s/(?P\w+.*)$',views.workout_export_view), url(r'^workout/(?P\d+)/export$',views.workout_export_view), + url(r'^workout/(?P\d+)/comment$',views.workout_comment_view), url(r'^workout/(\d+)/emailtcx$',views.workout_tcxemail_view), url(r'^workout/(\d+)/emailcsv$',views.workout_csvemail_view), url(r'^workout/compare/(\d+)/$',views.workout_comparison_list), diff --git a/rowers/views.py b/rowers/views.py index 9731e9e9..950e810f 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -32,7 +32,8 @@ from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart from rowers.models import ( RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm, RowerPowerZonesForm,AccountRowerForm,UserForm,StrokeData, - Team,TeamForm,TeamInviteForm,TeamInvite,TeamRequest + Team,TeamForm,TeamInviteForm,TeamInvite,TeamRequest, + WorkoutComment,WorkoutCommentForm ) from rowers.models import FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement from django.forms.formsets import formset_factory @@ -58,7 +59,9 @@ from rest_framework.renderers import JSONRenderer from rest_framework.parsers import JSONParser from rowers.rows import handle_uploaded_file from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,handle_sendemailcsv -from rowers.tasks import handle_sendemail_unrecognized +from rowers.tasks import ( + handle_sendemail_unrecognized,handle_sendemailnewcomment + ) from scipy.signal import savgol_filter from django.shortcuts import render_to_response @@ -797,30 +800,21 @@ def workout_strava_upload_view(request,id=0): tcxfile = stravastuff.createstravaworkoutdata(w) if tcxfile: with open(tcxfile,'rb') as f: - try: - res = stravastuff.handle_stravaexport(f,w.name, + res = stravastuff.handle_stravaexport(f,w.name, r.stravatoken, description=w.notes) - if res==0: - message = "Strava Upload error: %s" % e - w.uploadedtostrava = -1 - w.save() - os.remove(tcxfile) - url = reverse(workout_export_view, - kwargs = { - 'id':str(w.id), - }) - response = HttpResponseRedirect(url) - return response + if res==0: + message = "Strava Upload error: %s" % e + w.uploadedtostrava = -1 + w.save() + os.remove(tcxfile) + url = reverse(workout_export_view, + kwargs = { + 'id':str(w.id), + }) + response = HttpResponseRedirect(url) + return response - except: - with open("media/stravaerrors.log","a") as errorlog: - errorstring = str(sys.exc_info()[0]) - timestr = strftime("%Y%m%d-%H%M%S") - errorlog.write(timestr+errorstring+"\r\n") - errorlog.write("views.py line 937\r\n") - message = 'Error: '+errorstring - res = 0 try: w.uploadedtostrava = res w.save() @@ -832,7 +826,7 @@ def workout_strava_upload_view(request,id=0): errorstring = str(sys.exc_info()[0]) timestr = strftime("%Y%m%d-%H%M%S") errorlog.write(timestr+errorstring+"\r\n") - errorlog.write("views.py line 952\r\n") + errorlog.write("views.py line 826\r\n") message = 'Error: '+errorstring else: message = "Strava Upload error" @@ -1161,15 +1155,19 @@ def rower_process_stravacallback(request): code = request.GET['code'] res = stravastuff.get_token(code) - access_token = res[0] + if res[0]: + access_token = res[0] - r = Rower.objects.get(user=request.user) - r.stravatoken = access_token + r = Rower.objects.get(user=request.user) + r.stravatoken = access_token - r.save() + r.save() - successmessage = "Tokens stored. Good to go" - return imports_view(request,successmessage=successmessage) + successmessage = "Tokens stored. Good to go" + return imports_view(request,successmessage=successmessage) + else: + message = "Something went wrong with the Strava authorization" + return imports_view(request,message=message) # Process SportTracks callback @@ -3319,6 +3317,55 @@ def workout_export_view(request,id=0, message="", successmessage=""): 'successmessage':successmessage, }) +# list of comments to a workout +@login_required() +def workout_comment_view(request,id=0): + try: + w = Workout.objects.get(id=id) + except Workout.DoesNotExist: + raise Http404("Workout doesn't exist") + + if w.privacy == 'private' and w.user.user != request.user: + return HttpResponseForbidden("Permission error") + + # ok we're permitted + if request.method == 'POST': + r = w.user + form = WorkoutCommentForm(request.POST) + if form.is_valid(): + cd = form.cleaned_data + comment = cd['comment'] + c = WorkoutComment(workout=w,user=request.user,comment=comment) + c.save() + if settings.DEBUG: + res = handle_sendemailnewcomment.delay(r.user.first_name, + r.user.last_name, + r.user.email, + c.user.first_name, + c.user.last_name, + comment,w.name, + w.id) + + else: + res = queuehigh.enqueue(handle_sendemailnewcomment,r.user.first_name, + r.user.last_name, + r.user.email, + r.user.first_name, + r.user.last_name, + comment,w.name,w.id) + + + comments = WorkoutComment.objects.filter(workout=w).order_by("created") + + form = WorkoutCommentForm() + + return render(request, + 'workout_comments.html', + {'workout':w, + 'comments':comments, + 'form':form, + }) + # The basic edit page @login_required() def workout_edit_view(request,id=0,message="",successmessage=""): diff --git a/static/css/rowsandall.css b/static/css/rowsandall.css index 253f5e5d..09e1f881 100644 --- a/static/css/rowsandall.css +++ b/static/css/rowsandall.css @@ -554,3 +554,257 @@ a.wh:hover { .bk-canvas-map { overflow: hidden; } + + +/* container */ +.container { + padding: 5% 5%; +} + +/* CSS talk bubble */ +.talk-bubble { + margin: 40px; + display: inline-block; + position: relative; + width: 200px; + height: auto; + background-color: lightyellow; +} +.border{ + border: 8px solid #666; +} +.round{ + border-radius: 30px; + -webkit-border-radius: 30px; + -moz-border-radius: 30px; + +} + +/* Right triangle placed top left flush. */ +.tri-right.border.left-top:before { + content: ' '; + position: absolute; + width: 0; + height: 0; + left: -40px; + right: auto; + top: -8px; + bottom: auto; + border: 32px solid; + border-color: #666 transparent transparent transparent; +} +.tri-right.left-top:after{ + content: ' '; + position: absolute; + width: 0; + height: 0; + left: -20px; + right: auto; + top: 0px; + bottom: auto; + border: 22px solid; + border-color: lightyellow transparent transparent transparent; +} + +/* Right triangle, left side slightly down */ +.tri-right.border.left-in:before { + content: ' '; + position: absolute; + width: 0; + height: 0; + left: -40px; + right: auto; + top: 30px; + bottom: auto; + border: 20px solid; + border-color: #666 #666 transparent transparent; +} +.tri-right.left-in:after{ + content: ' '; + position: absolute; + width: 0; + height: 0; + left: -20px; + right: auto; + top: 38px; + bottom: auto; + border: 12px solid; + border-color: lightyellow lightyellow transparent transparent; +} + +/*Right triangle, placed bottom left side slightly in*/ +.tri-right.border.btm-left:before { + content: ' '; + position: absolute; + width: 0; + height: 0; + left: -8px; + right: auto; + top: auto; + bottom: -40px; + border: 32px solid; + border-color: transparent transparent transparent #666; +} +.tri-right.btm-left:after{ + content: ' '; + position: absolute; + width: 0; + height: 0; + left: 0px; + right: auto; + top: auto; + bottom: -20px; + border: 22px solid; + border-color: transparent transparent transparent lightyellow; +} + +/*Right triangle, placed bottom left side slightly in*/ +.tri-right.border.btm-left-in:before { + content: ' '; + position: absolute; + width: 0; + height: 0; + left: 30px; + right: auto; + top: auto; + bottom: -40px; + border: 20px solid; + border-color: #666 transparent transparent #666; +} +.tri-right.btm-left-in:after{ + content: ' '; + position: absolute; + width: 0; + height: 0; + left: 38px; + right: auto; + top: auto; + bottom: -20px; + border: 12px solid; + border-color: lightyellow transparent transparent lightyellow; +} + +/*Right triangle, placed bottom right side slightly in*/ +.tri-right.border.btm-right-in:before { + content: ' '; + position: absolute; + width: 0; + height: 0; + left: auto; + right: 30px; + bottom: -40px; + border: 20px solid; + border-color: #666 #666 transparent transparent; +} +.tri-right.btm-right-in:after{ + content: ' '; + position: absolute; + width: 0; + height: 0; + left: auto; + right: 38px; + bottom: -20px; + border: 12px solid; + border-color: lightyellow lightyellow transparent transparent; +} +/* + left: -8px; + right: auto; + top: auto; + bottom: -40px; + border: 32px solid; + border-color: transparent transparent transparent #666; + left: 0px; + right: auto; + top: auto; + bottom: -20px; + border: 22px solid; + border-color: transparent transparent transparent lightyellow; + +/*Right triangle, placed bottom right side slightly in*/ +.tri-right.border.btm-right:before { + content: ' '; + position: absolute; + width: 0; + height: 0; + left: auto; + right: -8px; + bottom: -40px; + border: 20px solid; + border-color: #666 #666 transparent transparent; +} +.tri-right.btm-right:after{ + content: ' '; + position: absolute; + width: 0; + height: 0; + left: auto; + right: 0px; + bottom: -20px; + border: 12px solid; + border-color: lightyellow lightyellow transparent transparent; +} + +/* Right triangle, right side slightly down*/ +.tri-right.border.right-in:before { + content: ' '; + position: absolute; + width: 0; + height: 0; + left: auto; + right: -40px; + top: 30px; + bottom: auto; + border: 20px solid; + border-color: #666 transparent transparent #666; +} +.tri-right.right-in:after{ + content: ' '; + position: absolute; + width: 0; + height: 0; + left: auto; + right: -20px; + top: 38px; + bottom: auto; + border: 12px solid; + border-color: lightyellow transparent transparent lightyellow; +} + +/* Right triangle placed top right flush. */ +.tri-right.border.right-top:before { + content: ' '; + position: absolute; + width: 0; + height: 0; + left: auto; + right: -40px; + top: -8px; + bottom: auto; + border: 32px solid; + border-color: #666 transparent transparent transparent; +} +.tri-right.right-top:after{ + content: ' '; + position: absolute; + width: 0; + height: 0; + left: auto; + right: -20px; + top: 0px; + bottom: auto; + border: 20px solid; + border-color: lightyellow transparent transparent transparent; +} + +/* talk bubble contents */ +.talktext{ + padding: 1em; + text-align: left; + line-height: 1.5em; +} +.talktext p{ + /* remove webkit p margins */ + -webkit-margin-before: 0em; + -webkit-margin-after: 0em; +}