Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed simpleImport setting folders after schema change

  • Loading branch information...
commit b1ceb6beeb6a404f6bb58ad456cadb9c4ed2e033 1 parent 16d5202
@trey0 trey0 authored
Showing with 13 additions and 3 deletions.
  1. +9 −0 geocamLens/bin/simpleImport.py
  2. +4 −3 geocamLens/models.py
View
9 geocamLens/bin/simpleImport.py
@@ -21,6 +21,7 @@
from django.core.exceptions import ObjectDoesNotExist
from geocamCore.models import Feature
+from geocamFolder.models import Folder
from geocamLens.UploadClient import UploadClient
from geocamLens.models import Photo
@@ -54,6 +55,13 @@ def importImageDirect(imagePath, attributes):
photo = Photo()
photo.readImportVals(storePath=imagePath, uploadImageFormData=attributes)
photo.save()
+
+ # must defer saving m2m fields until after base object is in db
+ for fieldName in ('folders',):
+ val = getattr(photo, '_' + fieldName)
+ setattr(photo, fieldName, val)
+ delattr(photo, '_' + fieldName)
+
photo.process(importFile=imagePath)
photo.save()
print 'processed', unicode(photo)
@@ -67,6 +75,7 @@ def importDir(opts, d, uploadClient):
d = os.path.realpath(d)
folderName = os.path.basename(d)
+ Folder.objects.get_or_create(name=folderName)
photosToUpload = []
View
7 geocamLens/models.py
@@ -33,6 +33,7 @@
from geocamUtil.FileUtil import mkdirP
from geocamUtil import TimeUtil
import geocamCore.models as coreModels
+from geocamFolder.models import Folder
from geocamLens import settings
@@ -299,11 +300,11 @@ def getUploadImageFormVals(self, formData):
folderName = formData.get('folder', None)
folder = None
if folderName:
- folderMatches = coreModels.Folder.objects.filter(name=folderName)
+ folderMatches = Folder.objects.filter(name=folderName)
if folderMatches:
folder = folderMatches[0]
if folder == None:
- folder = coreModels.Folder.objects.get(id=1)
+ folder = Folder.objects.get(id=1)
tzone = pytz.timezone(settings.TIME_ZONE)
timestampStr = Xmp.checkMissing(formData.get('cameraTime', None))
@@ -334,7 +335,7 @@ def getUploadImageFormVals(self, formData):
altitude=formData.get('altitude', None),
altitudeRef=formData.get('altitudeRef', None),
timestamp=timestampUtc,
- folder=folder,
+ _folders=[folder],
yaw=yaw,
yawRef=yawRef)
formVals = dict([(k, v) for k, v in formVals0.iteritems()
Please sign in to comment.
Something went wrong with that request. Please try again.