adding privacy default on import or upload
This commit is contained in:
@@ -21,7 +21,7 @@ from django.forms import ModelForm
|
|||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.forms.widgets import SplitDateTimeWidget, SelectDateWidget
|
from django.forms.widgets import SplitDateTimeWidget, SelectDateWidget
|
||||||
from django.forms.formsets import BaseFormSet
|
from django.forms.formsets import BaseFormSet
|
||||||
|
from django.db.models.signals import post_save
|
||||||
from django.contrib.admin.widgets import AdminDateWidget, AdminTimeWidget, AdminSplitDateTime
|
from django.contrib.admin.widgets import AdminDateWidget, AdminTimeWidget, AdminSplitDateTime
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@@ -1255,6 +1255,8 @@ class Rower(models.Model):
|
|||||||
getemailnotifications = models.BooleanField(default=False,
|
getemailnotifications = models.BooleanField(default=False,
|
||||||
verbose_name='Receive email notifications')
|
verbose_name='Receive email notifications')
|
||||||
|
|
||||||
|
imports_are_private = models.BooleanField(default=False, verbose_name='Make imports private by default')
|
||||||
|
|
||||||
# Friends/Team
|
# Friends/Team
|
||||||
friends = models.ManyToManyField("self", blank=True)
|
friends = models.ManyToManyField("self", blank=True)
|
||||||
mycoachgroup = models.ForeignKey(
|
mycoachgroup = models.ForeignKey(
|
||||||
@@ -3780,6 +3782,15 @@ class Workout(models.Model):
|
|||||||
|
|
||||||
super(Workout, self).save(*args, **kwargs)
|
super(Workout, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def post_create(cls, sender, instance, created, *args, **kwargs):
|
||||||
|
if created:
|
||||||
|
user = instance.user
|
||||||
|
if user.imports_are_private:
|
||||||
|
instance.privacy = 'hidden'
|
||||||
|
instance.save()
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -3838,6 +3849,8 @@ class Workout(models.Model):
|
|||||||
|
|
||||||
return stri
|
return stri
|
||||||
|
|
||||||
|
post_save.connect(Workout.post_create, sender=Workout)
|
||||||
|
|
||||||
class WorkoutRPEForm(ModelForm):
|
class WorkoutRPEForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Workout
|
model = Workout
|
||||||
@@ -4581,7 +4594,15 @@ class RowerExportForm(ModelForm):
|
|||||||
'rp3_auto_import',
|
'rp3_auto_import',
|
||||||
'intervals_auto_import',
|
'intervals_auto_import',
|
||||||
'intervals_auto_export',
|
'intervals_auto_export',
|
||||||
'intervals_resample_to_1s'
|
'intervals_resample_to_1s',
|
||||||
|
'imports_are_private'
|
||||||
|
]
|
||||||
|
|
||||||
|
class RowerPrivateImportForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Rower
|
||||||
|
fields = [
|
||||||
|
'imports_are_private'
|
||||||
]
|
]
|
||||||
|
|
||||||
class RowerExportFormStrava(ModelForm):
|
class RowerExportFormStrava(ModelForm):
|
||||||
|
|||||||
@@ -11,12 +11,16 @@
|
|||||||
<th>Distance:</th><td>{{ workout.distance }}m</td>
|
<th>Distance:</th><td>{{ workout.distance }}m</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
|
<th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
|
||||||
</tr><tr>
|
</tr>
|
||||||
|
{% if workout.privacy != 'hidden' %}
|
||||||
|
<tr>
|
||||||
<th>Public link to this workout</th>
|
<th>Public link to this workout</th>
|
||||||
<td>
|
<td>
|
||||||
<a href="/rowers/workout/{{ workout.id|encode }}">https://rowsandall.com/rowers/workout/{{ workout.id|encode }}</a>
|
<a href="/rowers/workout/{{ workout.id|encode }}">https://rowsandall.com/rowers/workout/{{ workout.id|encode }}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr><tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
<tr>
|
||||||
<th>Comments</th>
|
<th>Comments</th>
|
||||||
<td>
|
<td>
|
||||||
<a href="/rowers/workout/{{ workout.id|encode }}/comment">Comment ({{ aantalcomments }})</a>
|
<a href="/rowers/workout/{{ workout.id|encode }}/comment">Comment ({{ aantalcomments }})</a>
|
||||||
|
|||||||
@@ -46,6 +46,14 @@
|
|||||||
<p>
|
<p>
|
||||||
Click on the icons to establish the connection or to renew the authorization.
|
Click on the icons to establish the connection or to renew the authorization.
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
By default, imported workouts are set to have a public URL. However, new workouts can be set to
|
||||||
|
private by default with the following setting:
|
||||||
|
<table>
|
||||||
|
{{ forms.imports_are_private.as_table }}
|
||||||
|
<input type="submit" value="Save">
|
||||||
|
</table>
|
||||||
|
</p>
|
||||||
</li>
|
</li>
|
||||||
<li class="grid_4">
|
<li class="grid_4">
|
||||||
<h2>API Key</h2>
|
<h2>API Key</h2>
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
<form enctype="multipart/form-data" action="" method="post">
|
<form enctype="multipart/form-data" action="" method="post">
|
||||||
<table>
|
<table>
|
||||||
{{ userform.as_table }}
|
{{ userform.as_table }}
|
||||||
|
{{ privateform.as_table }}
|
||||||
{{ accountform.as_table }}
|
{{ accountform.as_table }}
|
||||||
<tr>
|
<tr>
|
||||||
<th> </th><td></td>
|
<th> </th><td></td>
|
||||||
|
|||||||
@@ -150,12 +150,15 @@
|
|||||||
<th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
|
<th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
|
||||||
</tr><tr>
|
</tr><tr>
|
||||||
<th>Source:</th><td>{{ workout.workoutsource }}</td>
|
<th>Source:</th><td>{{ workout.workoutsource }}</td>
|
||||||
</tr><tr>
|
</tr>
|
||||||
|
{% if workout.privacy != 'hidden' %}
|
||||||
|
<tr>
|
||||||
<th>Public link to this workout:</th>
|
<th>Public link to this workout:</th>
|
||||||
<td>
|
<td>
|
||||||
<a href="/rowers/workout/{{ workout.id|encode }}/">https://rowsandall.com/rowers/workout/{{ workout.id|encode }}/</a>
|
<a href="/rowers/workout/{{ workout.id|encode }}/">https://rowsandall.com/rowers/workout/{{ workout.id|encode }}/</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% for course in courses %}
|
{% for course in courses %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
@@ -163,12 +166,12 @@
|
|||||||
</th>
|
</th>
|
||||||
<td>
|
<td>
|
||||||
<a href="/rowers/courses/{{ course.id }}"/>{{ course }}</a>
|
<a href="/rowers/courses/{{ course.id }}"/>{{ course }}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
</li>
|
</li>
|
||||||
<li class="grid_2">
|
<li class="grid_2">
|
||||||
{% if form.errors %}
|
{% if form.errors %}
|
||||||
<p style="color: red;">
|
<p style="color: red;">
|
||||||
Please correct the error{{ form.errors|pluralize }} below.
|
Please correct the error{{ form.errors|pluralize }} below.
|
||||||
|
|||||||
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
BIN
rowers/tests/testdata/testdata.tcx.gz
vendored
Binary file not shown.
@@ -186,7 +186,7 @@ from rowers.models import ( RowerPowerForm, RowerHRZonesForm, SimpleRowerPowerFo
|
|||||||
RowerExportFormSportTracks, RowerExportFormTrainingPeaks,
|
RowerExportFormSportTracks, RowerExportFormTrainingPeaks,
|
||||||
RowerExportFormConcept2, RowerExportFormGarmin,
|
RowerExportFormConcept2, RowerExportFormGarmin,
|
||||||
RowerExportFormIntervals, RowerExportFormRP3,
|
RowerExportFormIntervals, RowerExportFormRP3,
|
||||||
RowerExportFormNK,
|
RowerExportFormNK, RowerPrivateImportForm,
|
||||||
)
|
)
|
||||||
from rowers.models import (
|
from rowers.models import (
|
||||||
FavoriteForm, BaseFavoriteFormSet, SiteAnnouncement, BasePlannedSessionFormSet,
|
FavoriteForm, BaseFavoriteFormSet, SiteAnnouncement, BasePlannedSessionFormSet,
|
||||||
|
|||||||
@@ -479,6 +479,7 @@ def rower_exportsettings_view(request, userid=0):
|
|||||||
'intervals': RowerExportFormIntervals(instance=r),
|
'intervals': RowerExportFormIntervals(instance=r),
|
||||||
'nk': RowerExportFormNK(instance=r),
|
'nk': RowerExportFormNK(instance=r),
|
||||||
'garmin': RowerExportFormGarmin(instance=r),
|
'garmin': RowerExportFormGarmin(instance=r),
|
||||||
|
'imports_are_private': RowerPrivateImportForm(instance=r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
@@ -493,6 +494,7 @@ def rower_exportsettings_view(request, userid=0):
|
|||||||
'intervals': RowerExportFormIntervals(request.POST, instance=r),
|
'intervals': RowerExportFormIntervals(request.POST, instance=r),
|
||||||
'nk': RowerExportFormNK(request.POST, instance=r),
|
'nk': RowerExportFormNK(request.POST, instance=r),
|
||||||
'garmin': RowerExportFormGarmin(request.POST, instance=r),
|
'garmin': RowerExportFormGarmin(request.POST, instance=r),
|
||||||
|
'imports_are_private': RowerPrivateImportForm(request.POST, instance=r),
|
||||||
}
|
}
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
cd = form.cleaned_data
|
cd = form.cleaned_data
|
||||||
@@ -593,11 +595,13 @@ def rower_edit_view(request, rowerid=0, userid=0, message=""):
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
accountform = AccountRowerForm(request.POST, instance=r)
|
accountform = AccountRowerForm(request.POST, instance=r)
|
||||||
userform = UserForm(request.POST, instance=r.user)
|
userform = UserForm(request.POST, instance=r.user)
|
||||||
|
privateform = RowerPrivateImportForm(request.POST, instance=r)
|
||||||
|
|
||||||
if accountform.is_valid() and userform.is_valid():
|
if accountform.is_valid() and userform.is_valid() and privateform.is_valid():
|
||||||
# process
|
# process
|
||||||
cd = accountform.cleaned_data
|
cd = accountform.cleaned_data
|
||||||
ucd = userform.cleaned_data
|
ucd = userform.cleaned_data
|
||||||
|
pcd = privateform.cleaned_data
|
||||||
|
|
||||||
first_name = ucd['first_name']
|
first_name = ucd['first_name']
|
||||||
last_name = ucd['last_name']
|
last_name = ucd['last_name']
|
||||||
@@ -633,6 +637,7 @@ def rower_edit_view(request, rowerid=0, userid=0, message=""):
|
|||||||
resetbounce = True
|
resetbounce = True
|
||||||
|
|
||||||
emailalternatives = cd['emailalternatives']
|
emailalternatives = cd['emailalternatives']
|
||||||
|
imports_are_private = pcd['imports_are_private']
|
||||||
|
|
||||||
u.save()
|
u.save()
|
||||||
r.defaulttimezone = defaulttimezone
|
r.defaulttimezone = defaulttimezone
|
||||||
@@ -644,6 +649,7 @@ def rower_edit_view(request, rowerid=0, userid=0, message=""):
|
|||||||
r.defaultlandingpage = defaultlandingpage
|
r.defaultlandingpage = defaultlandingpage
|
||||||
r.showfavoritechartnotes = showfavoritechartnotes
|
r.showfavoritechartnotes = showfavoritechartnotes
|
||||||
r.share_course_results = share_course_results
|
r.share_course_results = share_course_results
|
||||||
|
r.imports_are_private = imports_are_private
|
||||||
r.sex = sex
|
r.sex = sex
|
||||||
r.birthdate = birthdate
|
r.birthdate = birthdate
|
||||||
r.autojoin = autojoin
|
r.autojoin = autojoin
|
||||||
@@ -658,11 +664,13 @@ def rower_edit_view(request, rowerid=0, userid=0, message=""):
|
|||||||
|
|
||||||
accountform = AccountRowerForm(instance=r)
|
accountform = AccountRowerForm(instance=r)
|
||||||
userform = UserForm(instance=u)
|
userform = UserForm(instance=u)
|
||||||
|
privateform = RowerPrivateImportForm(instance=r)
|
||||||
successmessage = 'Account Information changed'
|
successmessage = 'Account Information changed'
|
||||||
messages.info(request, successmessage)
|
messages.info(request, successmessage)
|
||||||
else:
|
else:
|
||||||
accountform = AccountRowerForm(instance=r)
|
accountform = AccountRowerForm(instance=r)
|
||||||
userform = UserForm(instance=r.user)
|
userform = UserForm(instance=r.user)
|
||||||
|
privateform = RowerPrivateImportForm(instance=r)
|
||||||
|
|
||||||
grants = AccessToken.objects.filter(user=request.user)
|
grants = AccessToken.objects.filter(user=request.user)
|
||||||
try:
|
try:
|
||||||
@@ -678,6 +686,7 @@ def rower_edit_view(request, rowerid=0, userid=0, message=""):
|
|||||||
'grants': grants,
|
'grants': grants,
|
||||||
'userform': userform,
|
'userform': userform,
|
||||||
'accountform': accountform,
|
'accountform': accountform,
|
||||||
|
'privateform': privateform,
|
||||||
'rower': r,
|
'rower': r,
|
||||||
'apikey': apikey.key,
|
'apikey': apikey.key,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -687,7 +687,7 @@ def addmanual_view(request, raceid=0):
|
|||||||
empowerside = form.cleaned_data.get('empowerside','port')
|
empowerside = form.cleaned_data.get('empowerside','port')
|
||||||
|
|
||||||
if private: # pragma: no cover
|
if private: # pragma: no cover
|
||||||
privacy = 'private'
|
privacy = 'hidden'
|
||||||
else:
|
else:
|
||||||
privacy = 'visible'
|
privacy = 'visible'
|
||||||
|
|
||||||
@@ -4270,7 +4270,7 @@ def workout_flexchart_stacked_view(request, *args, **kwargs):
|
|||||||
def workout_unsubscribe_view(request, id=0):
|
def workout_unsubscribe_view(request, id=0):
|
||||||
w = get_workout(id)
|
w = get_workout(id)
|
||||||
|
|
||||||
if w.privacy == 'private' and w.user.user != request.user: # pragma: no cover
|
if w.privacy == 'hidden' and w.user.user != request.user: # pragma: no cover
|
||||||
return HttpResponseForbidden("Permission error")
|
return HttpResponseForbidden("Permission error")
|
||||||
|
|
||||||
comments = WorkoutComment.objects.filter(workout=w,
|
comments = WorkoutComment.objects.filter(workout=w,
|
||||||
@@ -4300,7 +4300,7 @@ def workout_unsubscribe_view(request, id=0):
|
|||||||
def workout_comment_view(request, id=0):
|
def workout_comment_view(request, id=0):
|
||||||
w = get_workout(id)
|
w = get_workout(id)
|
||||||
|
|
||||||
if w.privacy == 'private' and w.user.user != request.user: # pragma: no cover
|
if w.privacy == 'hidden' and w.user.user != request.user: # pragma: no cover
|
||||||
return HttpResponseForbidden("Permission error")
|
return HttpResponseForbidden("Permission error")
|
||||||
|
|
||||||
comments = WorkoutComment.objects.filter(workout=w).order_by("created")
|
comments = WorkoutComment.objects.filter(workout=w).order_by("created")
|
||||||
@@ -4490,7 +4490,7 @@ def workout_edit_view(request, id=0, message="", successmessage=""):
|
|||||||
|
|
||||||
|
|
||||||
if private:
|
if private:
|
||||||
privacy = 'private'
|
privacy = 'hidden'
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
privacy = 'visible'
|
privacy = 'visible'
|
||||||
|
|
||||||
@@ -5197,6 +5197,8 @@ def workout_upload_view(request,
|
|||||||
is_ajax = False
|
is_ajax = False
|
||||||
|
|
||||||
r = getrower(request.user)
|
r = getrower(request.user)
|
||||||
|
if r.imports_are_private:
|
||||||
|
uploadoptions['makeprivate'] = True
|
||||||
if r.rowerplan == 'freecoach': # pragma: no cover
|
if r.rowerplan == 'freecoach': # pragma: no cover
|
||||||
url = reverse('team_workout_upload_view')
|
url = reverse('team_workout_upload_view')
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|||||||
Reference in New Issue
Block a user