user ids for users
This commit is contained in:
parent
8dd8dab270
commit
4559fd167a
6 changed files with 33 additions and 23 deletions
|
@ -8,6 +8,7 @@ from django.db import models
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
import ox
|
||||||
from ox.django.fields import DictField
|
from ox.django.fields import DictField
|
||||||
from ox.utils import json
|
from ox.utils import json
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ class UserProfile(models.Model):
|
||||||
windowsize = models.CharField(default='', max_length=255)
|
windowsize = models.CharField(default='', max_length=255)
|
||||||
screensize = models.CharField(default='', max_length=255)
|
screensize = models.CharField(default='', max_length=255)
|
||||||
info = DictField(default={})
|
info = DictField(default={})
|
||||||
note = models.TextField(default='')
|
notes = models.TextField(default='')
|
||||||
|
|
||||||
def get_preferences(self):
|
def get_preferences(self):
|
||||||
prefs = self.preferences
|
prefs = self.preferences
|
||||||
|
@ -103,15 +104,17 @@ def user_post_save(sender, instance, **kwargs):
|
||||||
|
|
||||||
models.signals.post_save.connect(user_post_save, sender=User)
|
models.signals.post_save.connect(user_post_save, sender=User)
|
||||||
|
|
||||||
def user_json(user, keys, request_user=None):
|
def user_json(user, keys=None, request_user=None):
|
||||||
p = user.get_profile()
|
p = user.get_profile()
|
||||||
j = {
|
j = {
|
||||||
|
'disabled': not user.is_active,
|
||||||
'email': user.email,
|
'email': user.email,
|
||||||
'firstseen': user.date_joined,
|
'firstseen': user.date_joined,
|
||||||
'ip': p.ip,
|
'ip': p.ip,
|
||||||
|
'id': ox.to26(user.id),
|
||||||
'lastseen': user.last_login,
|
'lastseen': user.last_login,
|
||||||
'level': p.get_level(),
|
'level': p.get_level(),
|
||||||
'note': p.note,
|
'notes': p.notes,
|
||||||
'numberoflists': user.lists.count(),
|
'numberoflists': user.lists.count(),
|
||||||
'screensize': p.screensize,
|
'screensize': p.screensize,
|
||||||
'timesseen': p.timesseen,
|
'timesseen': p.timesseen,
|
||||||
|
|
|
@ -316,7 +316,7 @@ def editUser(request):
|
||||||
key: value
|
key: value
|
||||||
}
|
}
|
||||||
required key: id
|
required key: id
|
||||||
optional keys: username, email, level, note
|
optional keys: username, email, level, notes
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'status': {'code': int, 'text': string}
|
'status': {'code': int, 'text': string}
|
||||||
|
@ -326,8 +326,10 @@ def editUser(request):
|
||||||
'''
|
'''
|
||||||
response = json_response()
|
response = json_response()
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
user = get_object_or_404_json(models.User, username=data['id'])
|
user = get_object_or_404_json(models.User, pk=ox.from26(data['id']))
|
||||||
profile = user.get_profile()
|
profile = user.get_profile()
|
||||||
|
if 'disabled' in data:
|
||||||
|
user.is_active = not data['disabled']
|
||||||
if 'email' in data:
|
if 'email' in data:
|
||||||
if models.User.objects.filter(email=data['email']).exclude(id=user.id).count()>0:
|
if models.User.objects.filter(email=data['email']).exclude(id=user.id).count()>0:
|
||||||
response = json_response(status=403, text='email already in use')
|
response = json_response(status=403, text='email already in use')
|
||||||
|
@ -335,8 +337,8 @@ def editUser(request):
|
||||||
user.email = data['email']
|
user.email = data['email']
|
||||||
if 'level' in data:
|
if 'level' in data:
|
||||||
profile.set_level(data['level'])
|
profile.set_level(data['level'])
|
||||||
if 'note' in data:
|
if 'notes' in data:
|
||||||
profile.note = data['note']
|
profile.notes = data['notes']
|
||||||
if 'username' in data:
|
if 'username' in data:
|
||||||
if models.User.objects.filter(username=data['username']).exclude(id=user.id).count()>0:
|
if models.User.objects.filter(username=data['username']).exclude(id=user.id).count()>0:
|
||||||
response = json_response(status=403, text='username already in use')
|
response = json_response(status=403, text='username already in use')
|
||||||
|
@ -344,7 +346,7 @@ def editUser(request):
|
||||||
user.username = data['username']
|
user.username = data['username']
|
||||||
user.save()
|
user.save()
|
||||||
profile.save()
|
profile.save()
|
||||||
response['data'] = models.user_json()
|
response['data'] = models.user_json(user)
|
||||||
return render_to_json_response(response)
|
return render_to_json_response(response)
|
||||||
actions.register(editUser, cache=False)
|
actions.register(editUser, cache=False)
|
||||||
|
|
||||||
|
@ -515,7 +517,7 @@ Positions
|
||||||
if qs.count() > 0:
|
if qs.count() > 0:
|
||||||
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
|
response['data']['position'] = utils.get_positions(ids, [qs[0].itemId])[0]
|
||||||
elif 'positions' in data:
|
elif 'positions' in data:
|
||||||
ids = [i.username for i in qs]
|
ids = [ox.to26(i.id) for i in qs]
|
||||||
response['data']['positions'] = utils.get_positions(ids, data['positions'])
|
response['data']['positions'] = utils.get_positions(ids, data['positions'])
|
||||||
else:
|
else:
|
||||||
response['data']['items'] = qs.count()
|
response['data']['items'] = qs.count()
|
||||||
|
|
|
@ -4,18 +4,18 @@
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding-top: 96px;
|
padding-top: 128px;
|
||||||
background: #101010;
|
background: #101010;
|
||||||
color: #F0F0F0;
|
color: #F0F0F0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" type="text/css" href="/static/oxjs/build/Ox.UI/css/Ox.UI.css"/>
|
<link rel="stylesheet" type="text/css" href="/static/oxjs/build/Ox.UI/css/Ox.UI.css"/>
|
||||||
<title>We'll be back in a minute</title>
|
<title>We will be back in a minute</title>
|
||||||
</head>
|
</head>
|
||||||
<body class="OxThemeModern">
|
<body class="OxThemeModern">
|
||||||
<img src="/static/png/logo256.png">
|
<img src="/static/png/logo256.png" style="width: 256px"/>
|
||||||
<div style="padding-top: 8px">
|
<div style="padding-top: 16px">
|
||||||
We'll be back in a minute.
|
We will be back in a minute.
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ pandora.UI = (function() {
|
||||||
if (!isAdd) {
|
if (!isAdd) {
|
||||||
trigger[key] = val;
|
trigger[key] = val;
|
||||||
}
|
}
|
||||||
}
|
}// else { alert(keys[0] + ' equal\n\n' + JSON.stringify([ui[keys[0]], val])); }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Ox.len(set) && pandora.api.setUI(set);
|
Ox.len(set) && pandora.api.setUI(set);
|
||||||
|
|
|
@ -50,8 +50,7 @@ pandora.ui.filter = function(list) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
pandora.UI.set({find: data.query});
|
pandora.UI.set({find: data.query});
|
||||||
pandora.URL.push();
|
//pandora.URL.replace();
|
||||||
//reload();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -26,7 +26,7 @@ pandora.ui.usersDialog = function() {
|
||||||
click: function() {
|
click: function() {
|
||||||
pandora.api.findUsers({
|
pandora.api.findUsers({
|
||||||
query: {conditions: [], operator: '&'},
|
query: {conditions: [], operator: '&'},
|
||||||
keys: ['mail', 'username'],
|
keys: ['email', 'username'],
|
||||||
range: [0, numberOfUsers],
|
range: [0, numberOfUsers],
|
||||||
sort: [{key: 'username', operator: '+'}]
|
sort: [{key: 'username', operator: '+'}]
|
||||||
}, function(result) {
|
}, function(result) {
|
||||||
|
@ -46,7 +46,7 @@ pandora.ui.usersDialog = function() {
|
||||||
.css({margin: '16px'})
|
.css({margin: '16px'})
|
||||||
.html(
|
.html(
|
||||||
result.data.items.map(function(item) {
|
result.data.items.map(function(item) {
|
||||||
return item.username + ' <' + 'mail@example.com' + '>'
|
return item.username + ' <' + item.email + '>'
|
||||||
}).join(', ')
|
}).join(', ')
|
||||||
),
|
),
|
||||||
title: 'E-Mail Addresses'
|
title: 'E-Mail Addresses'
|
||||||
|
@ -100,6 +100,12 @@ pandora.ui.usersDialog = function() {
|
||||||
|
|
||||||
$list = Ox.TextList({
|
$list = Ox.TextList({
|
||||||
columns: [
|
columns: [
|
||||||
|
{
|
||||||
|
id: 'id',
|
||||||
|
title: 'ID',
|
||||||
|
unique: true,
|
||||||
|
visible: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
format: function(value) {
|
format: function(value) {
|
||||||
Ox.print('&&', value)
|
Ox.print('&&', value)
|
||||||
|
@ -136,7 +142,6 @@ pandora.ui.usersDialog = function() {
|
||||||
removable: false,
|
removable: false,
|
||||||
title: 'Username',
|
title: 'Username',
|
||||||
visible: true,
|
visible: true,
|
||||||
unique: true,
|
|
||||||
width: 120
|
width: 120
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -250,7 +255,7 @@ pandora.ui.usersDialog = function() {
|
||||||
columnsRemovable: true,
|
columnsRemovable: true,
|
||||||
columnsVisible: true,
|
columnsVisible: true,
|
||||||
items: pandora.api.findUsers,
|
items: pandora.api.findUsers,
|
||||||
keys: [],
|
keys: ['notes'],
|
||||||
max: 1,
|
max: 1,
|
||||||
scrollbarVisible: true,
|
scrollbarVisible: true,
|
||||||
sort: [
|
sort: [
|
||||||
|
@ -426,7 +431,7 @@ pandora.ui.usersDialog = function() {
|
||||||
.css({margin: '8px'})
|
.css({margin: '8px'})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
change: function(event) {
|
change: function(event) {
|
||||||
var data = {id: userData.username}, key, value;
|
var data = {id: userData.id}, key, value;
|
||||||
if (event.id == 'status') {
|
if (event.id == 'status') {
|
||||||
data.disabled = !event.data.checked;
|
data.disabled = !event.data.checked;
|
||||||
} else if (event.id == 'level') {
|
} else if (event.id == 'level') {
|
||||||
|
@ -434,8 +439,9 @@ pandora.ui.usersDialog = function() {
|
||||||
} else {
|
} else {
|
||||||
data[event.id] = event.data.value;
|
data[event.id] = event.data.value;
|
||||||
}
|
}
|
||||||
|
$list.value(userData.id, event.id, data[event.id]);
|
||||||
pandora.api.editUser(data, function(result) {
|
pandora.api.editUser(data, function(result) {
|
||||||
// ...
|
Ox.Request.clearCache('findUsers');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue