Private
Public Access
1
0

unfinished, untested

This commit is contained in:
Sander Roosendaal
2021-12-01 19:46:11 +01:00
parent 81ba5dc6ae
commit 5dbde8b744
2 changed files with 40 additions and 1 deletions

View File

@@ -29,6 +29,10 @@
{% if workouts %}
<li class="grid_4">
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
<input name='workouts' type="submit" value="Import selected workouts">
<a href="/rowers/workout/nkimport/?selectallnew=true">Select All New</a>
<table width="70%" class="listtable">
<thead>
<tr>
@@ -44,7 +48,12 @@
{% for workout in workouts %}
<tr>
<td>
<a href="/rowers/workout/nkimport/{{ workout|lookup:'id' }}/async/">Import</a></td>
{% if workout|lookup:'new' == 'NEW' and checknew == 'true' %}
<input checked type="checkbox" value={{ workout|lookup:'id' }} name="workoutid">
{% else %}
<input type="checkbox" value={{ workout|lookup:'id' }} name="workoutid">
{% endif %}
</td>
<td>{{ workout|lookuplong:'name' }}</td>
<td class="block" style="width:auto">{{ workout|lookuplong:'starttime' }}</td>
<td>{{ workout|lookup:'duration' }} </td>
@@ -55,6 +64,7 @@
{% endfor %}
</tbody>
</table>
</form>
</li>
{% else %}
<li class="grid_4">

View File

@@ -637,6 +637,35 @@ def workout_nkimport_view(request,userid=0,after=0,before=0):
workouts = workouts[::-1]
if request.method == 'POST':
try:
tdict = dict(request.POST.lists())
ids = tdict['workoutid']
nkids = [int(id) for id in ids]
alldata = {}
for item in res.json()['data']:
alldata[item['id']] = item
counter = 0
for nkid in nkids:
csvfilename = 'media/{code}_{nkid}.csv'.format(code=uuid4().hex[:16],nkid=nkid)
result = myqueue(
queue,
handle_nk_async_workout,
alldata,
r.user.id,
r.nktoken,
nkid,
counter,
r.defaulttimezone
)
counter = counter+1
messages.info(request,'Your NK logbook workouts will be imported in the background. It may take a few minutes before it appears.'.format(c2id=c2id))
url = reverse('workouts_view')
return HttpResponseRedirect(url)
except KeyError:
pass
breadcrumbs = [
{
'url':'/rowers/list-workouts/',