Private
Public Access
1
0

first changes for template planned sessions

This commit is contained in:
Sander Roosendaal
2019-09-22 12:56:53 +02:00
parent 2917513be1
commit d0b0c37674
8 changed files with 129 additions and 2 deletions

View File

@@ -2128,6 +2128,8 @@ class PlannedSession(models.Model):
hasranking = models.BooleanField(default=False)
is_template = models.BooleanField(default=False)
def __str__(self):
name = self.name

View File

@@ -600,6 +600,7 @@ def get_sessions_manager(m,teamid=0,startdate=date.today(),
manager=m,
startdate__lte=enddate,
enddate__gte=startdate,
is_template=False,
).order_by("preferreddate","startdate","enddate").exclude(
sessiontype='race').exclude(sessiontype='indoorrace')
else:
@@ -607,6 +608,7 @@ def get_sessions_manager(m,teamid=0,startdate=date.today(),
manager=m,
startdate__lte=enddate,
enddate__gte=startdate,
is_template=False,
).order_by("preferreddate","startdate","enddate").exclude(
sessiontype='race').exclude(sessiontype='indoorrace')
@@ -619,6 +621,7 @@ def get_sessions(r,startdate=date.today(),
rower__in=[r],
startdate__lte=enddate,
enddate__gte=startdate,
is_template=False,
).order_by("preferreddate","startdate","enddate").exclude(
sessiontype='race').exclude(sessiontype='indoorrace')

View File

@@ -60,6 +60,7 @@
<th>Edit</th>
<th>Clone</th>
<th>Delete</th>
<th>Template</th>
</tr>
</thead>
<tbody>
@@ -88,6 +89,45 @@
<td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/deleteconfirm/">Delete</a>
</td>
<td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/maketemplate/">Save</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</li>
<li class="grid_2">
<h1>Templates</h1>
<p>
Click on session name to clone to current period
</p>
<table class="listtable shortpadded" width="80%">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th>&nbsp;</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for ps in sessiontemplates %}
<tr>
<td>
{% if ps.name != '' %}
<a class="small"
href="/rowers/sessions/{{ ps.id }}/clone/user/{{ rower.user.id }}/?when={{ timeperiod }}">{{ ps.name }}</a>
{% else %}
<a class="small"
href="/rowers/sessions/{{ ps.id }}/clone/user/{{ rower.user.id }}/?when={{ timeperiod }}">Unnamed Session</a>
{% endif %}
</td>
<td> {{ ps.sessionvalue }} </td>
<td> {{ ps.sessionunit }} </td>
<td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/deleteconfirm/">Delete</a>
</td>
</tr>
{% endfor %}
</tbody>

View File

@@ -18,6 +18,7 @@
</p>
</li>
{% if not object.is_template %}
<li class="grid_2">
<h2>Session {{ psdict.name.1 }}</h2>
<table class="listtable shortpadded">
@@ -32,6 +33,7 @@
{% endfor %}
</table>
</li>
{% endif %}
</ul>

View File

@@ -110,6 +110,42 @@
</tbody>
</table>
</li>
<li class="grid_2">
<h1>Templates</h1>
<p>
Click on session name to clone to current period
</p>
<table class="listtable shortpadded" width="80%">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th>&nbsp;</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
{% for ps in sessiontemplates %}
<tr>
<td>
{% if ps.name != '' %}
<a class="small"
href="/rowers/sessions/{{ ps.id }}/clone/user/{{ rower.user.id }}/?when={{ timeperiod }}">{{ ps.name }}</a>
{% else %}
<a class="small"
href="/rowers/sessions/{{ ps.id }}/clone/user/{{ rower.user.id }}/?when={{ timeperiod }}">Unnamed Session</a>
{% endif %}
</td>
<td> {{ ps.sessionvalue }} </td>
<td> {{ ps.sessionunit }} </td>
<td>
<a class="small" href="/rowers/sessions/{{ ps.id }}/deleteconfirm/">Delete</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</li>
</ul>
{% endblock %}

Binary file not shown.

View File

@@ -649,6 +649,7 @@ urlpatterns = [
views.plannedsession_multicreate_view,
name='plannedsession_multicreate_view'),
re_path(r'^sessions/(?P<id>\d+)/edit/$',views.plannedsession_edit_view),
re_path(r'^sessions/(?P<id>\d+)/maketemplate/$',views.plannedsession_totemplate_view),
re_path(r'^sessions/(?P<id>\d+)/compare/$',
views.plannedsession_compare_view,
name='plannedsession_compare_view'),

View File

@@ -240,6 +240,7 @@ def plannedsession_multiclone_view(
sps = PlannedSession.objects.filter(
manager=request.user,
rower__in=[r],
is_template=False,
startdate__lte=enddate,
enddate__gte=startdate).order_by(
"startdate","preferreddate","enddate").exclude(
@@ -435,6 +436,10 @@ def plannedsession_create_view(request,
sps = get_sessions(r,startdate=startdate,enddate=enddate).exclude(
sessiontype='race')
sessiontemplates = PlannedSession.objects.filter(manager=request.user,is_template=True)
try:
trainingplan = TrainingPlan.objects.filter(
startdate__lte = startdate,
@@ -458,6 +463,7 @@ def plannedsession_create_view(request,
'form':sessioncreateform,
'active':'nav-plan',
'plannedsessions':sps,
'sessiontemplates':sessiontemplates,
'rower':r,
'timeperiod':timeperiod,
})
@@ -1412,13 +1418,16 @@ def plannedsession_clone_view(request,id=0,userid=0):
teams = ps.team.all()
ps.pk = None
ps.id = None
if not ps.is_template:
ps.name += ' (copy)'
ps.is_template = False
deltadays = ps.enddate-ps.startdate
ps.startdate = timezone.now().date()
ps.enddate = (timezone.now()+deltadays).date()
ps.preferreddate = ps.preferreddate+deltadays
ps.name += ' (copy)'
ps.save()
@@ -1441,6 +1450,37 @@ def plannedsession_clone_view(request,id=0,userid=0):
return HttpResponseRedirect(url)
@user_passes_test(hasplannedsessions, login_url="/rowers/paidplans/",
message="This functionality requires a Coach or Self-Coach plan",
redirect_field_name=None)
def plannedsession_totemplate_view(request,id=0):
r = getrequestplanrower(request)
startdate, enddate = get_dates_timeperiod(request)
try:
ps = PlannedSession.objects.get(id=id)
except PlannedSession.DoesNotExist:
raise Http404("Planned Session does not exist")
if ps.manager != request.user:
raise PermissionDenied("You can only store your own sessions as a template")
ps.pk = None
ps.id = None
ps.is_template = True
ps.startdate = datetime.date(1970,1,1)
ps.enddate = datetime.date(1970,1,1)
ps.save()
url = reverse(plannedsession_create_view,kwargs={'userid':request.user.id})
startdatestring = startdate.strftime('%Y-%m-%d')
enddatestring = enddate.strftime('%Y-%m-%d')
url += '?when='+startdatestring+'/'+enddatestring
return HttpResponseRedirect(url)
# Edit an existing planned session
@user_passes_test(hasplannedsessions,login_url="/rowers/paidplans/",
@@ -1547,6 +1587,8 @@ def plannedsession_edit_view(request,id=0,userid=0):
]
sessiontemplates = PlannedSession.objects.filter(manager=request.user,is_template=True)
dateform = DateRangeForm(initial={
'startdate':startdate,
'enddate':enddate,
@@ -1564,6 +1606,7 @@ def plannedsession_edit_view(request,id=0,userid=0):
'plannedsessions':sps,
'thesession':ps,
'dateform':dateform,
'sessiontemplates':sessiontemplates,
'rower':r,
'timeperiod':timeperiod,
})