update item access in setUI

This commit is contained in:
j 2011-01-25 20:15:07 +05:30
parent a7b84e2b7f
commit 7c1e3c7681
2 changed files with 29 additions and 16 deletions

View file

@ -92,10 +92,12 @@ def get_user_json(user):
result = {} result = {}
for key in ('username', ): for key in ('username', ):
result[key] = getattr(user, key) result[key] = getattr(user, key)
if user.is_staff: if user.is_superuser:
result['level'] = 'admin' result['level'] = 'admin'
elif user.is_staff:
result['level'] = 'staff'
else: else:
result['level'] = 'user' result['level'] = 'member'
result['groups'] = [g.name for g in user.groups.all()] result['groups'] = [g.name for g in user.groups.all()]
result['preferences'] = profile.get_preferences() result['preferences'] = profile.get_preferences()
result['ui'] = profile.get_ui() result['ui'] = profile.get_ui()

View file

@ -19,6 +19,7 @@ import models
from api.actions import actions from api.actions import actions
from app.models import site_config from app.models import site_config
from item.models import Access, Item
class SigninForm(forms.Form): class SigninForm(forms.Form):
username = forms.TextInput() username = forms.TextInput()
@ -419,7 +420,6 @@ def resetUI(request):
return render_to_json_response(response) return render_to_json_response(response)
actions.register(resetUI, cache=False) actions.register(resetUI, cache=False)
@login_required_json
def setUI(request): def setUI(request):
''' '''
param data { param data {
@ -433,20 +433,31 @@ def setUI(request):
} }
''' '''
data = json.loads(request.POST['data']) data = json.loads(request.POST['data'])
keys = data.keys()[0].split('|') if request.user.is_authenticated():
value = data.values()[0] for key in data:
profile = request.user.get_profile() keys = key.split('|')
p = profile.ui value = data[key]
while len(keys)>1: profile = request.user.get_profile()
key = keys.pop(0) p = profile.ui
if isinstance(p, list): while len(keys)>1:
p = p[getPositionById(p, key)] key = keys.pop(0)
if isinstance(p, list):
p = p[getPositionById(p, key)]
else:
if key not in p:
p[key] = {}
p = p[key]
p[keys[0]] = value
profile.save()
if data.get('item', False):
item = Item.objects.get(itemId=data['item'])
if request.user.is_authenticated():
access, created = Access.objects.get_or_create(item=item, user=request.user)
else: else:
if key not in p: access, created = Access.objects.get_or_create(item=item, user=None)
p[key] = {} access.save()
p = p[key]
p[keys[0]] = value
profile.save()
response = json_response() response = json_response()
return render_to_json_response(response) return render_to_json_response(response)
actions.register(setUI, cache=False) actions.register(setUI, cache=False)