untested - form to create new instant plan
This commit is contained in:
@@ -1535,12 +1535,28 @@ class InstantPlan(models.Model):
|
|||||||
uuid = models.UUIDField(primary_key=False,editable=True,default=uuid.uuid4)
|
uuid = models.UUIDField(primary_key=False,editable=True,default=uuid.uuid4)
|
||||||
owner = models.ForeignKey(User,on_delete=models.SET_NULL,null=True)
|
owner = models.ForeignKey(User,on_delete=models.SET_NULL,null=True)
|
||||||
name = models.CharField(max_length=150,blank=True)
|
name = models.CharField(max_length=150,blank=True)
|
||||||
goal = models.CharField(max_length=150,blank=True)
|
goal = models.CharField(max_length=150,blank=True,verbose_name="Goal (one sentence)")
|
||||||
description = models.TextField(max_length=300,blank=True)
|
description = models.TextField(max_length=450,blank=True)
|
||||||
duration = models.IntegerField(default=6)
|
duration = models.IntegerField(default=6,verbose_name='Duration in Calendar Days')
|
||||||
target = models.TextField(max_length=300,blank=True)
|
target = models.TextField(max_length=450,blank=True,verbose_name='What the plan will achieve')
|
||||||
hoursperweek = models.IntegerField(default=4)
|
hoursperweek = models.IntegerField(default=4,verbose_name='Hours Per Week')
|
||||||
|
yaml = models.FileField(upload_to=get_file_path,verbose_name="Plan YAML file",null=True,blank=True)
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
super(InstantPlan, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
class InstantPlanForm(ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = InstantPlan
|
||||||
|
fields = [
|
||||||
|
'name',
|
||||||
|
'goal',
|
||||||
|
'description',
|
||||||
|
'duration',
|
||||||
|
'target',
|
||||||
|
'hoursperweek',
|
||||||
|
'yaml',
|
||||||
|
]
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class TrainingPlan(models.Model):
|
class TrainingPlan(models.Model):
|
||||||
|
|||||||
32
rowers/templates/add_instantplan.html
Normal file
32
rowers/templates/add_instantplan.html
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{% extends "newbase.html" %}
|
||||||
|
{% load staticfiles %}
|
||||||
|
{% load rowerfilters %}
|
||||||
|
|
||||||
|
{% block title %}Add Instant Plan{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block main %}
|
||||||
|
<h1>{{ plan.name }}</h1>
|
||||||
|
|
||||||
|
<ul class="main-content">
|
||||||
|
<li class="grid_4">
|
||||||
|
<form enctype="multipart/form-data" action="" method="post">
|
||||||
|
{% if form.errors %}
|
||||||
|
<p style="color: red;">
|
||||||
|
Please correct the error{{ form.errors|pluralize }} below.
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
<table>
|
||||||
|
{{ form.as_table }}
|
||||||
|
</table>
|
||||||
|
{% csrf_token %}
|
||||||
|
<p><input class="button" type="submit" value="Save"></p>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
{% include 'menu_plan.html' %}
|
||||||
|
{% endblock %}
|
||||||
@@ -15,6 +15,11 @@
|
|||||||
<p>{{ plan.plan|lookup:"duration"}}</p>
|
<p>{{ plan.plan|lookup:"duration"}}</p>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if user.is_authenticated and user.is_staff %}
|
||||||
|
<li class="grid_4">
|
||||||
|
<a href="/rowers/addinstantplan/">Add a New Training Plan</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -743,6 +743,7 @@ urlpatterns = [
|
|||||||
re_path(r'^plans/$', views.rower_select_instantplan, name='rower_select_instantplan'),
|
re_path(r'^plans/$', views.rower_select_instantplan, name='rower_select_instantplan'),
|
||||||
re_path(r'^plans/(?P<id>[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})/$',
|
re_path(r'^plans/(?P<id>[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})/$',
|
||||||
views.rower_view_instantplan, name='rower_view_instantplan'),
|
views.rower_view_instantplan, name='rower_view_instantplan'),
|
||||||
|
re_path(r'^addinstantplan/$', views.add_instantplan_view, name='add_instantplan_view'),
|
||||||
re_path(r'^deleteplan/(?P<pk>\d+)/$',login_required(
|
re_path(r'^deleteplan/(?P<pk>\d+)/$',login_required(
|
||||||
views.TrainingPlanDelete.as_view()),name='trainingplan_delete_view'),
|
views.TrainingPlanDelete.as_view()),name='trainingplan_delete_view'),
|
||||||
re_path(r'^deletemicrocycle/(?P<pk>\d+)/$',login_required(
|
re_path(r'^deletemicrocycle/(?P<pk>\d+)/$',login_required(
|
||||||
|
|||||||
@@ -2497,6 +2497,54 @@ def rower_view_instantplan(request,id='',userid=0):
|
|||||||
'trainingdays':trainingdays2,
|
'trainingdays':trainingdays2,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@login_required()
|
||||||
|
def add_instantplan_view(request):
|
||||||
|
if not request.user.is_staff:
|
||||||
|
raise PermissionDenied("Not Allowed")
|
||||||
|
|
||||||
|
r = getrequestrower(request)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
form = InstantPlanForm(request.POST,request.FILES)
|
||||||
|
if form.is_valid():
|
||||||
|
ip = form.save(commit=False)
|
||||||
|
ip.manager = r.user
|
||||||
|
ip.save()
|
||||||
|
|
||||||
|
url = reverse(rower_select_instantplan)
|
||||||
|
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
else:
|
||||||
|
form = InstantPlanForm()
|
||||||
|
|
||||||
|
breadcrumbs = [
|
||||||
|
{
|
||||||
|
'url':reverse('plannedsessions_view'),
|
||||||
|
'name': 'Sessions'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url':reverse(rower_create_trainingplan),
|
||||||
|
'name': 'Manage Plans and Targets'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url':reverse('rower_select_instantplan'),
|
||||||
|
'name': 'Select Existing Plans'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'url': reverse(add_instantplan_view),
|
||||||
|
'name': 'Add New Instant Plan'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
return render(request,'add_instantplan.html',
|
||||||
|
{
|
||||||
|
'form':form,
|
||||||
|
'rower':r,
|
||||||
|
'active':'nav-plan',
|
||||||
|
'breadcrumbs':breadcrumbs,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
@user_passes_test(can_plan,login_url="/rowers/paidplans",
|
@user_passes_test(can_plan,login_url="/rowers/paidplans",
|
||||||
message="This functionality requires a Coach or Self-Coach plan",
|
message="This functionality requires a Coach or Self-Coach plan",
|
||||||
redirect_field_name=None)
|
redirect_field_name=None)
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ from rowers.models import (
|
|||||||
IndoorVirtualRaceResultForm,IndoorVirtualRaceResult,
|
IndoorVirtualRaceResultForm,IndoorVirtualRaceResult,
|
||||||
IndoorVirtualRaceForm,PlannedSessionCommentForm,
|
IndoorVirtualRaceForm,PlannedSessionCommentForm,
|
||||||
Alert, Condition, StaticChartRowerForm,
|
Alert, Condition, StaticChartRowerForm,
|
||||||
FollowerForm,VirtualRaceAthleteForm,
|
FollowerForm,VirtualRaceAthleteForm,InstantPlanForm,
|
||||||
)
|
)
|
||||||
from rowers.models import (
|
from rowers.models import (
|
||||||
FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement,BasePlannedSessionFormSet,
|
FavoriteForm,BaseFavoriteFormSet,SiteAnnouncement,BasePlannedSessionFormSet,
|
||||||
|
|||||||
Reference in New Issue
Block a user