Update settings view a bit; still in progress

This commit is contained in:
Jason McBrayer 2018-06-22 08:39:42 -04:00
parent b3444772fc
commit 12bce6638b
1 changed files with 10 additions and 14 deletions

View File

@ -6,7 +6,7 @@ from django.views.decorators.cache import never_cache, cache_page
from django.urls import reverse from django.urls import reverse
from django.core.files.uploadhandler import TemporaryFileUploadHandler from django.core.files.uploadhandler import TemporaryFileUploadHandler
from brutaldon.forms import LoginForm, OAuthLoginForm, SettingsForm, PostForm 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 mastodon import Mastodon, AttribAccessDict, MastodonError
from urllib import parse from urllib import parse
from pdb import set_trace from pdb import set_trace
@ -369,26 +369,22 @@ def user(request, username, prev=None, next=None):
@never_cache @never_cache
@br_login_required @br_login_required
def settings(request): def settings(request):
account = Account.objects.get(username=username, client_id=client.id)
if request.method == 'POST': if request.method == 'POST':
form = SettingsForm(request.POST) form = SettingsForm(request.POST)
if form.is_valid(): if form.is_valid():
request.session['fullbrutalism'] = form.cleaned_data['fullbrutalism'] account.preferences.theme = Theme.objects.get(form.cleaned_data['theme'])
request.session['filter_replies'] = form.cleaned_data['filter_replies'] account.preferences.filter_replies = form.cleaned_data['filter_replies']
request.session['filter_boosts'] = form.cleaned_data['filter_boosts'] account.preferences.filter_boosts = form.cleaned_data['filter_boosts']
request.session['timezone'] = form.cleaned_data['timezone'] account.preferences.timezone = form.cleaned_data['timezone']
account.preferences.save()
account.save()
return redirect(home) return redirect(home)
else: else:
return render(request, 'setup/settings.html', return render(request, 'setup/settings.html',
{'form' : form, {'form' : form, 'account': account})
'own_acct': request.session['user'],
'fullbrutalism': fullbrutalism_p(request)})
else: else:
form = SettingsForm(initial={ form = SettingsForm(account.preferences)
"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')
})
return render(request, 'setup/settings.html', return render(request, 'setup/settings.html',
{ 'form': form, { 'form': form,
'own_acct': request.session['user'], 'own_acct': request.session['user'],