From 7f676068f802fd15fb10b93d78ec816337484bf5 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Fri, 30 Mar 2018 09:19:38 +0200 Subject: [PATCH] New round takes defaults from previous one of the same session --- gym/views.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gym/views.py b/gym/views.py index 2082c20..109cd61 100644 --- a/gym/views.py +++ b/gym/views.py @@ -365,14 +365,21 @@ class RoundCreateView(LoginRequiredMixin, QuickActionsMixin, generic.CreateView) initial = super().get_initial() initial['equipment'] = self.equipment initial['session'] = self.session - initial['repetition_number'] = self.equipment.default_repetition_number or 12 - initial['work_form'] = self.equipment.default_work_form + last_round = self.equipment.rounds.filter(session=self.session).last() # type: Round initial['theoretical_max_percentage'] = theoretical_max_percentage - proposed_weight = 0 - theoretical_max = self.equipment.last_theoretical_max - if theoretical_max: - proposed_weight = theoretical_max.value * theoretical_max_percentage / 100 - initial['chosen_weight'] = proposed_weight + + if last_round: + initial['repetition_number'] = last_round.repetition_number + initial['work_form'] = last_round.work_form + initial['chosen_weight'] = last_round.chosen_weight + else: + initial['repetition_number'] = self.equipment.default_repetition_number or 12 + initial['work_form'] = self.equipment.default_work_form + proposed_weight = 0 + theoretical_max = self.equipment.last_theoretical_max + if theoretical_max: + proposed_weight = theoretical_max.value * theoretical_max_percentage / 100 + initial['chosen_weight'] = proposed_weight return initial