def post(self, request, *args, **kwargs): """ Save user color theme selection """ form = self.get_form() # Get current user theme user_theme = self.get_user_theme() # Create theme entry if user did not select one yet if not user_theme: user_theme = ColorTheme() user_theme.user = request.user if form.is_valid(): theme_selected = form.cleaned_data['name'] # Set color theme to form selection user_theme.name = theme_selected user_theme.save() return self.form_valid(form) else: # Set color theme to default user_theme.name = ColorTheme.default_color_theme[0] user_theme.save() return self.form_invalid(form)
def post(self, request, *args, **kwargs): """Save user color theme selection.""" theme = request.POST.get('theme', None) # Get current user theme user_theme = self.get_user_theme() # Create theme entry if user did not select one yet if not user_theme: user_theme = ColorTheme() user_theme.user = request.user user_theme.name = theme user_theme.save() return redirect(reverse_lazy('settings'))