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,8 +433,10 @@ 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:
keys = key.split('|')
value = data[key]
profile = request.user.get_profile() profile = request.user.get_profile()
p = profile.ui p = profile.ui
while len(keys)>1: while len(keys)>1:
@ -447,6 +449,15 @@ def setUI(request):
p = p[key] p = p[key]
p[keys[0]] = value p[keys[0]] = value
profile.save() 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:
access, created = Access.objects.get_or_create(item=item, user=None)
access.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)