本文整理汇总了Python中forms.UploadFileForm.getResource方法的典型用法代码示例。如果您正苦于以下问题:Python UploadFileForm.getResource方法的具体用法?Python UploadFileForm.getResource怎么用?Python UploadFileForm.getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.UploadFileForm
的用法示例。
在下文中一共展示了UploadFileForm.getResource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveImage
# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import getResource [as 别名]
def saveImage(request):
"""
Image drag and drop, saves the files and to the database.
"""
if request.method == "POST":
timeMark = time.time()
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
# create and save a single image obj
uploadedFile = request.FILES["file"]
newImage = SINGLE_IMAGE_MODEL.get()(file=uploadedFile)
form_tz = form.getTimezone()
resource = form.getResource()
exifData = getExifData(newImage)
# save image dimensions and file size
try:
newImage.width = int(getExifValue(exifData, "ExifImageWidth"))
newImage.height = int(getExifValue(exifData, "ExifImageHeight"))
except:
pass
newImage.fileSizeBytes = uploadedFile.size
# get exif time
exifTime = None
exifTimeString = getExifValue(exifData, "DateTimeOriginal")
if not exifTimeString:
exifTimeString = getExifValue(exifData, "DateTime")
if exifTimeString:
exifTime = datetime.strptime(str(exifTimeString), "%Y:%m:%d %H:%M:%S")
if (form_tz != pytz.utc) and exifTime:
localized_time = form_tz.localize(exifTime)
exifTime = TimeUtil.timeZoneToUtc(localized_time)
else:
exifTime = exifTime.replace(tzinfo=pytz.utc)
else:
# read the time from the last modified time that we pushed in from imageUpload.js
if "HTTP_LASTMOD" in request.META:
modtimesString = request.META["HTTP_LASTMOD"]
if modtimesString:
modtime = None
theImages = modtimesString.split(",")
for i in theImages:
k, v = i.split("||")
if k == str(uploadedFile.name):
modtime = datetime.fromtimestamp(int(v) / 1000)
break
if modtime:
localized_time = form_tz.localize(modtime)
exifTime = TimeUtil.timeZoneToUtc(localized_time)
if not exifTime:
exifTime = datetime.now(pytz.utc)
# create a new image set instance
author = None
if request.user.is_authenticated():
author = request.user # set user as image author
elif "username" in request.POST:
try:
username = str(request.POST["username"])
author = User.objects.get(username=username)
except:
author = User.objects.get(username="camera")
newImageSet = IMAGE_SET_MODEL.get()()
newImageSet.acquisition_time = exifTime
newImageSet.acquisition_timezone = form.getTimezoneName()
fileName = uploadedFile.name
newImageSet.name = fileName
newImageSet.camera = getCameraObject(exifData)
newImageSet.track_position = getTrackPosition(exifTime, resource)
newImageSet.exif_position = buildExifPosition(exifData, newImageSet.camera, resource, exifTime, form_tz)
newImageSet.author = author
newImageSet.resource = resource
newImageSet.finish_initialization(request)
nowTime = time.time()
uploadAndSaveTime = nowTime - timeMark
newImageSet.uploadAndSaveTime = uploadAndSaveTime
overallStartTime = cache.get("imageAutoloadGlobalTimeMark", None)
if overallStartTime:
totalTimeSinceNotify = nowTime - float(overallStartTime)
newImageSet.totalTimeSinceNotify = totalTimeSinceNotify
newImageSet.save()
# link the "image set" to "image".
newImage.imageSet = newImageSet
newImage.save()
# create a thumbnail
thumbnailStream = createThumbnailFile(newImage.file)
SINGLE_IMAGE_MODEL.get().objects.create(
file=thumbnailStream, raw=False, thumbnail=True, imageSet=newImageSet
)
#.........这里部分代码省略.........