本文整理汇总了Python中models.Photo.size方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.size方法的具体用法?Python Photo.size怎么用?Python Photo.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Photo
的用法示例。
在下文中一共展示了Photo.size方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import size [as 别名]
def add_photo(self, album_id=''):
if request.method == 'POST':
album = Album.get(id=album_id)
photo = Photo()
photo.album = album
file = request.files['files']
photo_title, size, photo_path, photo_url, thumb_url, thumb_path = self.gal_man.add_photo(album, file)
result = []
result.append({
'name':photo_title,
'size':size,
'url':photo_url,
'thumbnail_url':thumb_path,
"delete_type":"POST",
})
photo.title = photo_title
photo.photo_path = photo_path
photo.thumb_path = thumb_path
photo.photo_url = photo_url
photo.thumb_url = thumb_url
photo.size = size
photo.save()
return json.dumps(result)
else:
return 'response'
示例2: index
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import size [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