adding bulk action assign rowers
This commit is contained in:
@@ -1213,6 +1213,7 @@ class ForceCurveMultipleCompareForm(forms.Form):
|
||||
bulkactions = (
|
||||
('remove','remove'),
|
||||
('export','export'),
|
||||
('rower assign','rower assign'),
|
||||
)
|
||||
destinations = (
|
||||
('C2','C2'),
|
||||
@@ -1230,6 +1231,15 @@ class ExportChoices(forms.Form):
|
||||
choices=destinations, label='Destination', required=False, initial='strava'
|
||||
)
|
||||
|
||||
class AssignChoices(forms.Form):
|
||||
remove_workout = forms.BooleanField(initial=False, required=False)
|
||||
destination = forms.ModelMultipleChoiceField(label='Rowers', required=False,
|
||||
queryset=Rower.objects.filter(), widget=forms.CheckboxSelectMultiple())
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(AssignChoices, self).__init__(*args, **kwargs)
|
||||
self.fields['destination'].queryset = Rower.objects.filter()
|
||||
|
||||
class WorkoutMultipleCompareForm(forms.Form):
|
||||
workouts = forms.ModelMultipleChoiceField(
|
||||
queryset=Workout.objects.filter(),
|
||||
|
||||
@@ -324,6 +324,50 @@ def summaryfromsplitdata(splitdata, data, filename, sep='|', workouttype='rower'
|
||||
|
||||
return sums, sa, results
|
||||
|
||||
@app.task
|
||||
def handle_assignworkouts(workouts, rowers, remove_workout, debug=False, **kwargs):
|
||||
for workout in workouts:
|
||||
uploadoptions = {
|
||||
'secret': UPLOAD_SERVICE_SECRET,
|
||||
'title': workout.name,
|
||||
'boattype': workout.boattype,
|
||||
'workouttype': workout.workouttype,
|
||||
'inboard': workout.inboard,
|
||||
'oarlength': workout.oarlength,
|
||||
'summary': workout.summary,
|
||||
'elapsedTime': 3600.*workout.duration.hour+60*workout.duration.minute+workout.duration.second,
|
||||
'totalDistance': workout.distance,
|
||||
'useImpeller': workout.impeller,
|
||||
'seatNumber': workout.seatnumber,
|
||||
'boatName': workout.boatname,
|
||||
'portStarboard': workout.empowerside,
|
||||
}
|
||||
for rower in rowers:
|
||||
failed = False
|
||||
csvfilename = 'media/{code}.csv'.format(code=uuid4().hex[:16])
|
||||
try:
|
||||
with open(csvfilename,'wb') as f:
|
||||
shutil.copy(workout.csvfilename,csvfilename)
|
||||
except FileNotFoundError:
|
||||
try:
|
||||
with open(csvfilename,'wb') as f:
|
||||
csvfilename = csvfilename+'.gz'
|
||||
shutil.copy(workout.csvfilename+'.gz', csvfilename)
|
||||
except:
|
||||
failed = True
|
||||
if not failed:
|
||||
uploadoptions['user'] = rower.user.id
|
||||
uploadoptions['file'] = csvfilename
|
||||
session = requests.session()
|
||||
newHeaders = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||
session.headers.update(newHeaders)
|
||||
response = session.post(UPLOAD_SERVICE_URL, json=uploadoptions)
|
||||
print(response.text)
|
||||
if remove_workout:
|
||||
workout.delete()
|
||||
|
||||
return 1
|
||||
|
||||
@app.task
|
||||
def handle_post_workout_api(uploadoptions, debug=False, **kwargs): # pragma: no cover
|
||||
session = requests.session()
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
{{ exportchoice.as_p }}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if action == 'rower assign' %}
|
||||
<p>
|
||||
{{ assignchoices.as_p }}
|
||||
</p>
|
||||
{% endif %}
|
||||
</li>
|
||||
<li class="grid_2">
|
||||
{% csrf_token %}
|
||||
|
||||
@@ -770,7 +770,7 @@ def team_rowers(user): # pragma: no cover
|
||||
teams = Team.objects.filter(manager=user)
|
||||
members = Rower.objects.filter(
|
||||
team__in=teams).distinct().order_by(
|
||||
"user__last_name", "user__last_name").exclude(
|
||||
"user__last_name", "user__first_name").exclude(
|
||||
rowerplan='freecoach')
|
||||
return members
|
||||
except TypeError:
|
||||
|
||||
@@ -116,7 +116,8 @@ from rowers.forms import (
|
||||
StravaChartForm, FitnessFitForm, PerformanceManagerForm,
|
||||
TrainingPlanBillingForm, InstantPlanSelectForm,
|
||||
TrainingZonesForm, InstrokeForm, InStrokeMultipleCompareForm,
|
||||
ForceCurveMultipleCompareForm, PlanByRscoreForm
|
||||
ForceCurveMultipleCompareForm, PlanByRscoreForm,
|
||||
AssignChoices,
|
||||
)
|
||||
|
||||
from django.urls import reverse, reverse_lazy
|
||||
@@ -267,6 +268,7 @@ from rowers.tasks import (
|
||||
handle_send_email_instantplan_notification,
|
||||
handle_nk_async_workout,
|
||||
check_tp_workout_id,
|
||||
handle_assignworkouts,
|
||||
)
|
||||
|
||||
from scipy.signal import savgol_filter
|
||||
|
||||
@@ -2031,6 +2031,12 @@ def workouts_bulk_actions(request):
|
||||
'Export to {destination} of workout {id} failed'.format(
|
||||
id=encoder.encode_hex(w.id),
|
||||
destination=destination))
|
||||
elif action == 'rower assign':
|
||||
assignchoices = AssignChoices(request.POST)
|
||||
if assignchoices.is_valid():
|
||||
remove_workout = assignchoices.cleaned_data['remove_workout']
|
||||
rowers = assignchoices.cleaned_data['destination']
|
||||
_ = myqueue(queuehigh, handle_assignworkouts, workouts, rowers, remove_workout)
|
||||
url = reverse('workouts_view')
|
||||
return HttpResponseRedirect(url)
|
||||
else: # pragma: no cover
|
||||
@@ -2041,6 +2047,12 @@ def workouts_bulk_actions(request):
|
||||
exportchoice = ExportChoices()
|
||||
actionform = WorkoutBulkActions()
|
||||
actionform.fields["action"].initial = action
|
||||
assignchoices = AssignChoices()
|
||||
teams = Team.objects.filter(manager=request.user)
|
||||
assignchoices.fields["destination"].queryset = Rower.objects.filter(
|
||||
team__in=teams
|
||||
).distinct().order_by("user__last_name", "user__first_name").exclude(rowerplan='freecoach')
|
||||
assignchoices.fields["destination"].initial = []
|
||||
form = WorkoutMultipleCompareForm()
|
||||
form.fields["workouts"].queryset = Workout.objects.filter(id__in=[w.id for w in workouts])
|
||||
form.fields["workouts"].initial = workouts
|
||||
@@ -2049,6 +2061,7 @@ def workouts_bulk_actions(request):
|
||||
{'action':action,
|
||||
'exportchoice':exportchoice,
|
||||
'actionform':actionform,
|
||||
'assignchoices': assignchoices,
|
||||
'form':form,
|
||||
'workouts':workouts})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user