当前位置: 首页>>代码示例>>Python>>正文


Python UploadFileForm.getTimezoneName方法代码示例

本文整理汇总了Python中forms.UploadFileForm.getTimezoneName方法的典型用法代码示例。如果您正苦于以下问题:Python UploadFileForm.getTimezoneName方法的具体用法?Python UploadFileForm.getTimezoneName怎么用?Python UploadFileForm.getTimezoneName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.UploadFileForm的用法示例。


在下文中一共展示了UploadFileForm.getTimezoneName方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: saveImage

# 需要导入模块: from forms import UploadFileForm [as 别名]
# 或者: from forms.UploadFileForm import getTimezoneName [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
            )

#.........这里部分代码省略.........
开发者ID:xgds,项目名称:xgds_image,代码行数:103,代码来源:views.py


注:本文中的forms.UploadFileForm.getTimezoneName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。