add groups to collections, edits and lists, towards #3063
This commit is contained in:
parent
15c5ad9d54
commit
85c5fafe0d
8 changed files with 143 additions and 19 deletions
21
pandora/itemlist/migrations/0002_list_groups.py
Normal file
21
pandora/itemlist/migrations/0002_list_groups.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.9.2 on 2017-12-31 12:33
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('auth', '0008_auto_20171231_1233'),
|
||||
('itemlist', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='list',
|
||||
name='groups',
|
||||
field=models.ManyToManyField(blank=True, related_name='lists', to='auth.Group'),
|
||||
),
|
||||
]
|
||||
|
|
@ -9,7 +9,7 @@ from glob import glob
|
|||
|
||||
from django.db import models
|
||||
from django.db.models import Max
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django.conf import settings
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
import ox
|
||||
|
|
@ -17,6 +17,7 @@ import ox
|
|||
from oxdjango.fields import DictField, TupleField
|
||||
|
||||
from archive import extract
|
||||
from user.utils import update_groups
|
||||
|
||||
from . import managers
|
||||
|
||||
|
|
@ -35,6 +36,7 @@ class List(models.Model):
|
|||
created = models.DateTimeField(auto_now_add=True)
|
||||
modified = models.DateTimeField(auto_now=True)
|
||||
user = models.ForeignKey(User, related_name='lists')
|
||||
groups = models.ManyToManyField(Group, blank=True, related_name='lists')
|
||||
name = models.CharField(max_length=255)
|
||||
status = models.CharField(max_length=20, default='private')
|
||||
_status = ['private', 'public', 'featured']
|
||||
|
|
@ -116,20 +118,24 @@ class List(models.Model):
|
|||
if user.is_anonymous():
|
||||
return False
|
||||
if self.user == user or \
|
||||
self.groups.filter(id__in=user.groups.all()).count() > 0 or \
|
||||
user.is_staff or \
|
||||
user.profile.capability('canEditFeaturedLists') == True:
|
||||
user.profile.capability('canEditFeaturedLists'):
|
||||
return True
|
||||
return False
|
||||
|
||||
def edit(self, data, user):
|
||||
if 'groups' in data:
|
||||
groups = data.pop('groups')
|
||||
update_groups(self, groups)
|
||||
for key in data:
|
||||
if key == 'query' and not data['query']:
|
||||
setattr(self, key, {"static":True})
|
||||
setattr(self, key, {"static": True})
|
||||
elif key == 'query' and isinstance(data[key], dict):
|
||||
setattr(self, key, data[key])
|
||||
elif key == 'type':
|
||||
if data[key] == 'static':
|
||||
self.query = {"static":True}
|
||||
self.query = {"static": True}
|
||||
self.type = 'static'
|
||||
else:
|
||||
self.type = 'smart'
|
||||
|
|
@ -198,14 +204,27 @@ class List(models.Model):
|
|||
if 'view' in data:
|
||||
self.view = data['view']
|
||||
if 'sort' in data:
|
||||
self.sort= tuple(data['sort'])
|
||||
self.sort = tuple(data['sort'])
|
||||
self.save()
|
||||
if 'posterFrames' in data:
|
||||
self.update_icon()
|
||||
|
||||
def json(self, keys=None, user=None):
|
||||
if not keys:
|
||||
keys=['id', 'name', 'user', 'type', 'query', 'status', 'subscribed', 'posterFrames', 'description', 'view']
|
||||
keys = [
|
||||
'description',
|
||||
'editable',
|
||||
'groups',
|
||||
'id',
|
||||
'name',
|
||||
'posterFrames',
|
||||
'query',
|
||||
'status',
|
||||
'subscribed',
|
||||
'type',
|
||||
'user',
|
||||
'view',
|
||||
]
|
||||
response = {}
|
||||
for key in keys:
|
||||
if key == 'items':
|
||||
|
|
@ -214,6 +233,10 @@ class List(models.Model):
|
|||
response[key] = self.get_id()
|
||||
elif key == 'user':
|
||||
response[key] = self.user.username
|
||||
elif key == 'groups':
|
||||
response[key] = [g.name for g in self.groups.all()]
|
||||
elif key == 'editable':
|
||||
response[key] = self.editable(user)
|
||||
elif key == 'query':
|
||||
if not self.query.get('static', False):
|
||||
response[key] = self.query
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue