From 228cb1f851e6cd9114bcafe475d2384317dd1492 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 27 Jan 2010 11:06:21 +0530 Subject: [PATCH] implement preferences --- oxdb/oxuser/models.py | 3 ++- oxdb/oxuser/views.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/oxdb/oxuser/models.py b/oxdb/oxuser/models.py index 3a0c153ba..aa14d6621 100644 --- a/oxdb/oxuser/models.py +++ b/oxdb/oxuser/models.py @@ -3,6 +3,7 @@ from django.db import models from django.contrib.auth.models import User +from django.utils import simplejson as json class Preference(models.Model): @@ -22,7 +23,7 @@ def getUserJSON(user): def getPreferences(user): prefs = {} for p in Preference.objects.filter(user=user): - prefs[key] = json.loads(p.value) + prefs[p.key] = json.loads(p.value) return prefs def getPreference(user, key, value=None): diff --git a/oxdb/oxuser/views.py b/oxdb/oxuser/views.py index 76796e3cd..f7de35e5d 100644 --- a/oxdb/oxuser/views.py +++ b/oxdb/oxuser/views.py @@ -117,6 +117,7 @@ def api_recover(request): if q.count() > 0: user = q[0] if user: + user.email_user('recovert','not yest, but soon you will be able to recover') #user.sendmail(...) #FIXME: send recovery mail response = {'status': {'code': 200, 'text': 'recover email sent.'}} else: @@ -140,22 +141,21 @@ def api_preferences(request): if data is dict: set key values in dict as preferences ''' - response = {'status': 200, 'statusText': 'ok'} + response = {'status': {'code': 200, 'text': 'ok'}, 'data':{}} if 'data' not in request.POST: - response['preferences'] = request.user.preferences + response['data']['preferences'] = models.getPreferences(request.user) else: data = json.loads(request.POST['data']) if isinstance(data, basestring): - response = {'status': 500, 'statusText': 'fixme: get preferences not implemented'} - response['preferences'][data] = models.getPreference(user, data) + response['data']['preferences'] = {} + response['data']['preferences'][data] = models.getPreference(request.user, data) elif isinstance(data, list): - response = {'status': 500, 'statusText': 'fixme: get preferences not implemented'} - response['preferences'] = {} + response['data']['preferences'] = {} for preference in data: - response['preferences'][preference] = models.getPreference(user, preference) + response['preferences'][preference] = models.getPreference(request.user, preference) elif isinstance(data, dict): - response = {'status': 500, 'statusText': 'fixme: set preferences not implemented'} + del response['data'] for key in data: - models.setPreference(user, key, data[key]) + models.setPreference(request.user, key, data[key]) return render_to_json_response(response)