added date ranges to sessionview
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
from django.utils import timezone
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from datetime import date
|
||||
import time
|
||||
from django.db import IntegrityError
|
||||
import uuid
|
||||
@@ -104,8 +105,9 @@ def remove_rower_session(r,ps):
|
||||
|
||||
return 1
|
||||
|
||||
def get_sessions(r,startdate=timezone.now(),
|
||||
enddate=timezone.now()+timezone.timedelta(+1000)):
|
||||
def get_sessions(r,startdate=date.today(),
|
||||
enddate=date.today()+timezone.timedelta(+1000)):
|
||||
|
||||
sps = PlannedSession.objects.filter(
|
||||
rower__in=[r],
|
||||
startdate__gte=startdate,
|
||||
|
||||
@@ -40,4 +40,4 @@
|
||||
</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/(?P<id>\d+)/edit$',views.plannedsession_edit_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:
|
||||
|
||||
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
|
||||
@user_passes_test(hasplannedsessions,login_url="/",
|
||||
@user_passes_test(hasplannedsessions,login_url="/rowers/promembership/",
|
||||
redirect_field_name=None)
|
||||
def plannedsession_create_view(request):
|
||||
|
||||
@@ -11752,8 +11752,49 @@ def plannedsession_create_view(request):
|
||||
'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
|
||||
@user_passes_test(hasplannedsessions,login_url="/",
|
||||
@user_passes_test(hasplannedsessions,login_url="/rowers/promembership/",
|
||||
redirect_field_name=None)
|
||||
def plannedsession_edit_view(request,id=0):
|
||||
|
||||
@@ -11764,6 +11805,9 @@ def plannedsession_edit_view(request,id=0):
|
||||
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")
|
||||
|
||||
if request.method == 'POST':
|
||||
sessioncreateform = PlannedSessionForm(request.POST,instance=ps)
|
||||
if sessioncreateform.is_valid():
|
||||
@@ -11802,6 +11846,9 @@ def plannedsession_edit_view(request,id=0):
|
||||
'thesession':ps,
|
||||
})
|
||||
|
||||
|
||||
|
||||
@login_required()
|
||||
def plannedsession_view(request,id=0):
|
||||
|
||||
r = getrower(request.user)
|
||||
@@ -11812,7 +11859,9 @@ def plannedsession_view(request,id=0):
|
||||
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)
|
||||
|
||||
@@ -11821,7 +11870,52 @@ def plannedsession_view(request,id=0):
|
||||
'psdict': psdict,
|
||||
'attrs':[
|
||||
'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',
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user