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 @@ -