adding export form
This commit is contained in:
@@ -1267,11 +1267,24 @@ class ForceCurveMultipleCompareForm(forms.Form):
|
||||
|
||||
bulkactions = (
|
||||
('remove','remove'),
|
||||
('export','export'),
|
||||
)
|
||||
destinations = (
|
||||
('C2','C2'),
|
||||
('strava','strava'),
|
||||
('sporttracks','sporttracks'),
|
||||
('trainingpeaks','trainingpeaks')
|
||||
)
|
||||
|
||||
class WorkoutBulkActions(forms.Form):
|
||||
action = forms.ChoiceField(
|
||||
choices=bulkactions, label='Action', required=True, initial='remove')
|
||||
|
||||
class ExportChoices(forms.Form):
|
||||
destination = forms.ChoiceField(
|
||||
choices=destinations, label='Destination', required=False, initial='strava'
|
||||
)
|
||||
|
||||
class WorkoutMultipleCompareForm(forms.Form):
|
||||
workouts = forms.ModelMultipleChoiceField(
|
||||
queryset=Workout.objects.filter(),
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
<p>
|
||||
{{ actionform.as_p }}
|
||||
</p>
|
||||
{% if action == 'export' %}
|
||||
<p>
|
||||
{{ exportchoice.as_p }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</li>
|
||||
<li class="grid_2">
|
||||
{% csrf_token %}
|
||||
|
||||
@@ -96,7 +96,7 @@ from django.http import (
|
||||
)
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from rowers.forms import (
|
||||
WorkoutBulkActions,
|
||||
WorkoutBulkActions, ExportChoices,
|
||||
ForceCurveOptionsForm, HistoForm, TeamMessageForm,
|
||||
LoginForm, DocumentsForm, UploadOptionsForm, ImageForm, CourseForm,
|
||||
CourseConfirmForm, ResampleForm,
|
||||
|
||||
@@ -2,6 +2,7 @@ from shutil import copyfile
|
||||
from rowers.views.statements import *
|
||||
|
||||
import rowers.mytypes as mytypes
|
||||
from rowers.integrations import importsources
|
||||
import numpy
|
||||
import rowers.uploads as uploads
|
||||
import rowers.utils as utils
|
||||
@@ -2056,10 +2057,24 @@ def workouts_bulk_actions(request):
|
||||
for w in workouts:
|
||||
messages.info(request,'Removed workout '+str(encoder.encode_hex(w.id)))
|
||||
w.delete()
|
||||
elif action == 'export':
|
||||
exportchoice = ExportChoices(request.POST)
|
||||
if exportchoice.is_valid():
|
||||
destination = exportchoice.cleaned_data['destination']
|
||||
for w in workouts:
|
||||
integration = importsources[destination](request.user)
|
||||
try:
|
||||
id = integration.workout_export(w)
|
||||
messages.info(request,'Workout {id} exported to {destination}'.format(id=encoder.encode_hex(w.id),
|
||||
destination=destination))
|
||||
except NoTokenError:
|
||||
messages.error(request,'Export to {destination} of workout {id} failed'.format(id=encoder.encode_hex(w.id),
|
||||
destination=destination))
|
||||
url = reverse('workouts_view')
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
else:
|
||||
exportchoice = ExportChoices()
|
||||
actionform = WorkoutBulkActions()
|
||||
actionform.fields["action"].initial = action
|
||||
form = WorkoutMultipleCompareForm()
|
||||
@@ -2069,6 +2084,7 @@ def workouts_bulk_actions(request):
|
||||
|
||||
return render(request,'workout_bulk_actions.html',
|
||||
{'action':action,
|
||||
'exportchoice':exportchoice,
|
||||
'actionform':actionform,
|
||||
'form':form,
|
||||
'workouts':workouts})
|
||||
|
||||
Reference in New Issue
Block a user