def save(self): presets = list(all_presets()) t = self.instance # Identify + apply selected preset selected_index = self.cleaned_data["preset_rules"] selected_preset = next(p for p in presets if p.name == selected_index) selected_preferences = get_preferences_data(selected_preset, t) for preference in selected_preferences: t.preferences[preference['key']] = preference['new_value'] # Apply public info presets do_public = self.cleaned_data["public_info"] public_preset = next((p for p in presets if p.name == do_public), False) if public_preset: public_preferences = get_preferences_data(public_preset, t) for preference in public_preferences: t.preferences[preference['key']] = preference['new_value'] # Apply the credits if self.cleaned_data['tournament_staff'] != self.fields['tournament_staff'].initial: t.preferences["public_features__tournament_staff"] = self.cleaned_data["tournament_staff"] # Create break rounds (need to do so after we know teams-per-room) open_break = BreakCategory.objects.filter(tournament=t, is_general=True).first() # Check there aren't already break rounds (i.e. when importing demos) if open_break and not t.break_rounds().exists(): if t.pref('teams_in_debate') == 'bp': num_break_rounds = math.ceil(math.log2(open_break.break_size / 2)) else: num_break_rounds = math.ceil(math.log2(open_break.break_size)) auto_make_break_rounds(t, num_break_rounds, open_break)