|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#-*- coding:utf-8 -*-
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from common.decorators import render
from accounts.forms import SettingsForm
from accounts.models import UserSettings
@login_required
@render()
def settings(request):
user_settings, created = UserSettings.objects.get_or_create(user=request.user)
if request.method == 'POST':
form = SettingsForm(data=request.POST, instance=user_settings)
if form.is_valid():
form.save()
return HttpResponseRedirect(request.POST['next'])
else:
form = SettingsForm(instance=user_settings)
return {'form': form, 'next': request.META.get('HTTP_REFERER', '')}
|