forked from 0x2620/pandora
implement preferences
This commit is contained in:
parent
e6601e6dca
commit
228cb1f851
2 changed files with 11 additions and 10 deletions
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue