can now create new instantplan
This commit is contained in:
@@ -32,6 +32,7 @@ from scipy.interpolate import splprep, splev, CubicSpline,interp1d
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
import requests
|
||||||
|
|
||||||
from rowingdata import trainingparser
|
from rowingdata import trainingparser
|
||||||
|
|
||||||
@@ -1542,7 +1543,22 @@ class InstantPlan(models.Model):
|
|||||||
hoursperweek = models.IntegerField(default=4,verbose_name='Hours Per Week')
|
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)
|
yaml = models.FileField(upload_to=get_file_path,verbose_name="Plan YAML file",null=True,blank=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
yamltext = self.yaml.read()
|
||||||
|
|
||||||
|
authorizationstring = 'Bearer '+settings.WORKOUTS_FIT_TOKEN
|
||||||
|
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"
|
||||||
|
headers = {'Authorization':authorizationstring}
|
||||||
|
response = requests.post(url=url,headers=headers,data=yamltext)
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
self.yaml.name = data['filename']
|
||||||
|
self.uuid = data['ID']
|
||||||
|
self.name = data['name']
|
||||||
|
self.yaml = None
|
||||||
super(InstantPlan, self).save(*args, **kwargs)
|
super(InstantPlan, self).save(*args, **kwargs)
|
||||||
|
|
||||||
class InstantPlanForm(ModelForm):
|
class InstantPlanForm(ModelForm):
|
||||||
|
|||||||
@@ -9,10 +9,16 @@
|
|||||||
<h1>Training Plans</h1>
|
<h1>Training Plans</h1>
|
||||||
|
|
||||||
<ul class="main-content">
|
<ul class="main-content">
|
||||||
{% for plan in trainingdict %}
|
{% for plan in plans %}
|
||||||
<li>
|
<li class="rounder">
|
||||||
<p><a href="/rowers/plans/{{ plan.ID }}">{{ plan.name }}</a></p>
|
<h2><a href="/rowers/plans/{{ plan.uuid }}">{{ plan.name }}</a></h2>
|
||||||
<p>{{ plan.plan|lookup:"duration"}}</p>
|
<p>Created by: {{ plan.owner.first_name }} {{ plan.owner.last_name }}</p>
|
||||||
|
<p>Plan length: {{ plan.duration }} days</p>
|
||||||
|
<p>{{ plan.description }}</p>
|
||||||
|
<p>{{ plan.target }}</p>
|
||||||
|
<p>Goal: {{ plan.goal }}</p>
|
||||||
|
<p>{{ plan.hoursperweek }} hours per week</p>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if user.is_authenticated and user.is_staff %}
|
{% if user.is_authenticated and user.is_staff %}
|
||||||
|
|||||||
@@ -2508,7 +2508,7 @@ def add_instantplan_view(request):
|
|||||||
form = InstantPlanForm(request.POST,request.FILES)
|
form = InstantPlanForm(request.POST,request.FILES)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
ip = form.save(commit=False)
|
ip = form.save(commit=False)
|
||||||
ip.manager = r.user
|
ip.owner = r.user
|
||||||
ip.save()
|
ip.save()
|
||||||
|
|
||||||
url = reverse(rower_select_instantplan)
|
url = reverse(rower_select_instantplan)
|
||||||
@@ -2553,17 +2553,7 @@ def rower_select_instantplan(request,id=0):
|
|||||||
themanager = getrower(request.user)
|
themanager = getrower(request.user)
|
||||||
|
|
||||||
# get and present available plans
|
# get and present available plans
|
||||||
authorizationstring = 'Bearer '+settings.WORKOUTS_FIT_TOKEN
|
ips = InstantPlan.objects.all().order_by("duration")
|
||||||
|
|
||||||
url = settings.WORKOUTS_FIT_URL+"/trainingplan/"
|
|
||||||
headers = {'Authorization':authorizationstring}
|
|
||||||
|
|
||||||
trainingdict = {}
|
|
||||||
response = requests.get(url=url, headers=headers)
|
|
||||||
if response.status_code != 200:
|
|
||||||
messages.error(request,"Could not connect to the training plan server")
|
|
||||||
else:
|
|
||||||
trainingdict = response.json()['plans']
|
|
||||||
|
|
||||||
breadcrumbs = [
|
breadcrumbs = [
|
||||||
{
|
{
|
||||||
@@ -2587,7 +2577,7 @@ def rower_select_instantplan(request,id=0):
|
|||||||
{
|
{
|
||||||
'rower':r,
|
'rower':r,
|
||||||
'active':'nav-plan',
|
'active':'nav-plan',
|
||||||
'trainingdict':trainingdict,
|
'plans':ips,
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ from rowers.models import (
|
|||||||
PlannedSessionComment,CoachRequest,CoachOffer,
|
PlannedSessionComment,CoachRequest,CoachOffer,
|
||||||
VideoAnalysis,ShareKey,
|
VideoAnalysis,ShareKey,
|
||||||
StandardCollection,CourseStandard,
|
StandardCollection,CourseStandard,
|
||||||
VirtualRaceFollower,TombStone
|
VirtualRaceFollower,TombStone, InstantPlan
|
||||||
)
|
)
|
||||||
from rowers.models import (
|
from rowers.models import (
|
||||||
RowerPowerForm,RowerHRZonesForm,RowerForm,RowerCPForm,GraphImage,AdvancedWorkoutForm,
|
RowerPowerForm,RowerHRZonesForm,RowerForm,RowerCPForm,GraphImage,AdvancedWorkoutForm,
|
||||||
|
|||||||
Reference in New Issue
Block a user