Private
Public Access
1
0

shared sessions now work

This commit is contained in:
Sander Roosendaal
2021-03-05 11:52:56 +01:00
parent b107ea3a50
commit f88af509cc
7 changed files with 448 additions and 33 deletions

View File

@@ -412,6 +412,30 @@ def plannedsession_multiclone_view(
}
)
@permission_required('plannedsession.change_session',fn=get_session_by_pk,raise_exception=True)
@user_passes_test(can_plan,login_url="/rowers/paidplans/",
message="This functionality requires a Coach or Self-Coach plan",
redirect_field_name=None)
def template_share_view(request,id=0,userid=0):
r = getrequestplanrower(request,userid=userid)
ps = get_object_or_404(PlannedSession,pk=id)
ps.is_public = True
ps.save()
return HttpResponseRedirect(reverse(template_library_view))
@permission_required('plannedsession.change_session',fn=get_session_by_pk,raise_exception=True)
@user_passes_test(can_plan,login_url="/rowers/paidplans/",
message="This functionality requires a Coach or Self-Coach plan",
redirect_field_name=None)
def template_makeprivate_view(request,id=0,userid=0):
r = getrequestplanrower(request,userid=userid)
ps = get_object_or_404(PlannedSession,pk=id)
ps.is_public = False
ps.save()
return HttpResponseRedirect(reverse(template_library_view))
# Manage Template sessions (library)
@user_passes_test(can_plan,login_url="/rowers/paidplans/",
@@ -420,6 +444,9 @@ def plannedsession_multiclone_view(
def template_library_view(request,userid=0):
r = getrequestplanrower(request,userid=userid)
templates = PlannedSession.objects.filter(manager=request.user,is_template=True)
templates2 = PlannedSession.objects.filter(is_template=True,is_public=True)
templates = templates | templates2
startdate,enddate = get_dates_timeperiod(request)
@@ -431,6 +458,20 @@ def template_library_view(request,userid=0):
except IndexError:
trainingplan = None
alltags = []
for t in templates:
tags = t.tags.all()
for tag in tags:
alltags.append(tag)
alltags = uniqify(alltags)
tag = request.GET.get('tag')
if tag:
tags = [tag]
templates = templates.filter(tags__name__in=tags).distinct()
breadcrumbs = [
{
'url': reverse(plannedsessions_view),
@@ -450,6 +491,7 @@ def template_library_view(request,userid=0):
'plan': trainingplan,
'rower':r,
'active':'nav-plan',
'alltags':alltags,
}
)
@@ -561,13 +603,19 @@ def plannedsession_create_view(request,
sessiontemplates = sessiontemplates.order_by("name")
alltags = []
for t in sessiontemplates:
tags = t.tags.all()
for tag in tags:
alltags.append(tag)
alltags = uniqify(alltags)
tag = request.GET.get('tag')
if tag:
tags = [tag]
sessiontemplates = sessiontemplates.filter(tags__name__in=tags).distinct()
alltags = Tag.objects.all()
try:
trainingplan = TrainingPlan.objects.filter(
startdate__lte = startdate,
@@ -597,6 +645,84 @@ def plannedsession_create_view(request,
'alltags':alltags,
})
@user_passes_test(can_plan,login_url="/rowers/paidplans/",
message="This functionality requires a Coach or Self-Coach plan",
redirect_field_name=None)
def plannedsession_createtemplate_view(request,
userid=0,
):
r = getrequestplanrower(request,userid=userid)
startdate,enddate = get_dates_timeperiod(request)
if request.method == 'POST':
sessioncreateform = PlannedSessionTemplateForm(request.POST, request.FILES)
if sessioncreateform.is_valid():
ps = sessioncreateform.save(commit=False)
ps.manager = request.user
ps.is_template = True
ps.save()
sessioncreateform.save_m2m()
add_rower_session(r,ps)
url = reverse("template_library_view")
return HttpResponseRedirect(url)
else:
sessioncreateform = PlannedSessionTemplateForm()
sessiontemplates = PlannedSession.objects.filter(
manager=request.user,
is_template=True).order_by("name")
sessiontemplates2 = PlannedSession.objects.filter(
is_template=True,is_public=True
).order_by("name")
sessiontemplates = sessiontemplates | sessiontemplates2
sessiontemplates = sessiontemplates.order_by("name")
alltags = []
for t in sessiontemplates:
tags = t.tags.all()
for tag in tags:
alltags.append(tag)
alltags = uniqify(alltags)
try:
trainingplan = TrainingPlan.objects.filter(
startdate__lte = startdate,
rowers = r,
enddate__gte = enddate)[0]
except IndexError:
trainingplan = None
breadcrumbs = [
{
'url': reverse(plannedsessions_view),
'name': 'Sessions'
},
{
'url':reverse(plannedsession_createtemplate_view),
'name': 'Create Library Session'
}
]
return render(request,'plannedsessiontemplatecreate.html',
{
'teams':get_my_teams(request.user),
'plan':trainingplan,
'form':sessioncreateform,
'active':'nav-plan',
'rower':r,
'alltags':alltags,
})
@user_passes_test(can_plan,login_url="/rowers/paidplans/",
message="This functionality requires a Coach or Self-Coach plan",
redirect_field_name=None)
@@ -767,6 +893,8 @@ def plannedsession_teamcreate_view(request,
"preferreddate","startdate","enddate")
sessiontemplates = PlannedSession.objects.filter(manager=request.user,is_template=True)
sessiontemplates2 = PlannedSession.objects.filter(is_template=True,is_public=True)
sessiontemplates = sessiontemplates | sessiontemplates2
if request.method == 'POST':
sessioncreateform = PlannedSessionForm(request.POST, request.FILES)
@@ -1668,7 +1796,9 @@ def plannedsession_templateedit_view(request,id=0):
elif cd['sessionunit'] in ['km','m']:
cd['sessionmode'] = 'distance'
obj = sessioncreateform.save()
obj = sessioncreateform.save(commit=False)
obj.save()
sessioncreateform.save_m2m()
res, message = update_plannedsession(ps,cd)
#sessioncreateform.save_m2m()
@@ -1705,6 +1835,11 @@ def plannedsession_templateedit_view(request,id=0):
]
sessiontemplates = PlannedSession.objects.filter(manager=request.user,is_template=True)
sessiontemplates2 = PlannedSession.objects.filter(
is_template=True,is_public=True
).order_by("name")
sessiontemplates = sessiontemplates | sessiontemplates2
return render(request,'plannedsessiontemplateedit.html',
{
@@ -1848,6 +1983,11 @@ def plannedsession_edit_view(request,id=0,userid=0):
sessiontemplates = PlannedSession.objects.filter(manager=request.user,is_template=True)
sessiontemplates2 = PlannedSession.objects.filter(
is_template=True,is_public=True
).order_by("name")
sessiontemplates = sessiontemplates | sessiontemplates2
dateform = DateRangeForm(initial={
'startdate':startdate,