added date ranges to sessionview
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from datetime import date
|
||||||
import time
|
import time
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
import uuid
|
import uuid
|
||||||
@@ -104,8 +105,9 @@ def remove_rower_session(r,ps):
|
|||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def get_sessions(r,startdate=timezone.now(),
|
def get_sessions(r,startdate=date.today(),
|
||||||
enddate=timezone.now()+timezone.timedelta(+1000)):
|
enddate=date.today()+timezone.timedelta(+1000)):
|
||||||
|
|
||||||
sps = PlannedSession.objects.filter(
|
sps = PlannedSession.objects.filter(
|
||||||
rower__in=[r],
|
rower__in=[r],
|
||||||
startdate__gte=startdate,
|
startdate__gte=startdate,
|
||||||
|
|||||||
@@ -40,4 +40,4 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
45
rowers/templates/plannedsessiondeleteconfirm.html
Normal file
45
rowers/templates/plannedsessiondeleteconfirm.html
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load staticfiles %}
|
||||||
|
|
||||||
|
{% block title %}Planned Session{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="grid_12 alpha">
|
||||||
|
{% include "planningbuttons.html" %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="left" class="grid_6 alpha">
|
||||||
|
<h1>Confirm Delete</h1>
|
||||||
|
<p>This will permanently delete the planned session</p>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="grid_2 alpha">
|
||||||
|
<p>
|
||||||
|
<a class="button green small" href="/rowers/sessions/">Cancel</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid_2">
|
||||||
|
<p>
|
||||||
|
<a class="button red small" href="/rowers/sessions/{{ ps.id }}/delete">Delete</a>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="right" class="grid_6 omega">
|
||||||
|
<h1>Session {{ psdict.name.1 }}</h1>
|
||||||
|
<table class="listtable shortpadded">
|
||||||
|
{% for attr in attrs %}
|
||||||
|
{% for key,value in psdict.items %}
|
||||||
|
{% if key == attr %}
|
||||||
|
<tr>
|
||||||
|
<td><b>{{ value.0 }}</b></td><td>{{ value.1 }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
54
rowers/templates/plannedsessions.html
Normal file
54
rowers/templates/plannedsessions.html
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% load staticfiles %}
|
||||||
|
|
||||||
|
{% block title %}Planned Sessions{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="grid_12 alpha">
|
||||||
|
{% include "planningbuttons.html" %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div id="left" class="grid_6 alpha">
|
||||||
|
<p>Placeholder text</p>
|
||||||
|
</div>
|
||||||
|
<div id="right" class="grid_6 omega">
|
||||||
|
<h1>Plan</h1>
|
||||||
|
<p>
|
||||||
|
Click on session name to view
|
||||||
|
</p>
|
||||||
|
<table class="listtable shortpadded">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>After</th>
|
||||||
|
<th>Before</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Value</th>
|
||||||
|
<th> </th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for ps in plannedsessions %}
|
||||||
|
<tr>
|
||||||
|
<td> {{ ps.startdate|date:"Y-m-d" }} </td>
|
||||||
|
<td> {{ ps.enddate|date:"Y-m-d" }} </td>
|
||||||
|
<td>
|
||||||
|
{% if ps.name != '' %}
|
||||||
|
<a class="small"
|
||||||
|
href="/rowers/sessions/{{ ps.id }}">{{ ps.name }}</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="small"
|
||||||
|
href="/rowers/sessions/{{ ps.id }}">Unnamed Session</a>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td> {{ ps.sessionvalue }} </td>
|
||||||
|
<td> {{ ps.sessionunit }} </td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
@@ -399,6 +399,10 @@ urlpatterns = [
|
|||||||
url(r'^sessions/create$',views.plannedsession_create_view),
|
url(r'^sessions/create$',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+)$',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+)/delete$',views.plannedsession_delete_view),
|
||||||
|
url(r'^sessions/?$',views.plannedsessions_view),
|
||||||
|
url(r'^sessions/(?P<timeperiod>[\w\ ]+.*)$',views.plannedsessions_view),
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
|||||||
102
rowers/views.py
102
rowers/views.py
@@ -11704,7 +11704,7 @@ 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="/",
|
@user_passes_test(hasplannedsessions,login_url="/rowers/promembership/",
|
||||||
redirect_field_name=None)
|
redirect_field_name=None)
|
||||||
def plannedsession_create_view(request):
|
def plannedsession_create_view(request):
|
||||||
|
|
||||||
@@ -11752,8 +11752,49 @@ def plannedsession_create_view(request):
|
|||||||
'plannedsessions':sps,
|
'plannedsessions':sps,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@login_required()
|
||||||
|
def plannedsessions_view(request,timeperiod='today',rowerid=0):
|
||||||
|
|
||||||
|
if rowerid==0:
|
||||||
|
r = getrower(request.user)
|
||||||
|
else:
|
||||||
|
r = getrower(id=rowerid)
|
||||||
|
if not checkaccessuser(request.user,r):
|
||||||
|
raise Http404("You don't have access to this plan")
|
||||||
|
|
||||||
|
# set start end date according timeperiod
|
||||||
|
if timeperiod=='today':
|
||||||
|
startdate=datetime.date.today()
|
||||||
|
enddate=datetime.date.today()
|
||||||
|
elif timeperiod=='tomorrow':
|
||||||
|
startdate=datetime.date.today()+timezone.timedelta(days=1)
|
||||||
|
enddate=datetime.date.today()+timezone.timedelta(days=1)
|
||||||
|
elif timeperiod=='thisweek':
|
||||||
|
today = datetime.date.today()
|
||||||
|
startdate = datetime.date.today()-timezone.timedelta(days=today.weekday())
|
||||||
|
enddate = startdate+timezone.timedelta(weeks=1)
|
||||||
|
elif timeperiod=='thismonth':
|
||||||
|
today = datetime.date.today()
|
||||||
|
startdate = today.replace(day=1)
|
||||||
|
enddate = startdate+timezone.timedelta(days=32)
|
||||||
|
enddate = enddate.replace(day=1)
|
||||||
|
else:
|
||||||
|
startdate = datetime.date.today()
|
||||||
|
enddate = datetime.date.today()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sps = get_sessions(r,startdate=startdate,enddate=enddate)
|
||||||
|
|
||||||
|
return render(request,'plannedsessions.html',
|
||||||
|
{
|
||||||
|
'teams':get_my_teams(request.user),
|
||||||
|
'plannedsessions':sps,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# Edit an existing planned session
|
# Edit an existing planned session
|
||||||
@user_passes_test(hasplannedsessions,login_url="/",
|
@user_passes_test(hasplannedsessions,login_url="/rowers/promembership/",
|
||||||
redirect_field_name=None)
|
redirect_field_name=None)
|
||||||
def plannedsession_edit_view(request,id=0):
|
def plannedsession_edit_view(request,id=0):
|
||||||
|
|
||||||
@@ -11764,6 +11805,9 @@ def plannedsession_edit_view(request,id=0):
|
|||||||
except PlannedSession.DoesNotExist:
|
except PlannedSession.DoesNotExist:
|
||||||
raise Http404("Planned Session does not exist")
|
raise Http404("Planned Session does not exist")
|
||||||
|
|
||||||
|
if ps.manager != request.user:
|
||||||
|
raise Http404("You are not allowed to delete 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():
|
||||||
@@ -11802,6 +11846,9 @@ def plannedsession_edit_view(request,id=0):
|
|||||||
'thesession':ps,
|
'thesession':ps,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@login_required()
|
||||||
def plannedsession_view(request,id=0):
|
def plannedsession_view(request,id=0):
|
||||||
|
|
||||||
r = getrower(request.user)
|
r = getrower(request.user)
|
||||||
@@ -11812,7 +11859,9 @@ def plannedsession_view(request,id=0):
|
|||||||
raise Http404("Planned Session does not exist")
|
raise Http404("Planned Session does not exist")
|
||||||
|
|
||||||
|
|
||||||
psdict = {}
|
if ps.manager != request.user:
|
||||||
|
raise Http404("You are not allowed to delete this planned session")
|
||||||
|
|
||||||
|
|
||||||
psdict = my_dict_from_instance(ps,PlannedSession)
|
psdict = my_dict_from_instance(ps,PlannedSession)
|
||||||
|
|
||||||
@@ -11821,7 +11870,52 @@ def plannedsession_view(request,id=0):
|
|||||||
'psdict': psdict,
|
'psdict': psdict,
|
||||||
'attrs':[
|
'attrs':[
|
||||||
'name','startdate','enddate','sessiontype',
|
'name','startdate','enddate','sessiontype',
|
||||||
'comment'
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
@login_required()
|
||||||
|
def plannedsession_delete_view(request,id=0):
|
||||||
|
r = getrower(request.user)
|
||||||
|
|
||||||
|
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 delete this planned session")
|
||||||
|
|
||||||
|
ps.delete()
|
||||||
|
|
||||||
|
url = reverse(plannedsessions_view)
|
||||||
|
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
@login_required()
|
||||||
|
def plannedsession_deleteconfirm_view(request,id=0):
|
||||||
|
|
||||||
|
r = getrower(request.user)
|
||||||
|
|
||||||
|
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 delete this planned session")
|
||||||
|
|
||||||
|
|
||||||
|
psdict = my_dict_from_instance(ps,PlannedSession)
|
||||||
|
|
||||||
|
return render(request,'plannedsessiondeleteconfirm.html',
|
||||||
|
{
|
||||||
|
'ps':ps,
|
||||||
|
'psdict': psdict,
|
||||||
|
'attrs':[
|
||||||
|
'name','startdate','enddate','sessiontype',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,13 +3,6 @@
|
|||||||
{% load rowerfilters %}
|
{% load rowerfilters %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block plans %}
|
|
||||||
{% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %}
|
|
||||||
<p><a class="button gray small" href="/rowers/sessions/">Plans</a></p>
|
|
||||||
{% else %}
|
|
||||||
<p><a class="button gray small" href="/rowers/promembership/">Plans</a></p>
|
|
||||||
{% endif %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
|
|
||||||
{% block teams %}
|
{% block teams %}
|
||||||
|
|||||||
@@ -202,8 +202,11 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
<div class="grid_1 tooltip">
|
<div class="grid_1 tooltip">
|
||||||
{% block plans %}
|
{% if user.is_authenticated %}
|
||||||
{% endblock %}
|
<p><a class="button gray small" href="/rowers/sessions/">Plans</a></p>
|
||||||
|
{% else %}
|
||||||
|
<p> </p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="grid_1 tooltip">
|
<div class="grid_1 tooltip">
|
||||||
{% block challenges %}
|
{% block challenges %}
|
||||||
|
|||||||
Reference in New Issue
Block a user