Private
Public Access
1
0

fine tuning

This commit is contained in:
Sander Roosendaal
2018-02-08 15:31:23 +01:00
parent 7d51bb9356
commit 42426cdda2
9 changed files with 376 additions and 162 deletions

View File

@@ -49,7 +49,7 @@ class PlannedSessionAdmin(admin.ModelAdmin):
class GraphImageAdmin(admin.ModelAdmin): class GraphImageAdmin(admin.ModelAdmin):
list_display = ('creationdatetime','workout','filename') list_display = ('creationdatetime','workout','filename')
admin.site.unregister(User) admin.site.unregister(User)
admin.site.register(User,UserAdmin) admin.site.register(User,UserAdmin)
admin.site.register(Workout,WorkoutAdmin) admin.site.register(Workout,WorkoutAdmin)

View File

@@ -797,7 +797,7 @@ class PlannedSession(models.Model):
) )
criteriumchoices = ( criteriumchoices = (
('none','None'), ('none','Approximately'),
('minimum','At Least'), ('minimum','At Least'),
('exact','Exactly'), ('exact','Exactly'),
) )
@@ -879,6 +879,9 @@ class PlannedSession(models.Model):
return stri return stri
# Date input utility
class DateInput(forms.DateInput):
input_type = 'date'
class PlannedSessionForm(ModelForm): class PlannedSessionForm(ModelForm):
class Meta: class Meta:
@@ -888,19 +891,16 @@ class PlannedSessionForm(ModelForm):
'name', 'name',
'sessiontype', 'sessiontype',
'sessionmode', 'sessionmode',
'criterium',
'sessionvalue', 'sessionvalue',
'sessionunit', 'sessionunit',
'comment', 'comment',
] ]
widgets = { widgets = {
'comment': forms.Textarea, 'comment': forms.Textarea,
'startdate': SelectDateWidget( 'startdate': DateInput(),
years=range( 'enddate': DateInput(),
timezone.now().year-1,timezone.now().year+2)), }
'enddate': SelectDateWidget(
years=range(
timezone.now().year-1,timezone.now().year+2)),
}
# Workout # Workout
@@ -1140,9 +1140,6 @@ def auto_delete_image_on_delete(sender,instance, **kwargs):
else: else:
print "couldn't find the file "+instance.filename print "couldn't find the file "+instance.filename
# Date input utility
class DateInput(forms.DateInput):
input_type = 'date'
# Form to update Workout data # Form to update Workout data
class WorkoutForm(ModelForm): class WorkoutForm(ModelForm):

View File

@@ -0,0 +1,57 @@
{% extends "base.html" %}
{% block title %}About us{% endblock title %}
{% block content %}
<div class="grid_6 alpha">
<h2>Coach and Self-Coach Membership</h2>
<p>You have arrived at this page, because you tried to create a
training plan for yourself.</p>
<p>Currently, training planning is restricted to "coach" members with
"team" functionality.</p>
<p>If you are interested in becoming a coach and planning sessions
for a group of rowers on rowsandall.com, contact me through the contact
form.
</p>
<p>If you would like to find a coach who helps you plan your training
through rowsandall.com, contact me throught the contact form.</p>
<p>For self-coached rowers who would like to add the training planning
functionality, we will soon establish a "Self-Coach" plan, which will enable you to do so.</p>
</div>
<div class="grid_6 omega">
<h2>What training planning functionality do we offer?</h2>
<p>Over the spring of 2018, we will gradually expand this functionality.
Our current roadmap is to deploy the following and more:</li>
<p>
<ul>
<li>Create Planned Sessions (trainings, tests, challenges) for yourself
and for your team members (coach plan)</li>
<li>Track your performance against plan.
Match workouts to planned sessions.
Get feedback on plan adherence.</li>
<li>Track your teams performance against plan. See how well each
of your team members adhere to their (team or personalized) plan.</li>
<li>See test outcomes ranked by performance.</li>
<li>Attach courses to your OTW tests. This advanced functionality
allows you, for example, to assign "Row the 6km from bridge A to
bridge B on Saturday" to your team members. The resulting workout
tracks will be evaluated against the course, and you will receive
a results table for the net time spent between the start and finish
points on the course. It's like a mini head race.
</ul>
</p>
</div>
{% endblock content %}

View File

@@ -8,69 +8,105 @@
{% include "planningbuttons.html" %} {% include "planningbuttons.html" %}
</div> </div>
<div id="left" class="grid_6 alpha"> <div class="grid_12 alpha">
<h1>Create a new Planned Session</h1> <div id="left" class="grid_6 alpha">
<h1>Create Session for {{ rower.user.first_name }} {{ rower.user.last_name }}</h1>
</div>
<div id="timeperiod" class="grid_2 dropdown">
<button class="grid_2 alpha button gray small dropbtn">Time Period</button>
<div class="dropdown-content">
<a class="button gray small alpha"
href="/rowers/sessions/create/today/rower/{{ rower.id }}">
Today
</a>
<a class="button gray small alpha"
href="/rowers/sessions/create/thisweek/rower/{{ rower.id }}">
This Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/create/thismonth/rower/{{ rower.id }}">
This Month
</a>
<a class="button gray small alpha"
href="/rowers/sessions/create/lastweek/rower/{{ rower.id }}">
Last Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/create/lastmonth/rower/{{ rower.id }}">
Last Month
</a>
</div>
</div>
</div>
<div class="grid_12 alpha">
<div class="grid_6 alpha">
<form enctype="multipart/form-data" action="{{ formloc }}" method="post"> <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% 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.
</p> </p>
{% endif %} {% endif %}
<table> <table>
{{ form.as_table }} {{ form.as_table }}
</table> </table>
{% csrf_token %} {% csrf_token %}
<div id="formbutton" class="grid_1 prefix_4 suffix_1"> <div id="formbutton" class="grid_1 prefix_4 suffix_1">
<input class="button green" type="submit" value="Submit"> <input class="button green" type="submit" value="Submit">
</div> </div>
</div> </div>
<div id="right" class="grid_6 omega"> <div id="right" class="grid_6 omega">
<h1>Plan</h1> <h1>Plan</h1>
<p> <p>
Click on session name to view Click on session name to view
</p> </p>
<table class="listtable shortpadded" width="80%"> <table class="listtable shortpadded" width="80%">
<thead> <thead>
<tr> <tr>
<th>After</th> <th>After</th>
<th>Before</th> <th>Before</th>
<th>Name</th> <th>Name</th>
<th>Value</th> <th>Value</th>
<th>&nbsp;</th> <th>&nbsp;</th>
<th>Edit</th> <th>Edit</th>
<th>Delete</th> <th>Clone</th>
</tr> <th>Delete</th>
</thead> </tr>
<tbody> </thead>
{% for ps in plannedsessions %} <tbody>
<tr> {% for ps in plannedsessions %}
<td> {{ ps.startdate|date:"Y-m-d" }} </td> <tr>
<td> {{ ps.enddate|date:"Y-m-d" }} </td> <td> {{ ps.startdate|date:"Y-m-d" }} </td>
<td> <td> {{ ps.enddate|date:"Y-m-d" }} </td>
{% if ps.name != '' %} <td>
<a class="small" {% if ps.name != '' %}
href="/rowers/sessions/{{ ps.id }}">{{ ps.name }}</a> <a class="small"
{% else %} href="/rowers/sessions/{{ ps.id }}">{{ ps.name }}</a>
<a class="small" {% else %}
href="/rowers/sessions/{{ ps.id }}">Unnamed Session</a> <a class="small"
{% endif %} href="/rowers/sessions/{{ ps.id }}">Unnamed Session</a>
</td> {% endif %}
<td> {{ ps.sessionvalue }} </td> </td>
<td> {{ ps.sessionunit }} </td> <td> {{ ps.sessionvalue }} </td>
<td> <td> {{ ps.sessionunit }} </td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/edit">Edit</a> <td>
</td> <a class="small" href="/rowers/sessions/{{ ps.id }}/edit">Edit</a>
<td> </td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/deleteconfirm">Delete</a> <td>
</td> <a class="small" href="/rowers/sessions/{{ ps.id }}/clone">Clone</a>
</tr> </td>
{% endfor %}
</tbody> <td>
</table> <a class="small" href="/rowers/sessions/{{ ps.id }}/deleteconfirm">Delete</a>
</div> </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</form> </form>
</div>
{% endblock %} {% endblock %}

View File

@@ -8,72 +8,116 @@
{% include "planningbuttons.html" %} {% include "planningbuttons.html" %}
</div> </div>
<div class="grid_12 alpha">
<div id="left" class="grid_6 alpha"> <div id="left" class="grid_6 alpha">
<h1>Edit Session {{ thesession.name }}</h1> <h1>Edit Session {{ thesession.name }}</h1>
</div>
<div id="timeperiod" class="grid_2 dropdown">
<button class="grid_2 alpha button gray small dropbtn">Time Period</button>
<div class="dropdown-content">
<a class="button gray small alpha"
href="/rowers/sessions/create/today/rower/{{ rower.id }}">
Today
</a>
<a class="button gray small alpha"
href="/rowers/sessions/create/thisweek/rower/{{ rower.id }}">
This Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/create/thismonth/rower/{{ rower.id }}">
This Month
</a>
<a class="button gray small alpha"
href="/rowers/sessions/create/lastweek/rower/{{ rower.id }}">
Last Week
</a>
<a class="button gray small alpha"
href="/rowers/sessions/create/lastmonth/rower/{{ rower.id }}">
Last Month
</a>
</div>
</div>
</div>
<div class="grid_12 alpha">
<div class="grid_6 alpha">
<form enctype="multipart/form-data" action="{{ formloc }}" method="post"> <form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% 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.
</p> </p>
{% endif %} {% endif %}
<table> <table>
{{ form.as_table }} {{ form.as_table }}
</table> </table>
{% csrf_token %} {% csrf_token %}
<div class="grid_1 prefix_3 alpha"> <div class="grid_1 prefix_2 alpha">
<a class="red button small" href="/rowers/sessions/{{ thesession.id }}/deleteconfirm">Delete</a> <a class="red button small" href="/rowers/sessions/{{ thesession.id }}/deleteconfirm">Delete</a>
</div> </div>
<div id="formbutton" class="grid_1 suffix_1 omega"> <div class="grid_1">
<input class="button green" type="submit" value="Submit"> <a class="gray button small" href="/rowers/sessions/{{ thesession.id }}/clone">Clone</a>
</div> </div>
</div> <div id="formbutton" class="grid_1 suffix_1 omega">
<div id="right" class="grid_6 omega"> <input class="button green" type="submit" value="Save">
<h1>Plan</h1> </div>
<p> </div>
Click on session name to view <div id="right" class="grid_6 omega">
</p> <h1>Plan</h1>
<table class="listtable shortpadded" width="80%"> <p>
<thead> Click on session name to view
<tr> </p>
<th>After</th> <table class="listtable shortpadded" width="80%">
<th>Before</th> <thead>
<th>Name</th> <tr>
<th>Value</th> <th>After</th>
<th>&nbsp;</th> <th>Before</th>
<th>Edit</th> <th>Name</th>
<th>Delete</th> <th>Value</th>
</tr> <th>&nbsp;</th>
</thead> <th>Edit</th>
<tbody> <th>Clone</th>
{% for ps in plannedsessions %} <th>Delete</th>
<tr> </tr>
<td> {{ ps.startdate|date:"Y-m-d" }} </td> </thead>
<td> {{ ps.enddate|date:"Y-m-d" }} </td> <tbody>
<td> {% for ps in plannedsessions %}
{% if ps.name != '' %} <tr>
<a class="small" <td> {{ ps.startdate|date:"Y-m-d" }} </td>
href="/rowers/sessions/{{ ps.id }}">{{ ps.name }}</a> <td> {{ ps.enddate|date:"Y-m-d" }} </td>
{% else %} <td>
<a class="small" {% if ps.name != '' %}
href="/rowers/sessions/{{ ps.id }}">Unnamed Session</a> <a class="small"
{% endif %} href="/rowers/sessions/{{ ps.id }}">{{ ps.name }}</a>
</td> {% else %}
<td> {{ ps.sessionvalue }} </td> <a class="small"
<td> {{ ps.sessionunit }} </td> href="/rowers/sessions/{{ ps.id }}">Unnamed Session</a>
<td> {% endif %}
<a class="small" href="/rowers/sessions/{{ ps.id }}/edit">Edit</a> </td>
</td> <td> {{ ps.sessionvalue }} </td>
<td> <td> {{ ps.sessionunit }} </td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/deleteconfirm">Delete</a> <td>
</td> {% if timeperiod and rower %}
</tr> <a class="small" href="/rowers/sessions/{{ ps.id }}/edit/{{ timeperiod }}/rower/{{ rower.id }}">Edit</a>
{% endfor %} {% elif timeperiod %}
</tbody> <a class="small" href="/rowers/sessions/{{ ps.id }}/edit/{{ timeperiod }}">Edit</a>
</table> {% else %}
</div> <a class="small" href="/rowers/sessions/{{ ps.id }}/edit">Edit</a>
{% endif %}
</td>
<td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/clone">Clone</a>
</td>
<td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/deleteconfirm">Delete</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</form> </form>
</div>
{% endblock %} {% endblock %}

View File

@@ -13,7 +13,7 @@
<div class="grid_2"> <div class="grid_2">
<p> <p>
{% if timeperiod and rower %} {% if timeperiod and rower %}
<a class="button gray small" href="/rowers/sessions/manage{{ timeperiod }}/rower/{{ rower.id }}">Manage Sessions</a> <a class="button gray small" href="/rowers/sessions/manage/{{ timeperiod }}/rower/{{ rower.id }}">Manage Sessions</a>
{% elif timeperiod %} {% elif timeperiod %}
<a class="button gray small" href="/rowers/sessions/manage/{{ timeperiod }}">Manage Sessions</a> <a class="button gray small" href="/rowers/sessions/manage/{{ timeperiod }}">Manage Sessions</a>
{% else %} {% else %}

View File

@@ -2,9 +2,9 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block title %}About us{% endblock title %} {% block title %}About us{% endblock title %}
{% block content %} {% block content %}
<h2>Pro Membership</h2>
<div class="grid_6 alpha"> <div class="grid_6 alpha">
<h2>Pro Membership</h2>
<p>Donations are welcome to keep this web site going. To help cover the hosting <p>Donations are welcome to keep this web site going. To help cover the hosting
costs, I have created a <q>Pro</q> membership option (for only 15 EURO per year). Once I process your costs, I have created a <q>Pro</q> membership option (for only 15 EURO per year). Once I process your
@@ -27,7 +27,7 @@ You will be taken to the secure PayPal payment site.
</div> </div>
<div class="grid_6 omega"> <div class="grid_6 omega">
<h3>Recurring Payment</h2> <h2>Recurring Payment</h2>
<p>You need a Paypal account for this</p> <p>You need a Paypal account for this</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="cmd" value="_s-xclick">
@@ -40,7 +40,7 @@ You will be taken to the secure PayPal payment site.
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form> </form>
<h3>One Year Subscription</h3> <h2>One Year Subscription</h2>
<p>Only a credit card needed. Will not automatically renew</p> <p>Only a credit card needed. Will not automatically renew</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="cmd" value="_s-xclick">
@@ -49,7 +49,7 @@ You will be taken to the secure PayPal payment site.
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form> </form>
<h3>Payment Processing</h3> <h2>Payment Processing</h2>
<p>After you do the payment, we will manually change your membership to <p>After you do the payment, we will manually change your membership to
"Pro". Depending on our availability, this may take some time "Pro". Depending on our availability, this may take some time
(typically one working day). Don't hesitate to contact us (typically one working day). Don't hesitate to contact us

View File

@@ -382,6 +382,7 @@ urlpatterns = [
url(r'^videos', TemplateView.as_view(template_name='videos.html'),name='videos'), url(r'^videos', TemplateView.as_view(template_name='videos.html'),name='videos'),
url(r'^analysis', TemplateView.as_view(template_name='analysis.html'),name='analysis'), url(r'^analysis', TemplateView.as_view(template_name='analysis.html'),name='analysis'),
url(r'^promembership', TemplateView.as_view(template_name='promembership.html'),name='promembership'), url(r'^promembership', TemplateView.as_view(template_name='promembership.html'),name='promembership'),
url(r'^planmembership', TemplateView.as_view(template_name='planmembership.html'),name='planmembership'),
url(r'^paypaltest', TemplateView.as_view(template_name='paypaltest.html'),name='paypaltest'), url(r'^paypaltest', TemplateView.as_view(template_name='paypaltest.html'),name='paypaltest'),
url(r'^legal', TemplateView.as_view(template_name='legal.html'),name='legal'), url(r'^legal', TemplateView.as_view(template_name='legal.html'),name='legal'),
url(r'^register$',views.rower_register_view), url(r'^register$',views.rower_register_view),
@@ -397,11 +398,25 @@ urlpatterns = [
url(r'^test\_callback',views.rower_process_testcallback), url(r'^test\_callback',views.rower_process_testcallback),
url(r'^workout/(?P<id>\d+)/test\_strokedata$',views.strokedataform), url(r'^workout/(?P<id>\d+)/test\_strokedata$',views.strokedataform),
url(r'^sessions/create$',views.plannedsession_create_view), url(r'^sessions/create$',views.plannedsession_create_view),
url(r'^sessions/create/rower/(?P<rowerid>\d+)$',
views.plannedsession_create_view),
url(
r'^sessions/create/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',
views.plannedsession_create_view),
url(r'^sessions/create/(?P<timeperiod>[\w\ ]+.*)$',
views.plannedsession_create_view),
url(r'^sessions/(?P<id>\d+)/edit$',views.plannedsession_edit_view), url(r'^sessions/(?P<id>\d+)/edit$',views.plannedsession_edit_view),
url(r'^sessions/(?P<id>\d+)/edit/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsession_edit_view),
url(r'^sessions/(?P<id>\d+)/edit/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsession_edit_view),
url(r'^sessions/(?P<id>\d+)/clone$',views.plannedsession_clone_view),
url(r'^sessions/(?P<id>\d+)/clone/(?P<timeperiod>[\w\ ]+.*)/rower/(?P<rowerid>\d+)$',views.plannedsession_clone_view),
url(r'^sessions/(?P<id>\d+)/clone/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsession_clone_view),
url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view), url(r'^sessions/(?P<id>\d+)$',views.plannedsession_view),
url(r'^sessions/(?P<id>\d+)/deleteconfirm$',views.plannedsession_deleteconfirm_view), url(r'^sessions/(?P<id>\d+)/deleteconfirm$',views.plannedsession_deleteconfirm_view),
url(r'^sessions/(?P<id>\d+)/delete$',views.plannedsession_delete_view), url(r'^sessions/(?P<id>\d+)/delete$',views.plannedsession_delete_view),
url(r'^sessions/manage/session/(?P<initialsession>\d+)$', url(r'^sessions/manage/session/(?P<initialsession>\d+)$',
views.plannedsessions_manage_view), views.plannedsessions_manage_view),
url(r'^sessions/manage/rower/(?P<rowerid>\d+)/session/(?P<initialsession>\d+)$', url(r'^sessions/manage/rower/(?P<rowerid>\d+)/session/(?P<initialsession>\d+)$',

View File

@@ -11710,11 +11710,19 @@ def agegrouprecordview(request,sex='male',weightcategory='hwt',
}) })
# Individual user creates training for himself # Individual user creates training for himself
@user_passes_test(hasplannedsessions,login_url="/rowers/promembership/", @user_passes_test(hasplannedsessions,login_url="/rowers/planmembership/",
redirect_field_name=None) redirect_field_name=None)
def plannedsession_create_view(request): def plannedsession_create_view(request,timeperiod='today',rowerid=0):
r = getrower(request.user) if rowerid==0:
r = getrower(request.user)
else:
try:
r = Rower.objects.get(id=rowerid)
except Rower.DoesNotExist:
raise Http404("This rower doesn't exist")
if not checkaccessuser(request.user,r):
raise Http404("You don't have access to this plan")
if request.method == 'POST': if request.method == 'POST':
sessioncreateform = PlannedSessionForm(request.POST) sessioncreateform = PlannedSessionForm(request.POST)
@@ -11724,6 +11732,7 @@ def plannedsession_create_view(request):
enddate = cd['enddate'] enddate = cd['enddate']
sessiontype = cd['sessiontype'] sessiontype = cd['sessiontype']
sessionmode = cd['sessionmode'] sessionmode = cd['sessionmode']
criterium = cd['criterium']
sessionvalue = cd['sessionvalue'] sessionvalue = cd['sessionvalue']
sessionunit = cd['sessionunit'] sessionunit = cd['sessionunit']
comment = cd['comment'] comment = cd['comment']
@@ -11743,6 +11752,7 @@ def plannedsession_create_view(request):
sessionvalue=sessionvalue, sessionvalue=sessionvalue,
sessionunit=sessionunit, sessionunit=sessionunit,
comment=comment, comment=comment,
criterium=criterium,
manager=request.user) manager=request.user)
ps.save() ps.save()
@@ -11754,13 +11764,15 @@ def plannedsession_create_view(request):
else: else:
sessioncreateform = PlannedSessionForm() sessioncreateform = PlannedSessionForm()
sps = get_sessions(r) startdate,enddate = get_dates_timeperiod(timeperiod)
sps = get_sessions(r,startdate=startdate,enddate=enddate)
return render(request,'plannedsessioncreate.html', return render(request,'plannedsessioncreate.html',
{ {
'teams':get_my_teams(request.user), 'teams':get_my_teams(request.user),
'form':sessioncreateform, 'form':sessioncreateform,
'plannedsessions':sps, 'plannedsessions':sps,
'rower':r,
}) })
@login_required() @login_required()
@@ -11909,12 +11921,22 @@ def plannedsessions_manage_view(request,timeperiod='today',rowerid=0,
}) })
# Edit an existing planned session # Clone an existing planned session
@user_passes_test(hasplannedsessions,login_url="/rowers/promembership/", @user_passes_test(hasplannedsessions,login_url="/rowers/planmembership/",
redirect_field_name=None) redirect_field_name=None)
def plannedsession_edit_view(request,id=0): def plannedsession_clone_view(request,id=0,rowerid=0,
timeperiod='today'):
if rowerid==0:
r = getrower(request.user)
else:
try:
r = Rower.objects.get(id=rowerid)
except Rower.DoesNotExist:
raise Http404("This rower doesn't exist")
if not checkaccessuser(request.user,r):
raise Http404("You don't have access to this plan")
r = getrower(request.user) startdate,enddate = get_dates_timeperiod(timeperiod)
try: try:
ps = PlannedSession.objects.get(id=id) ps = PlannedSession.objects.get(id=id)
@@ -11922,26 +11944,65 @@ def plannedsession_edit_view(request,id=0):
raise Http404("Planned Session does not exist") raise Http404("Planned Session does not exist")
if ps.manager != request.user: if ps.manager != request.user:
raise Http404("You are not allowed to delete this planned session") raise Http404("You are not allowed to clone this planned session")
ps.pk = None
ps.startdate = timezone.now()
ps.enddate = timezone.now()
ps.name += ' (copy)'
ps.save()
add_rower_session(r,ps)
url = reverse(plannedsession_edit_view,
kwargs = {
'id':ps.id,
'timeperiod':timeperiod,
'rowerid':r.id,
}
)
return HttpResponseRedirect(url)
# Edit an existing planned session
@user_passes_test(hasplannedsessions,login_url="/rowers/planmembership/",
redirect_field_name=None)
def plannedsession_edit_view(request,id=0,timeperiod='today',rowerid=0):
if rowerid==0:
r = getrower(request.user)
else:
try:
r = Rower.objects.get(id=rowerid)
except Rower.DoesNotExist:
raise Http404("This rower doesn't exist")
if not checkaccessuser(request.user,r):
raise Http404("You don't have access to this plan")
startdate,enddate = get_dates_timeperiod(timeperiod)
try:
ps = PlannedSession.objects.get(id=id)
except PlannedSession.DoesNotExist:
raise Http404("Planned Session does not exist")
if ps.manager != request.user:
raise Http404("You are not allowed to edit this planned session")
if request.method == 'POST': if request.method == 'POST':
sessioncreateform = PlannedSessionForm(request.POST,instance=ps) sessioncreateform = PlannedSessionForm(request.POST,instance=ps)
if sessioncreateform.is_valid(): if sessioncreateform.is_valid():
cd = sessioncreateform.cleaned_data cd = sessioncreateform.cleaned_data
startdate = cd['startdate']
enddate = cd['enddate']
sessiontype = cd['sessiontype']
sessionmode = cd['sessionmode']
sessionvalue = cd['sessionvalue']
sessionunit = cd['sessionunit']
if sessionunit == 'min': if cd['sessionunit'] == 'min':
sessionmode = 'time' cd['sessionmode'] = 'time'
elif sessionunit in ['km','m']: elif cd['sessionunit'] in ['km','m']:
sessionmode = 'distance' cd['sessionmode'] = 'distance'
comment = cd['comment']
name = cd['name']
res,message = update_plannedsession(ps,cd) res,message = update_plannedsession(ps,cd)
@@ -11953,12 +12014,14 @@ def plannedsession_edit_view(request,id=0):
url = reverse(plannedsession_edit_view, url = reverse(plannedsession_edit_view,
kwargs={ kwargs={
'id':int(ps.id), 'id':int(ps.id),
'timeperiod':timeperiod,
'rowerid':r.id,
}) })
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
else: else:
sessioncreateform = PlannedSessionForm(instance=ps) sessioncreateform = PlannedSessionForm(instance=ps)
sps = get_sessions(r) sps = get_sessions(r,startdate=startdate,enddate=enddate)
return render(request,'plannedsessionedit.html', return render(request,'plannedsessionedit.html',
{ {
@@ -11966,6 +12029,8 @@ def plannedsession_edit_view(request,id=0):
'form':sessioncreateform, 'form':sessioncreateform,
'plannedsessions':sps, 'plannedsessions':sps,
'thesession':ps, 'thesession':ps,
'rower':r,
'timeperiod':timeperiod,
}) })