2013-07-01 10:06:47 +00:00
|
|
|
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()
|
2016-04-29 11:12:05 +00:00
|
|
|
os.system('rm -r /srv/pandora/data/media')
|
2013-07-01 10:06:47 +00:00
|
|
|
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__':
|
2013-08-08 08:08:17 +00:00
|
|
|
print 'please import from ./manage.py and run import_json.load(path_to_json)'
|
2013-07-01 10:06:47 +00:00
|
|
|
|