Private
Public Access
1
0

workout_view

This commit is contained in:
Sander Roosendaal
2018-10-09 10:44:35 +02:00
parent 864ea2883d
commit ffa523851e
3 changed files with 164 additions and 229 deletions

View File

@@ -6,7 +6,7 @@
{% block title %}Change Workout {% endblock %} {% block title %}Change Workout {% endblock %}
{% block main %} {% block main %}
<h1>Edit Workout Interval Data</h1> <h1>Split Workout</h1>
{% localtime on %} {% localtime on %}
<ul class="main-content"> <ul class="main-content">

View File

@@ -1,4 +1,4 @@
{% extends "base.html" %} {% extends "newbase.html" %}
{% load staticfiles %} {% load staticfiles %}
{% load rowerfilters %} {% load rowerfilters %}
{% block scripts %} {% block scripts %}
@@ -16,183 +16,117 @@
{% for graph in graphs1 %} {% for graph in graphs1 %}
{% block og_image %} {% block og_image %}
{% if graphs1 %} {% if graphs1 %}
{% for graph in graphs1 %} {% for graph in graphs %}
<meta property="og:image" content="http://rowsandall.com/{{ graph.filename |spacetohtml }}" /> <meta property="og:image" content="http://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" /> <meta property="og:image:secure_url" content="https://rowsandall.com/{{ graph.filename |spacetohtml }}" />
<meta property="og:image:width" content="{{ graph.width }}" /> <meta property="og:image:width" content="{{ graph.width }}" />
<meta property="og:image:height" content="{{ graph.height }}" /> <meta property="og:image:height" content="{{ graph.height }}" />
{% endfor %} {% endfor %}
{% else %} {% else %}
<meta property="og:image" content="http://rowsandall.com/static/img/logo_r.png" /> <meta property="og:image" content="http://rowsandall.com/static/img/logo_r.png" />
<meta property="og:image:secure_url" content="https://rowsandall.com/static/img/logo_r.png" /> <meta property="og:image:secure_url" content="https://rowsandall.com/static/img/logo_r.png" />
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block image_src %} {% block image_src %}
{% for graph in graphs1 %} {% for graph in graphs %}
<link rel="image_src" href="/{{ graph.filename |spacetohtml }}" /> <link rel="image_src" href="/{{ graph.filename |spacetohtml }}" />
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
{% endfor %} {% endfor %}
{% block content %} {% block main %}
<div id="workouts" class="grid_6 alpha">
<h1>{{ workout.name }}</h1>
<h1>{{ workout.name }}</h1> <ul class="main-content">
<div class="grid_1 alpha"> <li class="grid_2">
<div class="fb-share-button" data-href="https://rowsandall.com/rowers/workout/{{ workout.id }}" data-layout="button" data-size="small" data-mobile-iframe="false"> <p>
<a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https://rowsandall.com/rowers/workout/{{ workout.id }}">Share</a></div> <div class="fb-share-button"
</div> data-href="https://rowsandall.com/rowers/workout/{{ workout.id }}"
<div class="grid_1"> data-layout="button" data-size="small" data-mobile-iframe="false">
<a class="twitter-share-button" <a class="fb-xfbml-parse-ignore" target="_blank"
href="https://twitter.com/intent/tweet" href="https://www.facebook.com/sharer/sharer.php?u=https://rowsandall.com/rowers/workout/{{ workout.id }}">
data-url="https://rowsandall.com/rowers/workout/{{ workout.id }}" Share
data-text="@rowsandall #rowingdata">Tweet</a> </a>
</div> </div>
</p>
<table width=100%> <p>
<tr> <a class="twitter-share-button"
href="https://twitter.com/intent/tweet"
data-url="https://rowsandall.com/rowers/workout/{{ workout.id }}"
data-text="@rowsandall #rowingdata">Tweet</a>
</p>
<table width=100%>
<tr>
<th>Rower:</th><td>{{ first_name }} {{ last_name }}</td> <th>Rower:</th><td>{{ first_name }} {{ last_name }}</td>
</tr><tr> </tr><tr>
<tr> <tr>
<th>Name:</th><td>{{ workout.name }}</td> <th>Name:</th><td>{{ workout.name }}</td>
</tr><tr> </tr><tr>
<tr> <tr>
<th>Date:</th><td>{{ workout.date }}</td> <th>Date:</th><td>{{ workout.date }}</td>
</tr><tr> </tr><tr>
<th>Time:</th><td>{{ workout.starttime }}</td> <th>Time:</th><td>{{ workout.starttime }}</td>
</tr><tr> </tr><tr>
<th>Distance:</th><td>{{ workout.distance }}m</td> <th>Distance:</th><td>{{ workout.distance }}m</td>
</tr><tr> </tr><tr>
<th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td> <th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
</tr><tr> </tr><tr>
<th>Type:</th><td>{{ workout.workouttype }}</td> <th>Type:</th><td>{{ workout.workouttype }}</td>
</tr><tr> </tr><tr>
<th>Weight Category:</th><td>{{ workout.weightcategory }}</td> <th>Weight Category:</th><td>{{ workout.weightcategory }}</td>
</tr> </tr>
{% if user.is_authenticated %} {% if user.is_authenticated %}
<tr> <tr>
<th>Comments</th> <th>Comments</th>
<td> <td>
<a href="/rowers/workout/{{ workout.id }}/comment">Comment ({{ aantalcomments }})</a> <a href="/rowers/workout/{{ workout.id }}/comment">Comment ({{ aantalcomments }})</a>
</td> </td>
</tr> </tr>
{% endif %} {% endif %}
</table> </table>
</li>
<h1>Workout Summary</h1> <li class="grid_2">
<h1>Workout Summary</h1>
<p>
<pre>
{{ workout.summary }}
</pre>
</p>
<p>
<pre>
{{ workout.summary }}
</pre>
</p>
</li>
<li class="grid_2">
<div class="mapdiv">
{{ mapdiv|safe }} {{ mapdiv|safe }}
{{ mapscript|safe }} {{ mapscript|safe }}
</div>
</div> </li>
<div id="images" class="grid_6 omega"> <li class="grid_2">
<script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
<h1>Images linked to this workout</h1> <script async="true" type="text/javascript">
{% if graphs1 %} Bokeh.set_log_level("info");
{% for graph in graphs1 %}
{% if forloop.counter == 1 %}
<div id="thumb-container" class="grid_2 alpha">
<a href="/rowers/graph/{{ graph.id }}/">
<img src="/{{ graph.filename }}"
onerror="this.src='/static/img/rowingtimer.gif'"
alt="{{ graph.filename }}" width="120" height="100"></a>
</div>
{% elif forloop.counter == 3 %}
<div id="thumb-container" class="grid_2 omega">
<a href="/rowers/graph/{{ graph.id }}/">
<img src="/{{ graph.filename }}"
onerror="this.src='/static/img/rowingtimer.gif'"
alt="{{ graph.filename }}" width="120" height="100"></a>
</div>
{% else %}
<div id="thumb-container" class="grid_2">
<a href="/rowers/graph/{{ graph.id }}/">
<img src="/{{ graph.filename }}"
onerror="this.src='/static/img/rowingtimer.gif'"
alt="{{ graph.filename }}" width="120" height="100"></a>
</div>
{% endif %}
{% endfor %}
{% for graph in graphs2 %}
{% if forloop.counter == 1 %}
<div id="thumb-container" class="grid_2 alpha">
<a href="/rowers/graph/{{ graph.id }}/">
<img src="/{{ graph.filename }}"
onerror="this.src='/static/img/rowingtimer.gif'"
alt="{{ graph.filename }}" width="120" height="100"></a>
</div>
{% elif forloop.counter == 3 %}
<div id="thumb-container" class="grid_2 omega">
<a href="/rowers/graph/{{ graph.id }}/">
<img src="/{{ graph.filename }}"
onerror="this.src='/static/img/rowingtimer.gif'"
alt="{{ graph.filename }}" width="120" height="100"></a>
</div>
{% else %}
<div id="thumb-container" class="grid_2">
<a href="/rowers/graph/{{ graph.id }}/">
<img src="/{{ graph.filename }}"
onerror="this.src='/static/img/rowingtimer.gif'"
alt="{{ graph.filename }}" width="120" height="100"></a>
</div>
{% endif %}
{% endfor %}
{% else %}
<p> No graphs found </p>
{% endif %}
</div>
<script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
<script async="true" type="text/javascript">
Bokeh.set_log_level("info");
</script>
{{ interactiveplot |safe }}
<script>
// Set things up to resize the plot on a window resize. You can play with
// the arguments of resize_width_height() to change the plot's behavior.
var plot_resize_setup = function () {
var plotid = Object.keys(Bokeh.index)[0]; // assume we have just one plot
var plot = Bokeh.index[plotid];
var plotresizer = function() {
// arguments: use width, use height, maintain aspect ratio
plot.resize_width_height(true, true, true);
};
window.addEventListener('resize', plotresizer);
plotresizer();
};
window.addEventListener('load', plot_resize_setup);
</script> </script>
<style>
/* Need this to get the page in "desktop mode"; not having an infinite height.*/ {{ interactiveplot |safe }}
html, body {height: 100%; margin:5px;}
</style>
<div id="interactiveplot" class="grid_6 omega">
{{ the_div|safe }} {{ the_div|safe }}
</div> </li>
{% for graph in graphs %}
<li>
<a href="/rowers/graph/{{ graph.id }}/">
<img src="/{{ graph.filename }}"
onerror="this.src='/static/img/rowingtimer.gif'"
alt="{{ graph.filename }}" width="120" height="100">
</a>
</li>
{% endfor %}
</ul>
{% endblock %} {% endblock %}
{% block sidebar %}
{% include 'menu_workout.html' %}
{% endblock %}

View File

@@ -6596,99 +6596,100 @@ def workout_fusion_list(request,id=0,message='',successmessage='',
except Rower.DoesNotExist: except Rower.DoesNotExist:
raise Http404("User has no rower instance") raise Http404("User has no rower instance")
# Basic 'EDIT' view of workout # Basic view of workout
def workout_view(request,id=0): def workout_view(request,id=0):
request.session['referer'] = absolute(request)['PATH'] request.session['referer'] = absolute(request)['PATH']
try: if not request.user.is_anonymous():
# check if valid ID exists (workout exists) rower = getrower(request.user)
row = Workout.objects.get(id=id) else:
comments = WorkoutComment.objects.filter(workout=row) rower = None
aantalcomments = len(comments)
if row.privacy == 'private':
raise PermissionDenied("Access denied")
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime") try:
for i in g: row = Workout.objects.get(id=id)
try: except Workout.DoesNotExist:
width,height = Image.open(i.filename).size raise Http404("Workout doesn't exist")
i.width = width
i.height = height comments = WorkoutComment.objects.filter(workout=row)
i.save()
except: aantalcomments = len(comments)
pass
if row.privacy == 'private' and not checkworkoutuser(request.user,row):
raise PermissionDenied("Access denied")
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
for i in g:
try:
width,height = Image.open(i.filename).size
i.width = width
i.height = height
i.save()
except:
pass
r = Rower.objects.get(id=row.user.id)
u = User.objects.get(id=r.user.id)
# create interactive plot # create interactive plot
res = interactive_chart(id) res = interactive_chart(id)
script = res[0] script = res[0]
div = res[1] div = res[1]
# create map # create map
f1 = row.csvfilename f1 = row.csvfilename
u = row.user.user rowdata = rdata(f1)
r = getrower(u) hascoordinates = 1
rowdata = rdata(f1) if rowdata != 0:
hascoordinates = 1 try:
if rowdata != 0: latitude = rowdata.df[' latitude']
try: if not latitude.std():
latitude = rowdata.df[' latitude']
if not latitude.std():
hascoordinates = 0
except KeyError,AttributeError:
hascoordinates = 0 hascoordinates = 0
except KeyError,AttributeError:
else:
hascoordinates = 0 hascoordinates = 0
else:
hascoordinates = 0
if hascoordinates:
mapscript,mapdiv = leaflet_chart(rowdata.df[' latitude'], if hascoordinates:
rowdata.df[' longitude'], mapscript,mapdiv = leaflet_chart(rowdata.df[' latitude'],
row.name) rowdata.df[' longitude'],
row.name)
else: else:
mapscript = "" mapscript = ""
mapdiv = "" mapdiv = ""
breadcrumbs = [
# render page {
if (len(g)<=3): 'url':'/rowers/list-workouts',
return render(request, 'workout_view.html', 'name':'Workouts'
{'workout':row, },
'graphs1':g[0:3], {
'last_name':u.last_name, 'url':reverse(workout_view,kwargs={'id':id}),
'first_name':u.first_name, 'name': id,
'interactiveplot':script, }
'aantalcomments':aantalcomments,
'mapscript':mapscript, ]
'mapdiv':mapdiv,
'teams':get_my_teams(request.user),
'the_div':div})
else:
return render(request, 'workout_view.html',
{'workout':row,
'graphs1':g[0:3],
'graphs2':g[3:6],
'last_name':u.last_name,
'first_name':u.first_name,
'teams':get_my_teams(request.user),
'aantalcomments':aantalcomments,
'mapscript':mapscript,
'mapdiv':mapdiv,
'interactiveplot':script,
'the_div':div})
u = row.user.user
except Workout.DoesNotExist:
raise Http404("Workout doesn't exist") return render(request, 'workout_view.html',
{'workout':row,
'rower':rower,
'breadcrumbs':breadcrumbs,
'active':'nav-workouts',
'graphs':g,
'last_name':u.last_name,
'first_name':u.first_name,
'interactiveplot':script,
'aantalcomments':aantalcomments,
'mapscript':mapscript,
'mapdiv':mapdiv,
'teams':get_my_teams(request.user),
'the_div':div})
# Resets stroke data to raw data (pace) # Resets stroke data to raw data (pace)
@user_passes_test(ispromember,login_url="/",redirect_field_name=None) @user_passes_test(ispromember,login_url="/",redirect_field_name=None)