From 45bb18ef9658704f21d310b0e652152c73707ed9 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 18 Oct 2011 23:41:54 +0200 Subject: [PATCH] editPreferences --- pandora/user/views.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/pandora/user/views.py b/pandora/user/views.py index 524e5e1b..8737a4af 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -577,29 +577,34 @@ def getPositionById(list, key): @login_required_json -def setPreferences(request): +def editPreferences(request): ''' param data { - key.subkey: value + key: value } + keys: email, password return ''' data = json.loads(request.POST['data']) - keys = re.sub('([^\\\\])\.', '\\1\n', data.keys()[0]).split('\n') - value = data.values()[0] - profile = request.user.get_profile() - p = profile.preferences - while len(keys)>1: - key = keys.pop(0) - if isinstance(p, list): - p = p[getPositionById(p, key)] - else: - p = p[key] - p[keys[0]] = value - profile.save() + errors = {} + change = False response = json_response() + if 'email' in data: + if models.User.objects.filter( + email=data['email']).exclude(username=request.user.username).count()>0: + errors['email'] = 'Email address already in use' + else: + change = True + request.user.email = data['email'] + if 'password' in data: + change = True + request.user.password = data['password'] + if change: + request.user.save() + if errors: + response = json_response({ 'errors': errors}) return render_to_json_response(response) -actions.register(setPreferences, cache=False) +actions.register(editPreferences, cache=False) def resetUI(request):