diff --git a/rowers/celery.py b/rowers/celery.py index 8e41c855..a9865a5d 100644 --- a/rowers/celery.py +++ b/rowers/celery.py @@ -12,6 +12,7 @@ os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rowsandall_app.settings_dev') from django.conf import settings # noqa + app = Celery('tasks', broker='redis://localhost', backend='redis://localhost',) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 386f8a88..0b16e99f 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -228,7 +228,8 @@ def timedeltaconv(x): # Processes painsled CSV file to database def save_workout_database(f2,r,dosmooth=True,workouttype='rower', dosummary=True,title='Workout', - notes='',totaldist=0,totaltime=0): + notes='',totaldist=0,totaltime=0, + makeprivate=False): message = None powerperc = 100*np.array([r.pw_ut2, r.pw_ut1, @@ -313,12 +314,18 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower', workoutstarttime = row.rowdatetime.strftime('%H:%M:%S') workoutstartdatetime = thetimezone.localize(row.rowdatetime).astimezone(utc) + if makeprivate: + privacy = 'private' + else: + privacy = 'visible' + # check for duplicate start times ws = Workout.objects.filter(starttime=workoutstarttime, user=r) if (len(ws) != 0): message = "Warning: This workout probably already exists in the database" + w = Workout(user=r,name=title,date=workoutdate, workouttype=workouttype, duration=duration,distance=totaldist, @@ -326,15 +333,16 @@ def save_workout_database(f2,r,dosmooth=True,workouttype='rower', starttime=workoutstarttime, csvfilename=f2,notes=notes,summary=summary, maxhr=maxhr,averagehr=averagehr, - startdatetime=workoutstartdatetime) + startdatetime=workoutstartdatetime, + privacy=privacy) w.save() - ts = Team.objects.filter(rower=r) - - for t in ts: - w.team.add(t) + if privacy == 'visible': + ts = Team.objects.filter(rower=r) + for t in ts: + w.team.add(t) # put stroke data in database res = dataprep(row.df,id=w.id,bands=True, @@ -422,6 +430,7 @@ def handle_nonpainsled(f2,fileformat,summary=''): def new_workout_from_file(r,f2, workouttype='rower', title='Workout', + makeprivate=False, notes=''): message = None fileformat = get_file_type(f2) @@ -470,6 +479,7 @@ def new_workout_from_file(r,f2, dosummary = (fileformat != 'fit') id,message = save_workout_database(f2,r, workouttype=workouttype, + makeprivate=makeprivate, dosummary=dosummary, title=title) diff --git a/rowers/forms.py b/rowers/forms.py index 0644ff5b..23d67fb4 100644 --- a/rowers/forms.py +++ b/rowers/forms.py @@ -76,14 +76,17 @@ class UploadOptionsForm(forms.Form): ('distanceplot','Distance Plot'), ('pieplot','Pie Chart'), ) - make_plot = forms.BooleanField(initial=False) + make_plot = forms.BooleanField(initial=False,required=False) plottype = forms.ChoiceField(required=False, choices=plotchoices, - initial='timeplot') - upload_to_C2 = forms.BooleanField(initial=False) + initial='timeplot', + label='Plot Type') + upload_to_C2 = forms.BooleanField(initial=False,required=False) + makeprivate = forms.BooleanField(initial=False,required=False, + label='Make Workout Private') class Meta: - fields = ['make_plot','plottype','upload_toc2'] + fields = ['make_plot','plottype','upload_toc2','makeprivate'] # This form is used on the Analysis page to add a custom distance/time # trial and predict the pace diff --git a/rowers/models.py b/rowers/models.py index 755b3ede..f4b842be 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -104,19 +104,27 @@ class Team(models.Model): ('private','private'), ('open','open'), ) + + viewchoices = ( + ('coachonly','Coach Only'), + ('allmembers','All Members') + ) + name = models.CharField(max_length=150,unique=True,verbose_name='Team Name') notes = models.CharField(blank=True,max_length=200,verbose_name='Team Purpose') manager = models.ForeignKey(User) private = models.CharField(max_length=30,choices=choices,default='open', verbose_name='Team Type') + viewing = models.CharField(max_length=30,choices=viewchoices,default='allmembers',verbose_name='Sharing Behavior') + def __unicode__(self): return self.name class TeamForm(ModelForm): class Meta: model = Team - fields = ['name','notes','private'] + fields = ['name','notes','private','viewing'] widgets = { 'notes': forms.Textarea, } @@ -196,6 +204,11 @@ class Rower(models.Model): ('coach','coach') ) + privacychoices = ( + ('visible','Visible'), + ('hidden','Hidden'), + ) + rowerplan = models.CharField(default='basic',max_length=30, choices=plans) @@ -203,8 +216,11 @@ class Rower(models.Model): teamplanexpires = models.DateField(default=timezone.now) clubsize = models.IntegerField(default=0) + # Friends/Team friends = models.ManyToManyField("self",blank=True) + privacy = models.CharField(default='visible',max_length=30, + choices=privacychoices) team = models.ManyToManyField(Team,blank=True) @@ -351,6 +367,11 @@ class Workout(models.Model): ('4-', '4- (four)'), ('8+', '8+ (eight)'), ) + + privacychoices = ( + ('private','Private'), + ('visible','Visible'), + ) user = models.ForeignKey(Rower) team = models.ManyToManyField(Team,blank=True) @@ -374,6 +395,8 @@ class Workout(models.Model): uploadedtosporttracks = models.IntegerField(default=0) notes = models.CharField(blank=True,null=True,max_length=200) summary = models.TextField(blank=True) + privacy = models.CharField(default='visible',max_length=30, + choices=privacychoices) def __str__(self): @@ -491,7 +514,7 @@ class WorkoutForm(ModelForm): duration = forms.TimeInput(format='%H:%M:%S.%f') class Meta: model = Workout - fields = ['name','date','starttime','duration','distance','workouttype','boattype','notes'] + fields = ['name','date','starttime','duration','distance','workouttype','notes','privacy','boattype'] widgets = { 'date': DateInput(), 'notes': forms.Textarea, @@ -500,9 +523,12 @@ class WorkoutForm(ModelForm): def __init__(self, *args, **kwargs): super(WorkoutForm, self).__init__(*args, **kwargs) + # this line to be removed + del self.fields['privacy'] + if self.instance.workouttype != 'water': del self.fields['boattype'] - + # Used for the rowing physics calculations class AdvancedWorkoutForm(ModelForm): class Meta: diff --git a/rowers/tasks.py b/rowers/tasks.py index 313f9095..055dd524 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -10,7 +10,7 @@ import rowingdata from rowingdata import main as rmain from rowingdata import rowingdata as rdata import rowingdata -#from rowers.models import Workout + from matplotlib.backends.backend_agg import FigureCanvas #from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas import matplotlib.pyplot as plt @@ -244,6 +244,10 @@ def handle_sendemail_invite(email,name,code,teamname,manager): message = 'Dear '+name+',\n\n' message += manager+' is inviting you to join his team '+teamname message += ' on rowsandall.com\n\n' + message += 'By accepting the invite, you will have access to your' + message += " team's workouts on rowsandall.com and your workouts will " + message += " be visible to " + message += "the members of the team.\n\n" message += 'If you already have an account on rowsandall.com, you can login to the site and you will find the invitation here on the Teams page:\n' message += ' https://rowsandall.com/rowers/me/teams \n\n' message += 'You can also click the direct link: \n' diff --git a/rowers/teams.py b/rowers/teams.py index eadc2dc1..9891facb 100644 --- a/rowers/teams.py +++ b/rowers/teams.py @@ -43,7 +43,7 @@ def handle_add_workouts_team(ws,t): return 1 -def update_team(t,name,manager,private,notes): +def update_team(t,name,manager,private,notes,viewing): if t.manager != manager: return (0,'You are not the manager of this team') try: @@ -51,16 +51,17 @@ def update_team(t,name,manager,private,notes): t.manager = manager t.private = private t.notes = notes + t.viewing = viewing t.save() except IntegrityError: return (0,'Team name duplication') return (1,'Team Updated') -def create_team(name,manager,private='open',notes=''): +def create_team(name,manager,private='open',notes='',viewing='allmembers'): # needs some error testing try: t = Team(name=name,manager=manager,notes=notes, - private=private) + private=private,viewing=viewing) t.save() r = Rower.objects.get(user=manager) res = add_member(t.id,r) diff --git a/rowers/templates/document_form.html b/rowers/templates/document_form.html index 37ca763a..c6f42e9b 100644 --- a/rowers/templates/document_form.html +++ b/rowers/templates/document_form.html @@ -29,6 +29,10 @@

+

+ You can select one static plot to be generated immediately for this workout. You can select to upload to Concept2 automatically. If you check "make private", this workout will not be visible to your followers and will not show up in your teams' workouts list. +

+

Valid file types are: