From 4559fd167a1ac516263a8e454fff8728cf266664 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 3 Oct 2011 18:10:53 +0000 Subject: [PATCH] user ids for users --- pandora/user/models.py | 9 ++++++--- pandora/user/views.py | 14 ++++++++------ static/50x.html | 10 +++++----- static/js/pandora/UI.js | 2 +- static/js/pandora/ui/filter.js | 3 +-- static/js/pandora/ui/usersDialog.js | 18 ++++++++++++------ 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/pandora/user/models.py b/pandora/user/models.py index 880cb9d62..f8a5d1527 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -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, diff --git a/pandora/user/views.py b/pandora/user/views.py index 5f2ea5299..6ed02b1ee 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -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() diff --git a/static/50x.html b/static/50x.html index 6ba31bdb8..338103574 100644 --- a/static/50x.html +++ b/static/50x.html @@ -4,18 +4,18 @@ -We'll be back in a minute +We will be back in a minute - -
-We'll be back in a minute. + +
+We will be back in a minute.
diff --git a/static/js/pandora/UI.js b/static/js/pandora/UI.js index 215bfea26..7c127767e 100644 --- a/static/js/pandora/UI.js +++ b/static/js/pandora/UI.js @@ -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); diff --git a/static/js/pandora/ui/filter.js b/static/js/pandora/ui/filter.js index 6de613d2d..f55fffa12 100644 --- a/static/js/pandora/ui/filter.js +++ b/static/js/pandora/ui/filter.js @@ -50,8 +50,7 @@ pandora.ui.filter = function(list) { }); } else { pandora.UI.set({find: data.query}); - pandora.URL.push(); - //reload(); + //pandora.URL.replace(); } } }); diff --git a/static/js/pandora/ui/usersDialog.js b/static/js/pandora/ui/usersDialog.js index 3074c8798..72cb87945 100644 --- a/static/js/pandora/ui/usersDialog.js +++ b/static/js/pandora/ui/usersDialog.js @@ -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'); }); } });