def settings(request): if request.method == 'GET': form = SettingsForm(data={ 'login': request.user.username, 'email': request.user.email }) if request.POST: form = SettingsForm(data=request.POST, files=request.FILES, instance=request.user.author) if form.is_valid(): post = form.save(commit=False) username_field = form.cleaned_data.get('login') email_field = form.cleaned_data.get('email') author = request.user.author author.user_name = username_field author.avatar = request.FILES.get('avatar', request.user.author.avatar) author.save() user_ = request.user user_.username = username_field user_.email = email_field user_.save() form.save() return render(request, 'settings.html', {'form': form})
def settings(request): if request.method == 'POST': form = SettingsForm(request.POST, instance=request.user) formAv = AvatarForm(request.user, request.POST, request.FILES) if formAv.is_valid(): formAv.save() if form.is_valid(): form.save() return redirect('/main/') tags = Tag.objects.best_tags()[0:10] users = Client.objects.best_members()[0:10] return render(request, 'settings_page.html', { 'tags': tags, 'users': users, 'form': form, 'formAv': formAv, 'user': request.user, 'errors': form.errors, }) else: form = SettingsForm(instance=request.user) formAv = AvatarForm(request.user) tags = Tag.objects.best_tags()[0:10] users = Client.objects.best_members()[0:10] return render(request, 'settings_page.html', { 'tags': tags, 'users': users, 'form': form, 'formAv': formAv, 'user': request.user, 'errors': form.errors, })
def settings(request): if request.method == 'GET': form = SettingsForm(instance=request.user) elif request.method == 'POST': form = SettingsForm(data=request.POST, instance=request.user, files=request.FILES) if form.is_valid(): form.save() return render(request, 'settings.html', {'form': form})
def settings_page(request): if request.method == 'POST': form = SettingsForm(data=request.POST, instance=request.user, files=request.FILES) if form.is_valid(): form.save() return redirect(reverse('settings')) else: user_data = { 'username': request.user.username, 'first_name': request.user.first_name, 'email': request.user.email } form = SettingsForm(initial=user_data) return render(request, 'settings_page.html', {'form': form})
def save_settings(): form = SettingsForm() form.save(g.user) s = OreCalcService(g.user) return jsonify(s.to_json())