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 shutil
|
||||
import requests
|
||||
|
||||
from rowingdata import trainingparser
|
||||
|
||||
@@ -1542,7 +1543,22 @@ class InstantPlan(models.Model):
|
||||
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 __str__(self):
|
||||
return self.name
|
||||
|
||||
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)
|
||||
|
||||
class InstantPlanForm(ModelForm):
|
||||
|
||||
@@ -9,10 +9,16 @@
|
||||
<h1>Training Plans</h1>
|
||||
|
||||
<ul class="main-content">
|
||||
{% for plan in trainingdict %}
|
||||
<li>
|
||||
<p><a href="/rowers/plans/{{ plan.ID }}">{{ plan.name }}</a></p>
|
||||
<p>{{ plan.plan|lookup:"duration"}}</p>
|
||||
{% for plan in plans %}
|
||||
<li class="rounder">
|
||||
<h2><a href="/rowers/plans/{{ plan.uuid }}">{{ plan.name }}</a></h2>
|
||||
<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>
|
||||
{% endfor %}
|
||||
{% if user.is_authenticated and user.is_staff %}
|
||||
|
||||
@@ -2508,7 +2508,7 @@ def add_instantplan_view(request):
|
||||
form = InstantPlanForm(request.POST,request.FILES)
|
||||
if form.is_valid():
|
||||
ip = form.save(commit=False)
|
||||
ip.manager = r.user
|
||||
ip.owner = r.user
|
||||
ip.save()
|
||||
|
||||
url = reverse(rower_select_instantplan)
|
||||
@@ -2553,17 +2553,7 @@ def rower_select_instantplan(request,id=0):
|
||||
themanager = getrower(request.user)
|
||||
|
||||
# get and present available plans
|
||||
authorizationstring = 'Bearer '+settings.WORKOUTS_FIT_TOKEN
|
||||
|
||||
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']
|
||||
ips = InstantPlan.objects.all().order_by("duration")
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
@@ -2587,7 +2577,7 @@ def rower_select_instantplan(request,id=0):
|
||||
{
|
||||
'rower':r,
|
||||
'active':'nav-plan',
|
||||
'trainingdict':trainingdict,
|
||||
'plans':ips,
|
||||
|
||||
})
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ from rowers.models import (
|
||||
PlannedSessionComment,CoachRequest,CoachOffer,
|
||||
VideoAnalysis,ShareKey,
|
||||
StandardCollection,CourseStandard,
|
||||
VirtualRaceFollower,TombStone
|
||||
VirtualRaceFollower,TombStone, InstantPlan
|
||||
)
|
||||
from rowers.models import (
|
||||
RowerPowerForm,RowerHRZonesForm,RowerForm,RowerCPForm,GraphImage,AdvancedWorkoutForm,
|
||||
|
||||
Reference in New Issue
Block a user