本文整理汇总了Python中models.Photo.key方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.key方法的具体用法?Python Photo.key怎么用?Python Photo.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Photo
的用法示例。
在下文中一共展示了Photo.key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import key [as 别名]
def post(self):
if self.get_uploads('image'):
upload_files = self.get_uploads('image')
blob_info = upload_files[0]
else:
blob_info=None
if self.form.validate():
form=self.form
photo=Photo(name=form.name.data,
image=blob_info
)
if (form.lat.data and form.lon.data):
photo.location=db.GeoPt(lat=form.lat.data,lon= form.lon.data)
photo.put()
response = redirect_to('collector-thanks',)
else:
form=self.form
photo=Photo(name=form.name.data,
email=form.email.data,
phone=form.phone.data,
image=blob_info
)
photo.put()
response = redirect_to('collector',photo=photo.key())
# Clear the response body.
response.data = ''
return response
示例2: post
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import key [as 别名]
def post(self):
try:
upload = self.get_uploads('file')
blob = upload[0]
description = self.request.get('description');
title = self.request.get('title');
photo = Photo(blobKey=str(blob.key()), description=description, title=title)
photo.put()
competition = Competition(photoKey=photo.key(), dateCreated=datetime.datetime.now())
competition.put();
self.redirect("/competitions/latest")
except:
self.redirect("/upload-failure")
示例3: upload
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import key [as 别名]
def upload():
lightbox_id = int(request.form['lightboxId'])
lightbox = Lightbox.get_by_id(lightbox_id)
photos = []
for file in request.files.getlist('file'):
logger.debug('processing file name %s for lightbox id: %d' % (file.filename, lightbox_id))
photo = Photo()
photo.lightbox = lightbox
image_data = file.read()
photo.full_image = db.Blob(image_data)
photo.thumbnail = db.Blob(images.resize(image_data, 180, 180))
photo.owner = users.get_current_user()
photo.name = file.filename
photo.put()
photos.append(photo.key().id())
return jsonify(lightbox={"id": lightbox.key().id(), "photos": photos})
示例4: post
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import key [as 别名]
def post(self):
user = User.get_by_key_name(self.current_user['id'])
# action upload a photo
if self.request.get('action') == 'upload':
fd = self.request.get('photo')
# ext = fd.file.name.split('.')[-1].lower()
cropped, img = crop_image(fd, 'post', False)
photo_blob = Photo.create_blob(img)
extension = 'jpg' # if cropped==True else ext
photo = Photo(user=user, file=photo_blob, extension=extension, is_used=False)
photo.put()
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps({'success': True, 'photo': str(photo.key())}))
# Action create Photo post
if self.request.get('action') == 'boker_photo':
ispop = self.request.get('pop') == '1'
if ispop:
self.template = 'boker_pop.html'
explicitly_shared = self.request.get('explicit_share', False)
if explicitly_shared == 'on': explicitly_shared = True
photokey = self.request.get('photokey')
desc = self.request.get('desc')
photo = Photo.get(photokey)
if photo and desc:
# Save boker
boker = Boker(user=user, photo=photo, description=desc)
boker.put()
# Set photo used
photo.is_used = True
photo.put()
# Run task: Posting to page wall
boker_url = "%s/boker/%s" % (settings.APP_DOMAIN, boker.key().id())
user_access_token = self.current_user['access_token']
deferred.defer(post_page_photo, boker_url, photokey, desc)
deferred.defer(publish_upload_action, user_access_token, boker_url, explicitly_shared)
boker_url = self.uri_for('boker_view', boker_id=boker.key().id())
if ispop:
self.response.out.write(u'<script type="text/javascript">window.parent.window.location.href="%s";</script>' % boker_url);
else:
self.redirect(boker_url)
else:
return self.render_response(self.template, {
'errors': 'Photo dan Ceritanya harus diisi.',
'photokey': photokey,
'desc': desc,
})
# Action create Video Post
if self.request.get('action') == 'boker_video':
ispop = self.request.get('pop') == '1'
if ispop:
self.template = 'boker_video.html'
explicitly_shared = self.request.get('explicit_share', False)
if explicitly_shared == 'on': explicitly_shared = True
video_url = self.request.get('video_url')
video_id = self.request.get('video_id')
video_source = self.request.get('video_source')
desc = self.request.get('desc')
if video_id and video_source and desc:
boker = Boker(user=user, video_id=video_id, video_source=video_source, description=desc)
boker.put()
boker_url = "%s/boker/%s" % (settings.APP_DOMAIN, boker.key().id())
user_access_token = self.current_user['access_token']
# deferred.defer(post_page_video, boker_url, boker.description)
deferred.defer(publish_posts_action, user_access_token, boker_url, False)
boker_url = self.uri_for('boker_view', boker_id=boker.key().id())
if ispop:
self.response.out.write(u'<script type="text/javascript">window.parent.window.location.href="%s";</script>' % boker_url);
else:
self.redirect(boker_url)
else:
return self.render_response(self.template, {
'errors': 'Video dan Ceritanya harus diisi.',
'video_url': video_url,
'desc': desc,
})