From 4e6c2250c90f49fa5ae300046088b35343ebfee8 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 13 Jan 2012 15:17:18 +0530 Subject: [PATCH] item/user groups --- pandora/item/models.py | 11 +++++++---- pandora/item/views.py | 1 + pandora/user/models.py | 3 ++- pandora/user/views.py | 9 +++++++++ static/js/pandora/infoView.padma.js | 26 ++++++++++++++++++-------- static/js/pandora/usersDialog.js | 16 +++++++++++++++- 6 files changed, 52 insertions(+), 14 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index 04ee7b680..d33ec2047 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -209,10 +209,13 @@ class Item(models.Model): del data['id'] if 'groups' in data: groups = data.pop('groups') - self.groups.exclude(name__in=groups).delete() - for g in groups: - group, created = Group.objects.get_or_create(name=g) - self.groups.add(group) + if isinstance(groups, list): + groups = filter(lambda g: g.strip(), groups) + self.groups.exclude(name__in=groups).delete() + current_groups = [g.name for g in self.groups.all()] + for g in filter(lambda g: g not in current_groups, groups): + group, created = Group.objects.get_or_create(name=g) + self.groups.add(group) for key in data: self.data[key] = data[key] return self.save() diff --git a/pandora/item/views.py b/pandora/item/views.py index fca883cc8..363e0174a 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -404,6 +404,7 @@ def get(request): if not data['keys'] or 'notes' in data['keys'] \ and request.user.get_profile().capability('canEditMetadata'): info['notes'] = item.notes + info['groups'] = [g.name for g in item.groups.all()] response['data'] = info else: response = json_response(status=403, text='permission denied') diff --git a/pandora/user/models.py b/pandora/user/models.py index 11dcac9fb..61fb0274d 100644 --- a/pandora/user/models.py +++ b/pandora/user/models.py @@ -3,7 +3,7 @@ import copy from datetime import datetime -from django.contrib.auth.models import User +from django.contrib.auth.models import User, Group from django.db import models from django.db.models import Max from django.conf import settings @@ -149,6 +149,7 @@ class SessionData(models.Model): p = self.user.get_profile() j['disabled'] = not self.user.is_active j['email'] = self.user.email + j['groups'] = [g.name for g in self.user.groups.all()] j['level'] = p.get_level() j['newsletter'] = p.newsletter j['notes'] = p.notes diff --git a/pandora/user/views.py b/pandora/user/views.py index ec49f12b1..e5125ee55 100644 --- a/pandora/user/views.py +++ b/pandora/user/views.py @@ -334,6 +334,15 @@ def editUser(request): profile.notes = data['notes'] if 'newsletter' in data: profile.newsletter = data['newsletter'] + if 'groups' in data: + groups = data['groups'] + if isinstance(groups, list): + groups = filter(lambda g: g.strip(), groups) + user.groups.exclude(name__in=groups).delete() + current_groups = [g.name for g in user.groups.all()] + for g in filter(lambda g: g not in current_groups, groups): + group, created = models.Group.objects.get_or_create(name=g) + user.groups.add(group) if 'username' in data: if models.User.objects.filter( username__iexact=data['username']).exclude(id=user.id).count()>0: diff --git a/static/js/pandora/infoView.padma.js b/static/js/pandora/infoView.padma.js index 9beeea5b0..c0bc418dc 100644 --- a/static/js/pandora/infoView.padma.js +++ b/static/js/pandora/infoView.padma.js @@ -264,7 +264,7 @@ pandora.ui.infoView = function(data) { ) .appendTo($text); - var list_keys = ['language', 'topic', 'director', 'cinematographer', 'features']; + var list_keys = ['language', 'topic', 'director', 'cinematographer', 'features', 'groups']; $('
').html('
').appendTo($text); [ 'date', @@ -284,7 +284,6 @@ pandora.ui.infoView = function(data) { .html( formatKey({ categorty: 'categories', - user: 'contributor' }[key] || key).replace('', ' ') ) .appendTo($div); @@ -352,6 +351,22 @@ pandora.ui.infoView = function(data) { // Notes ------------------------------------------------------------------- if (canEdit) { + $('
') + .css({marginBottom: '4px'}) + .append(formatKey('Groups', true)) + .append( + Ox.Editable({ + placeholder: formatLight('No Groups'), + tooltip: 'Doubleclick to edit', + value: data.groups.join(', '), + }) + .bindEvent({ + submit: function(event) { + editMetadata('groups', event.value); + } + }) + ) + .appendTo($statistics); $('
') .css({marginBottom: '4px'}) @@ -367,12 +382,7 @@ pandora.ui.infoView = function(data) { }) .bindEvent({ submit: function(event) { - pandora.api.edit({ - id: data.id, - notes: event.value - }, function(result) { - // ... - }); + editMetadata('notes', event.value); } }) ) diff --git a/static/js/pandora/usersDialog.js b/static/js/pandora/usersDialog.js index 54e85f706..5875f37df 100644 --- a/static/js/pandora/usersDialog.js +++ b/static/js/pandora/usersDialog.js @@ -240,7 +240,7 @@ pandora.ui.usersDialog = function() { columnsRemovable: true, columnsVisible: true, items: pandora.api.findUsers, - keys: ['notes'], + keys: ['notes', 'groups'], max: -1, scrollbarVisible: true, sort: [{key: 'lastseen', operator: '-'}] @@ -490,6 +490,18 @@ pandora.ui.usersDialog = function() { .bindEvent({ submit: function(data) { + } + }), + Ox.Input({ + id: 'groups', + label: 'Groups', + labelWidth: 80, + value: user.groups.join(', '), + width: formWidth - 16 + }) + .bindEvent({ + submit: function(data) { + } }), Ox.Select({ @@ -542,6 +554,8 @@ pandora.ui.usersDialog = function() { data.level = event.data.value; } else if (event.id == 'newsletter') { data.newsletter = event.data.value; + } else if (event.id == 'groups') { + data.groups = event.data.value.split(', '); } else { data[event.id] = event.data.value; }