40 lines
1.2 KiB
Python
40 lines
1.2 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
|
|
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)
|
|
transaction.commit_unless_managed()
|
|
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 films:
|
|
item = models.Item()
|
|
item.data = data
|
|
item.save()
|
|
item.make_poster(True)
|
|
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)'
|
|
|