41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import ox
|
|
import json
|
|
|
|
def load(data_json):
|
|
|
|
def reset_table(table_name):
|
|
cursor = connection.cursor()
|
|
sql = "select setval('%s_id_seq', 1, false)" % table_name
|
|
cursor.execute(sql)
|
|
|
|
from django.db import connection, transaction
|
|
import item.models as models
|
|
import archive.models
|
|
import os
|
|
with transaction.atomic():
|
|
archive.models.File.objects.all().delete()
|
|
archive.models.Instance.objects.all().delete()
|
|
archive.models.Volume.objects.all().delete()
|
|
models.Item.objects.all().delete()
|
|
reset_table(archive.models.File._meta.db_table)
|
|
reset_table(archive.models.Instance._meta.db_table)
|
|
reset_table(archive.models.Volume._meta.db_table)
|
|
reset_table(models.Item._meta.db_table)
|
|
with transaction.atomic():
|
|
os.system('rm -r /srv/pandora/data/media')
|
|
os.system('rm -r /srv/pandora/data/items')
|
|
|
|
films = json.load(open(data_json))
|
|
for data in sorted(films, key=lambda f: (f['year'], f['title'], f.get('director', []))):
|
|
item = models.Item()
|
|
item.data = data
|
|
item.save()
|
|
item.make_poster()
|
|
item.make_icon()
|
|
item.level = 2
|
|
item.save()
|
|
print(item)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print('please import from ./manage.py and run import_json.load(path_to_json)')
|