Added children to "library.related"
This commit is contained in:
@@ -55,7 +55,7 @@ class Library(LibraryBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def related(self, media):
|
def related(self, media):
|
||||||
result = {media['type']: media}
|
result = {self.key(media['type']): media}
|
||||||
|
|
||||||
db = get_db()
|
db = get_db()
|
||||||
cur = media
|
cur = media
|
||||||
@@ -63,9 +63,17 @@ class Library(LibraryBase):
|
|||||||
while cur and cur.get('parent_id'):
|
while cur and cur.get('parent_id'):
|
||||||
cur = db.get('id', cur['parent_id'])
|
cur = db.get('id', cur['parent_id'])
|
||||||
|
|
||||||
parts = cur['type'].split('.')
|
result[self.key(cur['type'])] = cur
|
||||||
|
|
||||||
result[parts[-1]] = cur
|
children = db.get_many('media_children', media['_id'], with_doc = True)
|
||||||
|
|
||||||
|
for item in children:
|
||||||
|
key = self.key(item['doc']['type']) + 's'
|
||||||
|
|
||||||
|
if key not in result:
|
||||||
|
result[key] = []
|
||||||
|
|
||||||
|
result[key].append(item['doc'])
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -94,8 +102,7 @@ class Library(LibraryBase):
|
|||||||
|
|
||||||
# Build children arrays
|
# Build children arrays
|
||||||
for item in items:
|
for item in items:
|
||||||
parts = item['doc']['type'].split('.')
|
key = self.key(item['doc']['type']) + 's'
|
||||||
key = parts[-1] + 's'
|
|
||||||
|
|
||||||
if key not in result:
|
if key not in result:
|
||||||
result[key] = {}
|
result[key] = {}
|
||||||
@@ -115,3 +122,7 @@ class Library(LibraryBase):
|
|||||||
result['releases'] = fireEvent('release.for_media', result['_id'], single = True)
|
result['releases'] = fireEvent('release.for_media', result['_id'], single = True)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def key(self, media_type):
|
||||||
|
parts = media_type.split('.')
|
||||||
|
return parts[-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user