flake8 + map->[]
This commit is contained in:
parent
93734a4fbc
commit
fd9d3bdabf
2 changed files with 114 additions and 100 deletions
|
@ -142,10 +142,17 @@ def get_item(info, user=None, async=False):
|
|||
tasks.update_poster.delay(item.public_id)
|
||||
return item
|
||||
|
||||
def get_path(f, x): return f.path(x)
|
||||
def get_icon_path(f, x): return get_path(f, 'icon.jpg')
|
||||
def get_poster_path(f, x): return get_path(f, 'poster.jpg')
|
||||
def get_torrent_path(f, x): return get_path(f, 'torrent.torrent')
|
||||
def get_path(f, x):
|
||||
return f.path(x)
|
||||
|
||||
def get_icon_path(f, x):
|
||||
return get_path(f, 'icon.jpg')
|
||||
|
||||
def get_poster_path(f, x):
|
||||
return get_path(f, 'poster.jpg')
|
||||
|
||||
def get_torrent_path(f, x):
|
||||
return get_path(f, 'torrent.torrent')
|
||||
|
||||
class Item(models.Model):
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
@ -415,7 +422,8 @@ class Item(models.Model):
|
|||
self.update_sort()
|
||||
self.update_facets()
|
||||
if update_ids:
|
||||
for c in self.clips.all(): c.save()
|
||||
for c in self.clips.all():
|
||||
c.save()
|
||||
for a in self.annotations.all():
|
||||
public_id = a.public_id.split('/')[1]
|
||||
public_id = "%s/%s" % (self.public_id, public_id)
|
||||
|
@ -582,7 +590,7 @@ class Item(models.Model):
|
|||
if 'cast' in i and isinstance(i['cast'][0], basestring):
|
||||
i['cast'] = [i['cast']]
|
||||
if 'cast' in i and isinstance(i['cast'][0], list):
|
||||
i['cast'] = map(lambda x: {'actor': x[0], 'character': x[1]}, i['cast'])
|
||||
i['cast'] = [{'actor': x[0], 'character': x[1]} for x in i['cast']]
|
||||
|
||||
if 'connections' in i:
|
||||
i['connections'] = self.expand_connections()
|
||||
|
@ -798,10 +806,9 @@ class Item(models.Model):
|
|||
values = list(set(values))
|
||||
elif key == 'name':
|
||||
values = []
|
||||
for k in map(lambda x: x['id'],
|
||||
filter(lambda x: x.get('sortType') == 'person',
|
||||
settings.CONFIG['itemKeys'])):
|
||||
values += self.get(k, [])
|
||||
for k in settings.CONFIG['itemKeys']:
|
||||
if k.get('sortType') == 'person':
|
||||
values += self.get(k['id'], [])
|
||||
values = list(set(values))
|
||||
else:
|
||||
values = self.get(key, '')
|
||||
|
@ -1019,11 +1026,9 @@ class Item(models.Model):
|
|||
for item in sublist]
|
||||
elif key == 'name':
|
||||
current_values = []
|
||||
#FIXME: is there a better way to build name collection?
|
||||
for k in map(lambda x: x['id'],
|
||||
filter(lambda x: x.get('sortType') == 'person',
|
||||
settings.CONFIG['itemKeys'])):
|
||||
current_values += self.get(k, [])
|
||||
for k in settings.CONFIG['itemKeys']:
|
||||
if k.get('sortType') == 'person':
|
||||
current_values += self.get(k['id'], [])
|
||||
if not isinstance(current_values, list):
|
||||
if not current_values:
|
||||
current_values = []
|
||||
|
@ -1049,8 +1054,10 @@ class Item(models.Model):
|
|||
for a in self.annotations.filter(layer=key).distinct().values('value')]
|
||||
layer = utils.get_by_id(settings.CONFIG['layers'], key)
|
||||
if layer.get('type') == 'entity':
|
||||
current_values = [a['name']
|
||||
for a in Entity.objects.filter(id__in=[ox.fromAZ(i) for i in current_values]).values('name')]
|
||||
current_values = [
|
||||
a['name']
|
||||
for a in Entity.objects.filter(id__in=[ox.fromAZ(i) for i in current_values]).values('name')
|
||||
]
|
||||
current_values = [ox.decode_html(ox.strip_tags(v.replace('<br>', ' '))) for v in current_values]
|
||||
self.update_facet_values(key, current_values)
|
||||
|
||||
|
@ -1313,7 +1320,7 @@ class Item(models.Model):
|
|||
n = streams.count()
|
||||
for s in streams:
|
||||
self.data['volume'] += s.volume * s.duration
|
||||
color = map(lambda a, b: (a+b)/n, color, ox.image.getRGB(s.color or [0.0] * 3))
|
||||
color = [(a+b)/n for a, b in zip(color, ox.image.getRGB([1.0] * 3))]
|
||||
offset += s.duration
|
||||
self.data['hue'], self.data['saturation'], self.data['lightness'] = ox.image.getHSL(color)
|
||||
if offset:
|
||||
|
@ -1344,7 +1351,8 @@ class Item(models.Model):
|
|||
if self.json.get('posterRatio') != self.poster_width / self.poster_height:
|
||||
self.json = self.get_json()
|
||||
Item.objects.filter(id=self.id).update(json=self.json,
|
||||
poster_width=self.poster_width, poster_height=self.poster_height)
|
||||
poster_width=self.poster_width,
|
||||
poster_height=self.poster_height)
|
||||
|
||||
def prefered_poster_url(self):
|
||||
if settings.DATA_SERVICE:
|
||||
|
@ -1438,7 +1446,8 @@ class Item(models.Model):
|
|||
width, height = self.json['resolution']
|
||||
if width and height:
|
||||
pos = self.sort.duration / 2
|
||||
for p in map(int, [pos/2, pos, pos+pos/2]):
|
||||
for p in [pos/2, pos, pos+pos/2]:
|
||||
p = int(p)
|
||||
path = self.frame(p, height)
|
||||
if path:
|
||||
frames.append({
|
||||
|
|
|
@ -239,6 +239,7 @@ def find(request, data):
|
|||
if 'clip_qs' in query:
|
||||
r['clips'] = get_clips(query['clip_qs'].filter(item=m))
|
||||
return r
|
||||
|
||||
def only_p(m):
|
||||
r = {}
|
||||
if m:
|
||||
|
@ -267,9 +268,10 @@ def find(request, data):
|
|||
Sum('pixels'),
|
||||
Sum('size')
|
||||
)
|
||||
totals = [i['id']
|
||||
totals = [
|
||||
i['id']
|
||||
for i in settings.CONFIG['totals']
|
||||
if not 'capability' in i or has_capability(request.user, i['capability'])
|
||||
if 'capability' not in i or has_capability(request.user, i['capability'])
|
||||
]
|
||||
if 'duration' in totals:
|
||||
response['data']['duration'] = r['duration__sum']
|
||||
|
@ -284,7 +286,7 @@ def find(request, data):
|
|||
if 'size' in totals:
|
||||
response['data']['size'] = r['size__sum']
|
||||
for key in ('runtime', 'duration', 'pixels', 'size'):
|
||||
if key in totals and response['data'][key] == None:
|
||||
if key in totals and response['data'][key] is None:
|
||||
response['data'][key] = 0
|
||||
return render_to_json_response(response)
|
||||
actions.register(find)
|
||||
|
@ -305,7 +307,7 @@ def autocomplete(request, data):
|
|||
}
|
||||
see: autocompleteEntities
|
||||
'''
|
||||
if not 'range' in data:
|
||||
if 'range' not in data:
|
||||
data['range'] = [0, 10]
|
||||
op = data.get('operator', '=')
|
||||
|
||||
|
@ -313,7 +315,8 @@ def autocomplete(request, data):
|
|||
order_by = key.get('autocompleteSort', False)
|
||||
if order_by:
|
||||
for o in order_by:
|
||||
if o['operator'] != '-': o['operator'] = ''
|
||||
if o['operator'] != '-':
|
||||
o['operator'] = ''
|
||||
order_by = ['%(operator)ssort__%(key)s' % o for o in order_by]
|
||||
else:
|
||||
order_by = ['-items']
|
||||
|
@ -544,7 +547,7 @@ def edit(request, data):
|
|||
if item.editable(request.user):
|
||||
response = json_response(status=200, text='ok')
|
||||
if 'rightslevel' in data:
|
||||
if request.user.profile.capability('canEditRightsLevel') == True:
|
||||
if request.user.profile.capability('canEditRightsLevel'):
|
||||
item.level = int(data['rightslevel'])
|
||||
else:
|
||||
response = json_response(status=403, text='permission denied')
|
||||
|
@ -590,7 +593,7 @@ def remove(request, data):
|
|||
response = json_response({})
|
||||
item = get_object_or_404_json(models.Item, public_id=data['id'])
|
||||
user = request.user
|
||||
if user.profile.capability('canRemoveItems') == True or \
|
||||
if user.profile.capability('canRemoveItems') or \
|
||||
user.is_staff or \
|
||||
item.user == user or \
|
||||
item.groups.filter(id__in=user.groups.all()).count() > 0:
|
||||
|
@ -715,7 +718,7 @@ def lookup(request, data):
|
|||
r = {'id': i.public_id}
|
||||
for key in ('title', 'director', 'year'):
|
||||
value = i.get(key)
|
||||
if value != None:
|
||||
if value is not None:
|
||||
r[key] = value
|
||||
response = json_response(r)
|
||||
else:
|
||||
|
@ -847,6 +850,7 @@ def timeline(request, id, size, position=-1, format='jpg', mode=None):
|
|||
modes.pop(modes.index(mode))
|
||||
|
||||
prefix = os.path.join(item.timeline_prefix, 'timeline')
|
||||
|
||||
def timeline():
|
||||
timeline = '%s%s%sp' % (prefix, mode, size)
|
||||
if position > -1:
|
||||
|
@ -881,7 +885,7 @@ def download(request, id, resolution=None, format='webm'):
|
|||
r = item.merge_streams(video.name, resolution, format)
|
||||
if not r:
|
||||
return HttpResponseForbidden()
|
||||
elif r == True:
|
||||
elif r is True:
|
||||
response = HttpResponse(FileWrapper(video), content_type=content_type)
|
||||
response['Content-Length'] = os.path.getsize(video.name)
|
||||
else:
|
||||
|
@ -1147,7 +1151,7 @@ def oembed(request):
|
|||
embed_url = request.build_absolute_uri('/%s' % public_id)
|
||||
if url.startswith(embed_url):
|
||||
embed_url = url
|
||||
if not '#embed' in embed_url:
|
||||
if '#embed' not in embed_url:
|
||||
embed_url = '%s#embed' % embed_url
|
||||
|
||||
oembed = {}
|
||||
|
@ -1221,6 +1225,7 @@ def item_xml(request, id):
|
|||
j['layers'] = item.get_layers(request.user)
|
||||
if 'resolution' in j:
|
||||
j['resolution'] = {'width': j['resolution'][0], 'height': j['resolution'][1]}
|
||||
|
||||
def xmltree(root, key, data):
|
||||
if isinstance(data, list) or \
|
||||
isinstance(data, tuple):
|
||||
|
|
Loading…
Reference in a new issue