item/user groups
This commit is contained in:
parent
bf518ae603
commit
4e6c2250c9
6 changed files with 52 additions and 14 deletions
|
@ -209,10 +209,13 @@ class Item(models.Model):
|
||||||
del data['id']
|
del data['id']
|
||||||
if 'groups' in data:
|
if 'groups' in data:
|
||||||
groups = data.pop('groups')
|
groups = data.pop('groups')
|
||||||
self.groups.exclude(name__in=groups).delete()
|
if isinstance(groups, list):
|
||||||
for g in groups:
|
groups = filter(lambda g: g.strip(), groups)
|
||||||
group, created = Group.objects.get_or_create(name=g)
|
self.groups.exclude(name__in=groups).delete()
|
||||||
self.groups.add(group)
|
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:
|
for key in data:
|
||||||
self.data[key] = data[key]
|
self.data[key] = data[key]
|
||||||
return self.save()
|
return self.save()
|
||||||
|
|
|
@ -404,6 +404,7 @@ def get(request):
|
||||||
if not data['keys'] or 'notes' in data['keys'] \
|
if not data['keys'] or 'notes' in data['keys'] \
|
||||||
and request.user.get_profile().capability('canEditMetadata'):
|
and request.user.get_profile().capability('canEditMetadata'):
|
||||||
info['notes'] = item.notes
|
info['notes'] = item.notes
|
||||||
|
info['groups'] = [g.name for g in item.groups.all()]
|
||||||
response['data'] = info
|
response['data'] = info
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='permission denied')
|
response = json_response(status=403, text='permission denied')
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import copy
|
import copy
|
||||||
from datetime import datetime
|
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 import models
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -149,6 +149,7 @@ class SessionData(models.Model):
|
||||||
p = self.user.get_profile()
|
p = self.user.get_profile()
|
||||||
j['disabled'] = not self.user.is_active
|
j['disabled'] = not self.user.is_active
|
||||||
j['email'] = self.user.email
|
j['email'] = self.user.email
|
||||||
|
j['groups'] = [g.name for g in self.user.groups.all()]
|
||||||
j['level'] = p.get_level()
|
j['level'] = p.get_level()
|
||||||
j['newsletter'] = p.newsletter
|
j['newsletter'] = p.newsletter
|
||||||
j['notes'] = p.notes
|
j['notes'] = p.notes
|
||||||
|
|
|
@ -334,6 +334,15 @@ def editUser(request):
|
||||||
profile.notes = data['notes']
|
profile.notes = data['notes']
|
||||||
if 'newsletter' in data:
|
if 'newsletter' in data:
|
||||||
profile.newsletter = data['newsletter']
|
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 'username' in data:
|
||||||
if models.User.objects.filter(
|
if models.User.objects.filter(
|
||||||
username__iexact=data['username']).exclude(id=user.id).count()>0:
|
username__iexact=data['username']).exclude(id=user.id).count()>0:
|
||||||
|
|
|
@ -264,7 +264,7 @@ pandora.ui.infoView = function(data) {
|
||||||
)
|
)
|
||||||
.appendTo($text);
|
.appendTo($text);
|
||||||
|
|
||||||
var list_keys = ['language', 'topic', 'director', 'cinematographer', 'features'];
|
var list_keys = ['language', 'topic', 'director', 'cinematographer', 'features', 'groups'];
|
||||||
$('<div>').html('<br>').appendTo($text);
|
$('<div>').html('<br>').appendTo($text);
|
||||||
[
|
[
|
||||||
'date',
|
'date',
|
||||||
|
@ -284,7 +284,6 @@ pandora.ui.infoView = function(data) {
|
||||||
.html(
|
.html(
|
||||||
formatKey({
|
formatKey({
|
||||||
categorty: 'categories',
|
categorty: 'categories',
|
||||||
user: 'contributor'
|
|
||||||
}[key] || key).replace('</span>', ' </span>')
|
}[key] || key).replace('</span>', ' </span>')
|
||||||
)
|
)
|
||||||
.appendTo($div);
|
.appendTo($div);
|
||||||
|
@ -352,6 +351,22 @@ pandora.ui.infoView = function(data) {
|
||||||
// Notes -------------------------------------------------------------------
|
// Notes -------------------------------------------------------------------
|
||||||
|
|
||||||
if (canEdit) {
|
if (canEdit) {
|
||||||
|
$('<div>')
|
||||||
|
.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);
|
||||||
|
|
||||||
$('<div>')
|
$('<div>')
|
||||||
.css({marginBottom: '4px'})
|
.css({marginBottom: '4px'})
|
||||||
|
@ -367,12 +382,7 @@ pandora.ui.infoView = function(data) {
|
||||||
})
|
})
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
submit: function(event) {
|
submit: function(event) {
|
||||||
pandora.api.edit({
|
editMetadata('notes', event.value);
|
||||||
id: data.id,
|
|
||||||
notes: event.value
|
|
||||||
}, function(result) {
|
|
||||||
// ...
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
@ -240,7 +240,7 @@ pandora.ui.usersDialog = function() {
|
||||||
columnsRemovable: true,
|
columnsRemovable: true,
|
||||||
columnsVisible: true,
|
columnsVisible: true,
|
||||||
items: pandora.api.findUsers,
|
items: pandora.api.findUsers,
|
||||||
keys: ['notes'],
|
keys: ['notes', 'groups'],
|
||||||
max: -1,
|
max: -1,
|
||||||
scrollbarVisible: true,
|
scrollbarVisible: true,
|
||||||
sort: [{key: 'lastseen', operator: '-'}]
|
sort: [{key: 'lastseen', operator: '-'}]
|
||||||
|
@ -490,6 +490,18 @@ pandora.ui.usersDialog = function() {
|
||||||
.bindEvent({
|
.bindEvent({
|
||||||
submit: function(data) {
|
submit: function(data) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Ox.Input({
|
||||||
|
id: 'groups',
|
||||||
|
label: 'Groups',
|
||||||
|
labelWidth: 80,
|
||||||
|
value: user.groups.join(', '),
|
||||||
|
width: formWidth - 16
|
||||||
|
})
|
||||||
|
.bindEvent({
|
||||||
|
submit: function(data) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Ox.Select({
|
Ox.Select({
|
||||||
|
@ -542,6 +554,8 @@ pandora.ui.usersDialog = function() {
|
||||||
data.level = event.data.value;
|
data.level = event.data.value;
|
||||||
} else if (event.id == 'newsletter') {
|
} else if (event.id == 'newsletter') {
|
||||||
data.newsletter = event.data.value;
|
data.newsletter = event.data.value;
|
||||||
|
} else if (event.id == 'groups') {
|
||||||
|
data.groups = event.data.value.split(', ');
|
||||||
} else {
|
} else {
|
||||||
data[event.id] = event.data.value;
|
data[event.id] = event.data.value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue