save UI state
This commit is contained in:
parent
fddc4d29d3
commit
2430638cde
7 changed files with 259 additions and 169 deletions
|
|
@ -33,7 +33,17 @@ class UserProfile(models.Model):
|
|||
ui = {}
|
||||
config = site_config()
|
||||
ui.update(config['user']['ui'])
|
||||
ui.update(self.ui)
|
||||
def updateUI(ui, new):
|
||||
'''
|
||||
only update set keys in dicts
|
||||
'''
|
||||
for key in new:
|
||||
if isinstance(new[key], dict) and key in ui:
|
||||
ui[key] = updateUI(ui[key], new[key])
|
||||
else:
|
||||
ui[key] = new[key]
|
||||
return ui
|
||||
ui = updateUI(ui, self.ui)
|
||||
if not 'lists' in ui:
|
||||
ui['lists'] = {}
|
||||
ui['lists'][''] = config['uiDefaults']['list']
|
||||
|
|
|
|||
|
|
@ -409,14 +409,14 @@ def setUI(request):
|
|||
key.subkey: value
|
||||
}
|
||||
you can set nested keys
|
||||
api.setUI({"lists.my.listView": "icons"})
|
||||
api.setUI({"lists|my|ListView": "icons"})
|
||||
|
||||
return {
|
||||
'status': {'code': int, 'text': string}
|
||||
}
|
||||
'''
|
||||
data = json.loads(request.POST['data'])
|
||||
keys = data.keys()[0].split('.')
|
||||
keys = data.keys()[0].split('|')
|
||||
value = data.values()[0]
|
||||
profile = request.user.get_profile()
|
||||
p = profile.ui
|
||||
|
|
@ -425,6 +425,8 @@ def setUI(request):
|
|||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue