本文整理汇总了Python中models.Photo.create方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.create方法的具体用法?Python Photo.create怎么用?Python Photo.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Photo
的用法示例。
在下文中一共展示了Photo.create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import create [as 别名]
def new_photo(slide_id):
slide = Slide.query.filter_by(id=slide_id).first()
if not slide:
flash(BAD_KITTY, 'danger')
return redirect(url_for('index'))
journey = Journey.query.filter_by(id=slide.journey_id, user_id=current_user.id).first()
if not journey:
flash(BAD_KITTY, 'danger')
return redirect(url_for('index'))
form = NewPhotoForm(slide_id=slide_id)
if form.validate_on_submit():
photo = Photo()
tmp = tempfile.NamedTemporaryFile(suffix = '.jpg')
form.photo.data.save(tmp)
tmp.flush()
photo.create(form.data['title'], form.data['description'], slide_id, tmp.name)
db.session.add(photo)
db.session.commit()
flash('Photo added to slide', 'success')
return redirect(url_for('edit_slide', slide_id=slide_id))
flash_errors(form)
return render_template('new-photo.html', form=form, title='New Photo')
示例2: upload
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import create [as 别名]
def upload(request):
storage = Client(domain = settings.MOGILEFS_DOMAIN,
trackers = settings.MOGILEFS_TRACKERS)
photo_file = request.FILES.get('photo')
photo_desc = request.POST.get('desc', '')
if photo_file is None or not photo_file.name.endswith('.jpg') or \
photo_file.size > settings.MAX_PHOTO_SIZE:
# Mamy błąd
return HttpResponseRedirect('/')
else:
model = Photo.create(owner=request.user.id, desc=photo_desc)
#with open(path.join(settings.UNPROCESSED_PHOTOS_DIR, '%s.jpg' % model.id), 'wb') as f:
with storage.new_file(path.join(settings.UNPROCESSED_PHOTOS_DIR,
'%s,%s.jpg' % (model.owner, model.nb))) as f:
for chunk in photo_file.chunks():
f.write(chunk)
f.close()
prepare_photo_files.delay(model.owner, model.nb)
return HttpResponseRedirect('/')