Merge branch 'feature/tojson' into develop
This commit is contained in:
+4
-1
@@ -8,7 +8,7 @@ from .models import (
|
||||
WorkoutComment, C2WorldClassAgePerformance, PlannedSession,
|
||||
GeoCourse, GeoPolygon, GeoPoint, VirtualRace, VirtualRaceResult,
|
||||
PaidPlan, IndoorVirtualRaceResult, ShareKey,
|
||||
CourseStandard, StandardCollection,
|
||||
CourseStandard, StandardCollection, InstantPlan,
|
||||
)
|
||||
|
||||
# Register your models here so you can use them in the Admin module
|
||||
@@ -165,6 +165,8 @@ class StandardCollectionAdmin(admin.ModelAdmin):
|
||||
class CourseStandardAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'standardcollection')
|
||||
|
||||
class InstantPlanAdmin(admin.ModelAdmin):
|
||||
list_display = ('name','duration','price')
|
||||
|
||||
admin.site.unregister(User)
|
||||
admin.site.register(User, UserAdmin)
|
||||
@@ -187,3 +189,4 @@ admin.site.register(PaidPlan, PaidPlanAdmin)
|
||||
admin.site.register(ShareKey, ShareKeyAdmin)
|
||||
admin.site.register(CourseStandard, CourseStandardAdmin)
|
||||
admin.site.register(StandardCollection, StandardCollectionAdmin)
|
||||
admin.site.register(InstantPlan, InstantPlanAdmin)
|
||||
|
||||
@@ -1050,7 +1050,6 @@ def get_workouts_session(r, ps):
|
||||
|
||||
return ws
|
||||
|
||||
|
||||
def create_sessions_from_json(plansteps, rower, startdate, manager):
|
||||
trainingdays = plansteps['trainingDays']
|
||||
planstartdate = startdate
|
||||
|
||||
@@ -154,6 +154,12 @@
|
||||
href="/rowers/sessions/sendcalendar/user/{{ rower.user.id }}/?when={{ timeperiod }}">
|
||||
Get Calendar File</a>
|
||||
|
||||
{% if user.is_authenticated and user.is_staff %}
|
||||
<a
|
||||
href="/rowers/sessions/saveasplan/user/{{ rower.user.id }}/?when={{ timeperiod }}">
|
||||
Save to YaML</a>
|
||||
|
||||
{% endif %}
|
||||
<a
|
||||
href="/rowers/plan/0/execution/?when={{ timeperiod }}/">
|
||||
Actual vs Plan chart
|
||||
|
||||
@@ -1055,6 +1055,10 @@ urlpatterns = [
|
||||
name='plannedsessions_coach_icsemail_view'),
|
||||
re_path(r'^sessions/sendcalendar/user/(?P<userid>\d+)/$', views.plannedsessions_icsemail_view,
|
||||
name='plannedsessions_icsemail_view'),
|
||||
re_path(r'^sessions/saveasplan/$', views.save_plan_yaml,
|
||||
name='save_plan_yaml'),
|
||||
re_path(r'^sessions/saveasplan/user/(?P<userid>\d+)/$', views.save_plan_yaml,
|
||||
name='save_plan_yaml'),
|
||||
re_path(r'^sessions/$', views.plannedsessions_view,
|
||||
name='plannedsessions_view'),
|
||||
re_path(r'^sessions/user/(?P<userid>\d+)/$', views.plannedsessions_view,
|
||||
|
||||
@@ -1375,6 +1375,55 @@ def plannedsessions_coach_view(request,
|
||||
}
|
||||
)
|
||||
|
||||
@login_required()
|
||||
def save_plan_yaml(request, userid=0):
|
||||
r = getrequestrower(request, userid=userid)
|
||||
startdate, enddate = get_dates_timeperiod(request)
|
||||
startdate = startdate.date()
|
||||
enddate = enddate.date()
|
||||
|
||||
duration = (enddate-startdate).days+1
|
||||
filename = 'myplan.yml'
|
||||
|
||||
plan = {
|
||||
'filename': filename,
|
||||
'name': 'Training Plan',
|
||||
'duration': duration,
|
||||
'description': 'My Training Plan',
|
||||
}
|
||||
|
||||
sps = get_sessions(r, startdate=startdate, enddate=enddate)
|
||||
|
||||
trainingdays = []
|
||||
|
||||
# add sessions to days
|
||||
for i in range(duration):
|
||||
dd = startdate+timedelta(days=i)
|
||||
workouts = []
|
||||
for ps in sps:
|
||||
if ps.preferreddate == dd:
|
||||
sessionsport = mytypes.fitmapping[ps.sessionsport].capitalize()
|
||||
steps = ps.steps
|
||||
steps['filename'] = ""
|
||||
workouts.append(steps)
|
||||
|
||||
trainingdays.append({'order': i+1, 'workouts': workouts})
|
||||
|
||||
plan['trainingDays'] = trainingdays
|
||||
|
||||
response = HttpResponse(yaml.dump(plan))
|
||||
|
||||
response['Content-Disposition'] = 'attachment; filename="training_plan_{u}_{d1}_{d2}.yml"'.format(
|
||||
u=request.user.username,
|
||||
d1=startdate.strftime("%Y%m%d"),
|
||||
d2=enddate.strftime("%Y%m%d"),
|
||||
)
|
||||
|
||||
response['Content-Type'] = 'application/octet-stream'
|
||||
|
||||
return response
|
||||
|
||||
|
||||
|
||||
@login_required()
|
||||
def plannedsessions_view(request,
|
||||
@@ -2530,11 +2579,15 @@ def rower_view_instantplan(request, id='', userid=0):
|
||||
|
||||
trainingdays = plansteps['trainingDays']
|
||||
|
||||
|
||||
|
||||
trainingdays2 = []
|
||||
nextday = trainingdays.pop(0)
|
||||
|
||||
for i in range(plansteps['duration']):
|
||||
if nextday['order'] == i+1:
|
||||
nextday['week'] = (divmod(i, 7)[0])+1
|
||||
|
||||
trainingdays2.append(nextday)
|
||||
try:
|
||||
nextday = trainingdays.pop(0)
|
||||
@@ -2549,6 +2602,7 @@ def rower_view_instantplan(request, id='', userid=0):
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
targets = TrainingTarget.objects.filter(
|
||||
rowers=r,
|
||||
date__gte=timezone.now(),
|
||||
|
||||
Reference in New Issue
Block a user