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