本文整理汇总了Python中photo.Photo.event_id方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.event_id方法的具体用法?Python Photo.event_id怎么用?Python Photo.event_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photo.Photo
的用法示例。
在下文中一共展示了Photo.event_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_event_photo
# 需要导入模块: from photo import Photo [as 别名]
# 或者: from photo.Photo import event_id [as 别名]
def save_event_photo(cls, event_id, photo):
if type(photo) is type(''):
return False
file_content = photo.file.read()
if len(file_content) == 0:
return False
filename, ext = os.path.splitext(photo.filename)
filename = unicodedata.normalize('NFD', filename).encode('ascii', 'ignore')
md5_ = md5(str(file_content)).hexdigest()
new_filename = md5_ + '_' + filename.lower() + ext.lower()
if not os.path.exists(Photo.BASE_STORAGE_PATH + new_filename[0]):
os.makedirs(Photo.BASE_STORAGE_PATH + new_filename[0])
new_filename_with_path = Photo.BASE_STORAGE_PATH + new_filename[0] + '/' + new_filename
Photo.save_original(new_filename_with_path, file_content)
img = Image.open(new_filename_with_path)
if img.mode != "RBG":
img = img.convert("RGB")
tiny_image = Photo.resize(img, Photo.TINY_THUMBNAIL, new_filename, 'tiny_')
small_image = Photo.resize(img, Photo.SMALL_THUMBNAIL, new_filename, 'small_')
big_image = Photo.resize(img, Photo.BIG_THUMBNAIL, new_filename, 'big_')
maxi_image = Photo.resize(img, Photo.MAXI_THUMBNAIL, new_filename, 'maxi_')
photo = Photo()
photo.filepath = new_filename_with_path
photo.event_id = event_id
photo.is_main = True
DBSession.add(photo)
DBSession.flush()
return photo