From 4571f24daba2daf726a94e9face9eaee9da64bfc Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 15 Feb 2017 12:31:00 +0100 Subject: [PATCH] added privacy settings to workouts & users --- rowers/models.py | 22 ++++++++++++++++++++-- rowers/views.py | 5 +++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/rowers/models.py b/rowers/models.py index 41083237..f4b842be 100644 --- a/rowers/models.py +++ b/rowers/models.py @@ -204,6 +204,11 @@ class Rower(models.Model): ('coach','coach') ) + privacychoices = ( + ('visible','Visible'), + ('hidden','Hidden'), + ) + rowerplan = models.CharField(default='basic',max_length=30, choices=plans) @@ -211,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) @@ -359,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) @@ -382,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): @@ -499,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, @@ -508,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/views.py b/rowers/views.py index 9a2006be..ed51a361 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -3259,6 +3259,10 @@ def workout_edit_view(request,id=0,message="",successmessage=""): boattype = request.POST['boattype'] except KeyError: boattype = Workout.objects.get(id=id).boattype + try: + privacy = request.POST['privacy'] + except KeyError: + privacy = Workout.objects.get(id=id).privacy startdatetime = (str(date) + ' ' + str(starttime)) startdatetime = datetime.datetime.strptime(startdatetime, "%Y-%m-%d %H:%M:%S") @@ -3277,6 +3281,7 @@ def workout_edit_view(request,id=0,message="",successmessage=""): row.duration = duration row.distance = distance row.boattype = boattype + row.privacy = privacy row.save() # change data in csv file