From 12bce6638b8d52466bb165e1b319570ec9155bc2 Mon Sep 17 00:00:00 2001 From: Jason McBrayer Date: Fri, 22 Jun 2018 08:39:42 -0400 Subject: [PATCH] Update settings view a bit; still in progress --- brutaldon/views.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/brutaldon/views.py b/brutaldon/views.py index d144921..9ead940 100644 --- a/brutaldon/views.py +++ b/brutaldon/views.py @@ -6,7 +6,7 @@ from django.views.decorators.cache import never_cache, cache_page from django.urls import reverse from django.core.files.uploadhandler import TemporaryFileUploadHandler from brutaldon.forms import LoginForm, OAuthLoginForm, SettingsForm, PostForm -from brutaldon.models import Client, Account +from brutaldon.models import Client, Account, Preference, Theme from mastodon import Mastodon, AttribAccessDict, MastodonError from urllib import parse from pdb import set_trace @@ -369,26 +369,22 @@ def user(request, username, prev=None, next=None): @never_cache @br_login_required def settings(request): + account = Account.objects.get(username=username, client_id=client.id) if request.method == 'POST': form = SettingsForm(request.POST) if form.is_valid(): - request.session['fullbrutalism'] = form.cleaned_data['fullbrutalism'] - request.session['filter_replies'] = form.cleaned_data['filter_replies'] - request.session['filter_boosts'] = form.cleaned_data['filter_boosts'] - request.session['timezone'] = form.cleaned_data['timezone'] + account.preferences.theme = Theme.objects.get(form.cleaned_data['theme']) + account.preferences.filter_replies = form.cleaned_data['filter_replies'] + account.preferences.filter_boosts = form.cleaned_data['filter_boosts'] + account.preferences.timezone = form.cleaned_data['timezone'] + account.preferences.save() + account.save() return redirect(home) else: return render(request, 'setup/settings.html', - {'form' : form, - 'own_acct': request.session['user'], - 'fullbrutalism': fullbrutalism_p(request)}) + {'form' : form, 'account': account}) else: - form = SettingsForm(initial={ - "fullbrutalism": fullbrutalism_p(request), - "filter_replies": request.session.get('filter_replies', False), - "filter_boosts": request.session.get('filter_boosts', False), - "timezone": request.session.get('timezone', 'UTC') - }) + form = SettingsForm(account.preferences) return render(request, 'setup/settings.html', { 'form': form, 'own_acct': request.session['user'],