+ -
+
Create New Library Session
+
+
+
+ -
+
Library
+
+ Click on session name to clone to current period
+
+
+
+
+ | Name |
+ Value |
+ |
+ Edit |
+ Delete |
+
+
+
+ {% for ps in sessiontemplates %}
+
+ |
+ {% if ps.name != '' %}
+ {{ ps.name }}
+ {% else %}
+ Unnamed Session
+ {% endif %}
+ |
+ {{ ps.sessionvalue }} |
+ {{ ps.sessionunit }} |
+
+
+ |
+
+
+ |
+
+ {% endfor %}
+
+
+
+
+
+{% endblock %}
+
+{% block sidebar %}
+{% include 'menu_plan.html' %}
+{% endblock %}
+
+
+{% block scripts %}
+
+
+
+{% endblock %}
diff --git a/rowers/templates/templatelibrary.html b/rowers/templates/templatelibrary.html
index 3d3e702c..55754986 100644
--- a/rowers/templates/templatelibrary.html
+++ b/rowers/templates/templatelibrary.html
@@ -8,11 +8,26 @@
-
{% if templates %}
- Click on session name to view, edit to change the session.
+ Sharing a session makes it available to all Rowsandall users on Self-Coach and Coach plans, so they can
+ use it in their own training plans. You can make the session private again at any time, but users
+ can save your session in their own private libraries.
@@ -20,8 +35,13 @@
| Name |
Type |
Mode |
+ Value |
+ Private/Public |
Edit |
-
+ | Copy to Calendar |
+ Share |
+ Make Private |
+ Delete |
@@ -29,23 +49,56 @@
|
{% if ps.name != '' %}
- {{ ps.name }}
+ {{ ps.name }}
{% else %}
- Unnamed Session
+ Unnamed Session
{% endif %}
|
{{ ps.get_sessiontype_display }} |
{{ ps.get_sessionmode_display }} |
+ {{ ps.sessionvalue }} {{ ps.sessionunit }} |
+ {% if ps.is_public %}
+
+ {% else %}
+
+ {% endif %}
+ |
+
+ {% if ps.manager == request.user %}
+ {% endif %}
+ |
+
+
+
+
+ |
+
+ {% if ps.manager == request.user %}
+
+
+
+ {% endif %}
+ |
+
+ {% if ps.manager == request.user %}
+
+
+
+ {% endif %}
+ |
+
+ {% if ps.manager == request.user %}
+
+ {% endif %}
|
- {{ ps.sessionvalue }} |
- {{ ps.sessionunit }} |
{% endfor %}
@@ -55,6 +108,9 @@
{% endif %}
+ -
+ Add a session to the library
+
diff --git a/rowers/urls.py b/rowers/urls.py
index ed35a9fc..42aa1507 100644
--- a/rowers/urls.py
+++ b/rowers/urls.py
@@ -806,11 +806,17 @@ urlpatterns = [
name='plannedsession_teamcreate_view'),
re_path(r'^sessions/teamedit/(?P\d+)/$',views.plannedsession_teamedit_view,
name='plannedsession_teamedit_view'),
+ re_path(r'^sessions/(?P\d+)/share/$',views.template_share_view,
+ name='template_share_view'),
+ re_path(r'^sessions/(?P\d+)/makeprivate/$',views.template_makeprivate_view,
+ name='template_makeprivate_view'),
re_path(r'^sessions/teamedit/(?P\d+)/user/(?P\d+)/$',
views.plannedsession_teamedit_view,
name='plannedsession_teamedit_view'),
re_path(r'^sessions/create/$',views.plannedsession_create_view,
name='plannedsession_create_view'),
+ re_path(r'^sessions/createtemplate/$',views.plannedsession_createtemplate_view,
+ name='plannedsession_createtemplate_view'),
re_path(r'^sessions/create/user/(?P\d+)/$',
views.plannedsession_create_view,
name='plannedsession_create_view'),
diff --git a/rowers/views/planviews.py b/rowers/views/planviews.py
index 5499e562..39631db9 100644
--- a/rowers/views/planviews.py
+++ b/rowers/views/planviews.py
@@ -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,