本文整理汇总了Python中models.Image.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Image.get_by_id方法的具体用法?Python Image.get_by_id怎么用?Python Image.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Image
的用法示例。
在下文中一共展示了Image.get_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import get_by_id [as 别名]
def get(self):
data = populate_user()
data['domain_url'] = domain(self.request.url)
name = self.request.get('stream_name')
if self.request.get('geo'):
data['geo'] = '&geo=1'
if not name:
template = JINJA_ENVIRONMENT.get_template('view_all.html')
response = requests.get(
domain(self.request.url) + '/stream').json()
data['streams'] = response
return self.response.write(template.render(data))
response = requests.get(domain(self.request.url) + '/stream',
params={'stream_name': name})
if data['logged_in']:
user_id = data['nickname']
data['is_subscribed'] = User.get_by_id(user_id).is_subscribed(name)
data['is_owned'] = User.get_by_id(user_id).is_owned(name)
data['stream_name'] = name
data['offset'] = int(self.request.get('offset', IMG_OFF))
data['count'] = int(self.request.get('count', IMG_CNT))
template = JINJA_ENVIRONMENT.get_template('view.html')
if 'geo' in data:
template = JINJA_ENVIRONMENT.get_template('view_geo.html')
data['offset'] = 0
data['count'] = 100
data['geo_details'] = {}
for image_id in response.json()['image_ids']:
image = Image.get_by_id(image_id)
data['geo_details'][image_id] = {'lat': image.lat,
'lng': image.lng,
'date': image.date.isoformat()
}
if response.status_code == requests.codes.OK:
image_ids = response.json()['image_ids']
data['more'] = len(image_ids) > (data['offset'] + data['count'])
data['prev'] = data['offset'] > 0
self.process(image_ids, data)
if self.request.get('raw'):
self.response.headers['Content-Type'] = 'application/json'
return self.response.out.write(json.dumps(data))
self.response.write(template.render(data))
示例2: post
# 需要导入模块: from models import Image [as 别名]
# 或者: from models.Image import get_by_id [as 别名]
def post(self, key):
post = self.request.POST
edit = self.request.get('kind')
form_data = dict((k, post.get(k, ''))
for k in ('title', 'author', 'date', 'body', 'picture','video'))
template_dict = {'form_data': form_data, 'key': key, 'show_form' : True,'members': Member.all(),
'edit':edit,'thing' : self.thing_descriptors.get(edit),'images':Image.all().filter('name != ', "no-name")}
try:
this_date = utils.parse_date(form_data['date'])
except ValueError:
template_dict['message'] = \
'Date is not in the correct format (YYYY-MM-DD).'
else:
if key == 'new':
try:
if(edit=="news"):
thing = NewsArticleNew(
title=post['title'],
author=Member.get_by_id(int(post['author'])),
date=this_date,
body=post['body']
)
elif(edit=="talk"):
thing = TalkNew(
title=post['title'],
author=Member.get_by_id(int(post['author'])),
date=this_date,
body=post['body']
)
if('video' in post):
talk.video = post['video']
elif(edit=="hack"):
thing = Hack(
title=post['title'],
date=this_date,
body=post['body']
)
if(edit=="news" or edit=="hack"):
if(self.request.get("picture")):
pictureImage = Image(
picture=images.resize(self.request.get("picture"), self.image_height, self.image_width),
name="no-name",title=" ",alt=" ")
if post['picture_title'] :
pictureImage.title=post['picture_title']
if post['picture_alt'] :
pictureImage.alt=post['picture_alt']
pictureImage.put()
thing.picture=pictureImage
elif(post['picture_alias']!="none"):
thing.picture=Image.get_by_id(int(post['picture_alias']))
thing.put()
template_dict['key']=thing.key
except datastore_errors.Error:
template_dict['message'] = \
'Could not create new %s.' % self.thing_descriptors.get(edit)
else:
template_dict['message'] = '%s created.' % self.thing_descriptors.get(edit)
template_dict['show_form'] = False
else:
try:
if(edit=="news"):
thing = NewsArticleNew.get(Key(key))
thing.title = form_data['title']
thing.author = Member.get_by_id(int(post['author']))
thing.date = this_date
thing.body = form_data['body']
elif(edit=="talk"):
thing = TalkNew.get(Key(key))
thing.title = form_data['title']
thing.date = this_date
thing.body = form_data['body']
elif(edit=="hack"):
thing = Hack.get(Key(key))
thing.title = form_data['title']
thing.date = this_date
thing.body = form_data['body']
if(self.request.get("picture")):
pictureImage = Image(picture=images.resize(self.request.get("picture"), self.image_height, self.image_width),
name="no-name",title=" ",alt=" ")
if post['picture_title'] :
pictureImage.title=post['picture_title']
if post['picture_alt'] :
pictureImage.alt=post['picture_alt']
pictureImage.put()
thing.picture = pictureImage
elif(post['picture_alias']!="none"):
thing.picture=Image.get_by_id(int(post['picture_alias']))
if 'delete_picture' in post:
thing.picture=None
except BadKeyError:
#.........这里部分代码省略.........