added date ranges to sessionview
This commit is contained in:
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