New round takes defaults from previous one of the same session

This commit is contained in:
Gabriel Augendre 2018-03-30 09:19:38 +02:00
parent 2dfd335b04
commit 7f676068f8
No known key found for this signature in database
GPG key ID: F360212F958357D4

View file

@ -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