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


Python Photo.start_date方法代码示例

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


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

示例1: index

# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import start_date [as 别名]
def index():
    current_app.logger.info("upload_file, method = %s, folder=%s", request.method, current_app.config['UPLOAD_FOLDER'])
    if request.method == "GET":
        return render_template('admin/uploads.html')
    elif request.method == "POST":
        #generating json response array
        result = []
        for inputname, fileobj in request.files.items():
            # filename = fileobj.filename
            # current_app.logger.info("filename = %s" % (filename))
            # dump(fileobj)
            # fileobj = request.files[filename]
            # current_app.logger.info("filename = %s, file size = %d" % (filename, get_file_size(fileobj.file)))
            if fileobj and allowed_file(fileobj.filename):
                if Photo.query.filter(Photo.filename == fileobj.filename).count() > 0:
                    result.append({"name": fileobj.filename,
                                   "size": 0,
                                   "error": "Duplicated filename",
                                   "url": "",
                                   "thumbnail_url": "",
                                   "delete_url": "",
                                   "delete_type": "POST"})
                    continue

                # save file
                saved_filename = get_saved_filename(fileobj.filename)
                filesize = get_file_size(fileobj.stream)
                current_app.logger.info("filename original = %s, escaped = %s, size = %d" % (fileobj.filename, saved_filename, filesize))
                fileobj.save(os.path.join(current_app.config['UPLOAD_FOLDER'], saved_filename))

                # process file to get noexif image, thumb image
                noexif_filename = get_noexif_filename(fileobj.filename)
                thumb_filename = get_thumb_filename(fileobj.filename)
                save_transposed_imagefiles(saved_filename, noexif_filename, thumb_filename, current_app.config['UPLOAD_FOLDER'])

                photo = Photo(filename=fileobj.filename, saved_filename=saved_filename)
                photo.noexif_filename = noexif_filename
                photo.thumb_filename = thumb_filename
                photo.size = filesize
                photo.start_date = get_image_date(saved_filename=saved_filename, filepath=current_app.config['UPLOAD_FOLDER'])
                photo.exif = get_image_exif(saved_filename=saved_filename, filepath=current_app.config['UPLOAD_FOLDER'])
                photo.user_id = session['user_id']
                db_session.add(photo)
                db_session.commit()

                result.append({"name": fileobj.filename,
                               "size": filesize,
                               "url": url_for("photos.show_photo", filename=fileobj.filename),
                               "thumbnail_url": url_for("photos.show_thumb", filename=fileobj.filename),
                               "delete_url": "",
                               "delete_type": "POST"})
            else:
                current_app.logger.info("Invalid file extension: %s" % (fileobj.filename))
                result.append({"name": fileobj.filename,
                               "error": "Invalid file extension",
                               "size": "",
                               "url": "",
                               "thumbnail_url": "",
                               "delete_url": "",
                               "delete_type": "POST"})

        # https://github.com/blueimp/jQuery-File-Upload/wiki/Setup
        # response formats
        final_result = {}
        final_result['files'] = result
        response_data = json.dumps(final_result)
        current_app.logger.info("response = %s" % (response_data))
        return response_data
开发者ID:ChinaHackers,项目名称:timeline-gallery-in-openshift,代码行数:70,代码来源:uploads.py


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