add per list export_json
This commit is contained in:
parent
0cd6032816
commit
b961086475
4 changed files with 31 additions and 12 deletions
|
|
@ -337,6 +337,24 @@ class List(db.Model):
|
|||
def create_symlinks(self):
|
||||
pass
|
||||
|
||||
def export_json(self, path=None):
|
||||
if not path:
|
||||
if self.name:
|
||||
name = os.path.join('Lists', self.name)
|
||||
else:
|
||||
name = 'Books'
|
||||
path = os.path.join(os.path.expanduser(settings.preferences['libraryPath']), name, 'library.json')
|
||||
from utils import _to_json
|
||||
items = []
|
||||
for i in self.get_items():
|
||||
j = i.json()
|
||||
for f in i.files:
|
||||
j['path'] = f.path
|
||||
break
|
||||
items.append(j)
|
||||
with open(path, 'w') as f:
|
||||
json.dump(items, f, indent=1, default=_to_json, ensure_ascii=False, sort_keys=True)
|
||||
|
||||
class Metadata(db.Model):
|
||||
__tablename__ = 'user_metadata'
|
||||
|
||||
|
|
@ -475,6 +493,7 @@ def export_list(data):
|
|||
for f in list(existing_files - new_files):
|
||||
os.unlink(f)
|
||||
utils.remove_empty_folders(prefix)
|
||||
self.export_json(os.path.join(prefix, 'library.json'))
|
||||
trigger_event('activity', {
|
||||
'activity': 'export',
|
||||
'progress': [count, count],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue