本文整理汇总了Python中models.Entry.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Entry.get_by_id方法的具体用法?Python Entry.get_by_id怎么用?Python Entry.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Entry
的用法示例。
在下文中一共展示了Entry.get_by_id方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def get(self):
entry_id = self.request.get('entry_id')
if entry_id:
try:
entry_id = int(entry_id)
except:
self.response.set_status(400)
return
entry = Entry.get_by_id(entry_id)
if not entry:
self.response.set_status(404)
return
self.send_json(entry.to_dict())
return
count = self.request.get('count')
page = self.request.get('page')
try:
count = int(count) if count else 20
page = int(page) if page else 0
except:
self.response.set_status(400)
return
entries = Entry.get_latest(count, page)
self.send_json([e.to_dict() for e in entries])
示例2: put
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def put(self):
if not self.is_admin():
return
try:
entry_id = int(self.request.get('entry_id'))
except:
self.response.set_status(400)
return
slug = self.request.get('slug')
title = self.request.get('title')
content = self.request.get('content')
if not slug or not title or not content:
self.response.set_status(400)
return
entry = Entry.get_by_id(entry_id)
if not entry:
self.response.set_status(404)
return
try:
entry.update(slug, title, content)
except Exception as e:
logging.info('Failed to update entry %s: %s' % (entry_id, e))
self.response.set_status(403)
self.send_json({'error': str(e)})
return
self.send_json(entry.to_dict())
示例3: put
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def put(self, request, *args, **kwargs):
entry_id = kwargs.get('entry_id')
content, error_msg = {}, ""
if entry_id:
entry = Entry.get_by_id(int(entry_id))
if entry:
data = json.loads(request.raw_post_data)
for field in ('title', 'body_markdown'):
if field not in data or not data[field]:
error_msg += field + " "
if error_msg:
error_msg = " and ".join(error_msg.split())
status = 422
content = create_error_message("%s missing" %error_msg, status)
else:
for i in ('title', 'body_markdown'):
entry.__setattr__(i, data[i])
entry.body_html = markdown.markdown(data['body_markdown'])
e = entry.put()
content = entry.to_dict()
return self.render_to_response(content)
else:
status = 404
content = create_error_message("Entry with id %s does not exist" %entry_id, status)
else:
status = 400
content = create_error_message("Specify an Entry instance to modify", status)
return self.render_to_response(content, status=status)
示例4: admin_entry_delete
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def admin_entry_delete(request, id=None):
entry = id and Entry.get_by_id(int(id)) or None
if not entry:
raise Http404
entry.delete()
return HttpResponseRedirect('/admin/gae_blog/')
示例5: delete
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def delete(self):
if not self.is_admin():
return
try:
entry_id = int(self.request.get('entry_id'))
except:
self.response.set_status(400)
return
entry = Entry.get_by_id(entry_id)
if not entry:
self.response.set_status(404)
return
entry.delete()
示例6: delete
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def delete(self, request, *args, **kwargs):
entry_id = kwargs.get('entry_id')
content = {}
if entry_id:
entry = Entry.get_by_id(int(entry_id))
if entry:
entry.delete()
return self.render_to_response(content)
status = 404
content = create_error_message("Entry with id %s does not exist" %entry_id, status)
else:
status = 400
content = create_error_message("Specify an Entry instance to delete", status)
return self.render_to_response(content, status=status)
示例7: get
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def get(self, request, *args, **kwargs):
entry_id = kwargs.get('entry_id')
if not entry_id:
entries = db.Query(Entry).order('-pub_date').fetch(limit=6)
content = [e.to_dict() for e in entries]
else:
entry = Entry.get_by_id(int(entry_id))
if not entry:
status = 400
content = create_error_message("Entry with id %s does not exist" %entry_id, status)
return self.render_to_response(content, status=status)
content = entry.to_dict()
return self.render_to_response(content)
示例8: admin_entry_edit
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def admin_entry_edit(request, id=None):
entry = id and Entry.get_by_id(int(id)) or None
if request.POST:
form = FormEntry(request.POST, files=request.FILES, instance=entry)
if form.is_valid():
entry = form.save(False)
entry.author = users.get_current_user()
entry.save()
return HttpResponseRedirect(reverse('admin_index'))
else:
form = FormEntry(instance=entry)
return locals()
示例9: feed_entry_publish
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def feed_entry_publish(feed_id, entry_id):
"""Get a feed"""
logger.info('Manually publishing Feed:%s Entry: %s', feed_id, entry_id)
feed = Feed.get_by_id(feed_id, parent=g.user.key)
if not feed:
return jsonify_error(message="Can't find that feed")
entry = Entry.get_by_id(entry_id, parent=feed.key)
if not entry:
return jsonify_error(message="Can't find that entry")
entry.publish_entry(feed)
entry.overflow = False
entry.put()
return jsonify(status='ok')
示例10: get
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def get(self):
""" user: 用户id
title: 文件名,文件内容标题
pids: 文章列表
"""
user, title, pids = self.request.get('user'), \
self.request.get('title'), \
self.request.get('pids')
pages, idx = [], 1
tmp_pids = pids.split(',')
if tmp_pids:
for it in tmp_pids:
tmp_page = Entry.get_by_id(int(it))
tmp = {
'idx': idx,
'title': tmp_page.title,
'author': tmp_page.author,
'time': tmp_page.insertTime,
'url': tmp_page.url,
'tags': ", ".join(tmp_page.tags),
'content': tmp_page.content
}
pages.append(tmp)
idx += 1
# end for
# end if
tmp_content = common.jinja_template('ebook_pages.html', {
'title': title,
'createTime': datetime.utcnow() + timedelta(hours=TIMEZONE),
'pages': pages
})
sender_addr = 'Tony <[email protected]>'
user_addr = '[email protected]'
mail.send_mail(sender = sender_addr, \
to = user_addr, \
subject = 'Convert', \
body = "deliver from READ LATER, By Tony Chi", \
attachments=[("%s.html" % title, tmp_content)])
示例11: get
# 需要导入模块: from models import Entry [as 别名]
# 或者: from models.Entry import get_by_id [as 别名]
def get(self, pid):
itId = int(pid)
p = Entry.get_by_id(itId)
self.render_template('view.html', { 'title': p.title, 'item': p })