py3 filter->list(filter

This commit is contained in:
j 2017-02-16 14:24:51 +01:00
parent 2eafeff5f2
commit 12f3901c9a
17 changed files with 48 additions and 48 deletions

View file

@ -31,7 +31,7 @@ class Command(BaseCommand):
username, public_id, layer_id, filename = args
user = User.objects.get(username=username)
item = Item.objects.get(public_id=public_id)
layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])[0]
layer = list(filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers']))[0]
if filename.endswith('.vtt'):
annotations = ox.vtt.load(filename)
@ -53,7 +53,7 @@ class Command(BaseCommand):
value=a['value'])
annotation.save()
#update facets if needed
if filter(lambda f: f['id'] == layer_id, settings.CONFIG['filters']):
if list(filter(lambda f: f['id'] == layer_id, settings.CONFIG['filters'])):
item.update_layer_facet(layer_id)
Item.objects.filter(id=item.id).update(modified=annotation.modified)
annotation.item.modified = annotation.modified

View file

@ -36,7 +36,7 @@ def get_super_matches(obj, model):
def get_matches(obj, model, layer_type, qs=None):
super_matches = obj.get_super_matches()
exact = [l['id'] for l in filter(lambda l: l['type'] == layer_type, settings.CONFIG['layers'])]
exact = [l['id'] for l in list(filter(lambda l: l['type'] == layer_type, settings.CONFIG['layers']))]
if exact:
q = Q(value__iexact=obj.name)
for name in obj.alternativeNames:
@ -46,7 +46,7 @@ def get_matches(obj, model, layer_type, qs=None):
f = None
has_type = 'has%ss' % layer_type.capitalize()
contains = [l['id'] for l in filter(lambda l: l.get(has_type), settings.CONFIG['layers'])]
contains = [l['id'] for l in list(filter(lambda l: l.get(has_type), settings.CONFIG['layers']))]
if contains:
name = ox.decode_html(obj.name)
name = unicodedata.normalize('NFKD', name).lower()

View file

@ -18,7 +18,7 @@ def add_annotations(data):
from user.models import User
item = Item.objects.get(public_id=data['item'])
layer_id = data['layer']
layer = filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers'])
layer = list(filter(lambda l: l['id'] == layer_id, settings.CONFIG['layers']))
if not layer:
return False
else:
@ -61,7 +61,7 @@ def update_item(id, force=False):
Clip.objects.filter(item__id=a.item.id, annotations__id=None).delete()
#update facets if needed
with transaction.atomic():
if filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys']):
if list(filter(lambda f: f['id'] == a.layer and f.get('filter'), settings.CONFIG['itemKeys'])):
a.item.update_layer_facet(a.layer)
Item.objects.filter(id=a.item.id).update(modified=a.modified)
a.item.modified = a.modified

View file

@ -106,7 +106,7 @@ def update(request, data):
file__available=False,
file__wanted=True)]
if filter(lambda l: l['id'] == 'subtitles', settings.CONFIG['layers']):
if list(filter(lambda l: l['id'] == 'subtitles', settings.CONFIG['layers'])):
qs = files.filter(
file__is_subtitle=True,
file__available=False

View file

@ -135,7 +135,7 @@ class ClipManager(Manager):
layer_ids = [k['id'] for k in settings.CONFIG['layers']]
keys = layer_ids + ['annotations', 'text', '*']
conditions = data.get('query', {}).get('conditions', [])
conditions = filter(lambda c: c['key'] in keys, conditions)
conditions = list(filter(lambda c: c['key'] in keys, conditions))
operator = data.get('query', {}).get('operator', '&')
def parse(condition):
@ -194,7 +194,7 @@ class ClipManager(Manager):
if 'keys' in data:
layer_ids = [k['id'] for k in settings.CONFIG['layers']]
for l in filter(lambda k: k in layer_ids, data['keys']):
for l in list(filter(lambda k: k in layer_ids, data['keys'])):
qs = qs.filter(**{l: True})
#anonymous can only see public clips
if not user or user.is_anonymous():

View file

@ -102,8 +102,8 @@ def findClips(request, data):
entity_layer_ids = [k['id'] for k in layers if k['type'] == 'entity']
subtitles = utils.get_by_key(layers, 'isSubtitles', True)
layer_ids = [k['id'] for k in layers]
keys = filter(lambda k: k not in layer_ids + ['annotations'], data['keys'])
if filter(lambda k: k not in models.Clip.clip_keys, keys):
keys = list(filter(lambda k: k not in layer_ids + ['annotations'], data['keys']))
if list(filter(lambda k: k not in models.Clip.clip_keys, keys)):
qs = qs.select_related('item__sort')
clips = {}
@ -151,7 +151,7 @@ def findClips(request, data):
clip__in=clips)
add_annotations('annotations', aqs, True)
for layer in filter(lambda l: l in keys, layer_ids):
for layer in list(filter(lambda l: l in keys, layer_ids)):
aqs = Annotation.objects.filter(layer=layer, clip__in=clips)
add_annotations(layer, aqs)
elif 'position' in query:

View file

@ -104,7 +104,7 @@ class Document(models.Model):
def update_facet_values(self, key, current_values):
current_sortvalues = set([value.lower() for value in current_values])
saved_values = [i.value.lower() for i in Facet.objects.filter(document=self, key=key)]
removed_values = filter(lambda i: i not in current_sortvalues, saved_values)
removed_values = list(filter(lambda i: i not in current_sortvalues, saved_values))
if removed_values:
q = Q()
@ -208,7 +208,7 @@ class Document(models.Model):
value = len(value.split(' ')) if value else 0
return value
for key in filter(lambda k: k.get('sort', False), settings.CONFIG['documentKeys']):
for key in list(filter(lambda k: k.get('sort', False), settings.CONFIG['documentKeys'])):
name = key['id']
if name not in self.base_keys:
source = name
@ -737,7 +737,7 @@ attrs = {
'document': models.OneToOneField('Document', related_name='sort', primary_key=True),
'created': models.DateTimeField(null=True, blank=True, db_index=True),
}
for key in filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['documentKeys']):
for key in list(filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['documentKeys'])):
name = key['id']
sort_type = key.get('sortType', key['type'])
if isinstance(sort_type, list):

View file

@ -231,8 +231,8 @@ def getEvents(request, data):
see: getPlaces
'''
response = json_response({})
layers = [l['id'] for l in filter(lambda l: l['type'] == 'event',
settings.CONFIG['layers'])]
layers = [l['id'] for l in list(filter(lambda l: l['type'] == 'event',
settings.CONFIG['layers']))]
items = models.Annotation.objects.filter(layer__in=layers,
events__id=None).order_by('value')
items = items.values('value').annotate(Count('value'))

View file

@ -81,7 +81,7 @@ def get_item(info, user=None):
'director': info.get('director', []),
}
if filter(lambda k: k['id'] == 'year', settings.CONFIG['itemKeys']):
if list(filter(lambda k: k['id'] == 'year', settings.CONFIG['itemKeys'])):
item_data['year'] = info.get('year', '') or ''
# add additional item metadata parsed from path
@ -245,16 +245,16 @@ class Item(models.Model):
if 'groups' in data:
groups = data.pop('groups')
if isinstance(groups, list):
groups = filter(lambda g: g.strip(), groups)
groups = list(filter(lambda g: g.strip(), groups))
groups = [ox.escape_html(g) for g in groups]
for g in self.groups.exclude(name__in=groups):
self.groups.remove(g)
current_groups = [g.name for g in self.groups.all()]
for g in filter(lambda g: g not in current_groups, groups):
for g in list(filter(lambda g: g not in current_groups, groups)):
group, created = Group.objects.get_or_create(name=g)
self.groups.add(group)
keys = [k['id'] for k in
filter(lambda i: i.get('description'), settings.CONFIG['itemKeys'])]
list(filter(lambda i: i.get('description'), settings.CONFIG['itemKeys']))]
for k in keys:
key = '%sdescription' % k
if key in data:
@ -299,7 +299,7 @@ class Item(models.Model):
else:
self.data[key] = ox.escape_html(data[key])
p = self.save()
if not settings.USE_IMDB and filter(lambda k: k in self.poster_keys, data):
if not settings.USE_IMDB and list(filter(lambda k: k in self.poster_keys, data)):
p = tasks.update_poster.delay(self.public_id)
return p
@ -332,7 +332,7 @@ class Item(models.Model):
if i['id'] in known:
i['item'] = i['id']
i['title'] = known[i['id']]
c[t] = filter(lambda x: x['title'], c[t])
c[t] = list(filter(lambda x: x['title'], c[t]))
if not c[t]:
del c[t]
return c
@ -409,7 +409,7 @@ class Item(models.Model):
# update defaults
if settings.USE_IMDB:
defaults = filter(lambda k: 'default' in k, settings.CONFIG['itemKeys'])
defaults = list(filter(lambda k: 'default' in k, settings.CONFIG['itemKeys']))
for k in defaults:
if len(self.public_id) == 7:
if k['id'] in self.data and self.data[k['id']] == k['default']:
@ -657,16 +657,16 @@ class Item(models.Model):
i['posterFrame'] = self.poster_frame
dkeys = [k['id'] for k in
filter(lambda i: i.get('description'), settings.CONFIG['itemKeys'])]
list(filter(lambda i: i.get('description'), settings.CONFIG['itemKeys']))]
if keys:
dkeys = filter(lambda k: k in keys, dkeys)
dkeys = list(filter(lambda k: k in keys, dkeys))
for key in dkeys:
k = list(filter(lambda i: i['id'] == key, settings.CONFIG['itemKeys']))
if isinstance((k and k[0].get('type') or ''), list):
i['%sdescription' % key] = {}
if key == 'name':
values = []
for ikey in filter(lambda i: i.get('sortType') == 'person', settings.CONFIG['itemKeys']):
for ikey in list(filter(lambda i: i.get('sortType') == 'person', settings.CONFIG['itemKeys'])):
values += i.get(ikey['id'], [])
values = list(set(values))
else:
@ -822,8 +822,8 @@ class Item(models.Model):
elif key == 'character':
values = self.get('cast', '')
if values:
values = filter(lambda x: x.strip(),
[f['character'] for f in values])
values = list(filter(lambda x: x.strip(),
[f['character'] for f in values]))
values = list(set(values))
elif key == 'name':
values = []
@ -976,7 +976,7 @@ class Item(models.Model):
s.timesaccessed = 0
s.accessed = self.accessed.aggregate(Max('access'))['access__max']
for key in filter(lambda k: k.get('sort', False), settings.CONFIG['itemKeys']):
for key in list(filter(lambda k: k.get('sort', False), settings.CONFIG['itemKeys'])):
name = key['id']
source = name
sort_type = key.get('sortType', key['type'])
@ -1042,8 +1042,8 @@ class Item(models.Model):
if at:
current_values += [a[0] for a in at]
elif key == 'character':
current_values = filter(lambda x: x.strip(),
[f['character'] for f in self.get('cast', [])])
current_values = list(filter(lambda x: x.strip(),
[f['character'] for f in self.get('cast', [])]))
current_values = [item for sublist in [x.split(' / ') for x in current_values]
for item in sublist]
elif key == 'name':
@ -1089,7 +1089,7 @@ class Item(models.Model):
def update_facet_values(self, key, current_values):
current_sortvalues = set([value.lower() for value in current_values])
saved_values = [i.value.lower() for i in Facet.objects.filter(item=self, key=key)]
removed_values = filter(lambda i: i not in current_sortvalues, saved_values)
removed_values = list(filter(lambda i: i not in current_sortvalues, saved_values))
if removed_values:
q = Q()
@ -1736,7 +1736,7 @@ attrs = {
'height': models.BigIntegerField(null=True, blank=True, db_index=True),
'created': models.DateTimeField(null=True, blank=True, db_index=True),
}
for key in filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['itemKeys']):
for key in list(filter(lambda k: k.get('sort', False) or k['type'] in ('integer', 'time', 'float', 'date', 'enum'), settings.CONFIG['itemKeys'])):
name = key['id']
name = {'id': 'public_id'}.get(name, name)
sort_type = key.get('sortType', key['type'])

View file

@ -26,7 +26,7 @@ def cronjob(**kwargs):
def update_random_sort():
from . import models
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
if list(filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys'])):
random.seed()
ids = [f['item'] for f in models.ItemSort.objects.values('item')]
random.shuffle(ids)
@ -36,7 +36,7 @@ def update_random_sort():
n += 1
def update_random_clip_sort():
if filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys']):
if list(filter(lambda f: f['id'] == 'random', settings.CONFIG['itemKeys'])):
with transaction.atomic():
cursor = connection.cursor()
for row in (

View file

@ -116,7 +116,7 @@ def join_tiles(source_paths, durations, target_path):
offset = 0
for i, path in enumerate(source_paths):
file_info = map(get_file_info, os.listdir(path))
file_info = filter(lambda x: x is not None, file_info)
file_info = list(filter(lambda x: x is not None, file_info))
files = {}
for info in sorted(file_info, key=lambda x: x['index']):
mode = info['mode']
@ -218,7 +218,7 @@ def split_tiles(path, paths, durations):
def is_timeline_file(file_name):
return file_name.startswith('timeline') and file_name.endswith('.png')
file_names = filter(is_timeline_file, os.listdir(path))
file_names = list(filter(is_timeline_file, os.listdir(path)))
tiles = {}
for file_name in file_names:
mode = re.split('\d+', file_name[8:])[0]

View file

@ -729,7 +729,7 @@ def lookup(request, data):
i = None
if 'id' in data:
i = models.Item.objects.get(public_id=data['id'])
elif not filter(None, [d not in ('title', 'year', 'director') for d in data.keys()]):
elif not list(filter(None, [d not in ('title', 'year', 'director') for d in data.keys()])):
qs = models.Item.objects.find({'query': {
'conditions': [
{'key': key, 'value': data[key], 'operator': '=='} for key in data

View file

@ -108,7 +108,7 @@ class ApiActions(dict):
else:
f = self[name]
if name != 'api' and hasattr(f, 'func_closure') and f.func_closure:
fc = filter(lambda c: hasattr(c.cell_contents, '__call__'), f.func_closure)
fc = list(filter(lambda c: hasattr(c.cell_contents, '__call__'), f.func_closure))
f = fc[len(fc)-1].cell_contents
if PY2:
info = f.func_code.co_filename[len(settings.PROJECT_ROOT)+1:]

View file

@ -121,7 +121,7 @@ def editPlace(request, data):
names = [names]
names = [ox.escape_html(n) for n in names]
alternative_names = [ox.escape_html(n) for n in data.get('alternativeNames', [])]
alternative_names = filter(lambda n: n.strip(), alternative_names)
alternative_names = list(filter(lambda n: n.strip(), alternative_names))
if place.editable(request.user):
conflict = False
conflict_names = []
@ -284,8 +284,8 @@ def getPlaces(request, data):
see: getEvents
'''
response = json_response({})
layers = [l['id'] for l in filter(lambda l: l['type'] == 'place',
settings.CONFIG['layers'])]
layers = [l['id'] for l in list(filter(lambda l: l['type'] == 'place',
settings.CONFIG['layers']))]
items = models.Annotation.objects.filter(layer__in=layers,
places__id=None).order_by('value')
items = items.values('value').annotate(Count('value'))

View file

@ -60,7 +60,7 @@ def get_sequences(path, position=0):
sequences[mode] = []
position_start = position
fps = 25
file_names = filter(lambda x: 'timelinedata8p' in x, os.listdir(path))
file_names = list(filter(lambda x: 'timelinedata8p' in x, os.listdir(path)))
file_names = sorted(file_names, key=lambda x: int(x[14:-4]))
file_names = list(map(lambda x: path + x, file_names))
for file_name in file_names:
@ -84,7 +84,7 @@ class DataTimeline():
fps = 25
def __init__(self, path):
file_names = filter(lambda x: 'timelinedata8p' in x, os.listdir(path))
file_names = list(filter(lambda x: 'timelinedata8p' in x, os.listdir(path)))
file_names = sorted(file_names, key=lambda x: int(x[14:-4]))
file_names = list(map(lambda x: path + x, file_names))
self.file_names = file_names

View file

@ -28,7 +28,7 @@ def update_statistics():
for i in models.SessionData.objects.filter(level__gte=0).values('session_key')]
for chunk in chunker(ids, 100, None):
chunk = filter(None, chunk)
chunk = list(filter(None, chunk))
for u in models.SessionData.objects.filter(pk__in=chunk):
stats.add(u.json())
Settings.set('statistics', stats)

View file

@ -370,12 +370,12 @@ def editUser(request, data):
if 'groups' in data:
groups = data['groups']
if isinstance(groups, list):
groups = filter(lambda g: g.strip(), groups)
groups = list(filter(lambda g: g.strip(), groups))
groups = [ox.escape_html(g) for g in groups]
for g in user.groups.exclude(name__in=groups):
user.groups.remove(g)
current_groups = [g.name for g in user.groups.all()]
for g in filter(lambda g: g not in current_groups, groups):
for g in list(filter(lambda g: g not in current_groups, groups)):
group, created = Group.objects.get_or_create(name=g)
user.groups.add(group)
if 'username' in data: