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.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.utils import simplejson as json
|
||||||
|
|
||||||
|
|
||||||
class Preference(models.Model):
|
class Preference(models.Model):
|
||||||
|
@ -22,7 +23,7 @@ def getUserJSON(user):
|
||||||
def getPreferences(user):
|
def getPreferences(user):
|
||||||
prefs = {}
|
prefs = {}
|
||||||
for p in Preference.objects.filter(user=user):
|
for p in Preference.objects.filter(user=user):
|
||||||
prefs[key] = json.loads(p.value)
|
prefs[p.key] = json.loads(p.value)
|
||||||
return prefs
|
return prefs
|
||||||
|
|
||||||
def getPreference(user, key, value=None):
|
def getPreference(user, key, value=None):
|
||||||
|
|
|
@ -117,6 +117,7 @@ def api_recover(request):
|
||||||
if q.count() > 0:
|
if q.count() > 0:
|
||||||
user = q[0]
|
user = q[0]
|
||||||
if user:
|
if user:
|
||||||
|
user.email_user('recovert','not yest, but soon you will be able to recover')
|
||||||
#user.sendmail(...) #FIXME: send recovery mail
|
#user.sendmail(...) #FIXME: send recovery mail
|
||||||
response = {'status': {'code': 200, 'text': 'recover email sent.'}}
|
response = {'status': {'code': 200, 'text': 'recover email sent.'}}
|
||||||
else:
|
else:
|
||||||
|
@ -140,22 +141,21 @@ def api_preferences(request):
|
||||||
if data is dict:
|
if data is dict:
|
||||||
set key values in dict as preferences
|
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:
|
if 'data' not in request.POST:
|
||||||
response['preferences'] = request.user.preferences
|
response['data']['preferences'] = models.getPreferences(request.user)
|
||||||
else:
|
else:
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
if isinstance(data, basestring):
|
if isinstance(data, basestring):
|
||||||
response = {'status': 500, 'statusText': 'fixme: get preferences not implemented'}
|
response['data']['preferences'] = {}
|
||||||
response['preferences'][data] = models.getPreference(user, data)
|
response['data']['preferences'][data] = models.getPreference(request.user, data)
|
||||||
elif isinstance(data, list):
|
elif isinstance(data, list):
|
||||||
response = {'status': 500, 'statusText': 'fixme: get preferences not implemented'}
|
response['data']['preferences'] = {}
|
||||||
response['preferences'] = {}
|
|
||||||
for preference in data:
|
for preference in data:
|
||||||
response['preferences'][preference] = models.getPreference(user, preference)
|
response['preferences'][preference] = models.getPreference(request.user, preference)
|
||||||
elif isinstance(data, dict):
|
elif isinstance(data, dict):
|
||||||
response = {'status': 500, 'statusText': 'fixme: set preferences not implemented'}
|
del response['data']
|
||||||
for key in data:
|
for key in data:
|
||||||
models.setPreference(user, key, data[key])
|
models.setPreference(request.user, key, data[key])
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue