import_references.py 956 B

1234567891011121314151617181920212223242526
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals, division, print_function
  3. import json
  4. from django.core.management.base import BaseCommand, CommandError
  5. from panorama.models import Panorama, ReferencePoint, Reference
  6. class Command(BaseCommand):
  7. args = '<references.json>'
  8. help = 'Convert and import references exported from the old PHP-based celutz'
  9. def handle(self, *args, **options):
  10. if len(args) < 1:
  11. raise CommandError('Usage: import_references <references.json>')
  12. with open(args[0]) as f:
  13. for ref in json.load(f):
  14. pano = Panorama.objects.get(name=ref["pano"])
  15. refpoint = ReferencePoint.objects.get(name=ref["refpoint"])
  16. x = int(ref["x"] * pano.image_width)
  17. y = int((ref["y"] + 0.5) * pano.image_height)
  18. r = Reference(reference_point=refpoint, panorama=pano, x=x, y=y)
  19. r.save()