本文整理汇总了Python中model.Node.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Node.get_by_id方法的具体用法?Python Node.get_by_id怎么用?Python Node.get_by_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Node
的用法示例。
在下文中一共展示了Node.get_by_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import get_by_id [as 别名]
def get(self, nodeid):
n_obj = Node.get_by_id(int(nodeid))
if not n_obj:
self.error(404)
self.echo('error.html', {
'page': '404',
'title': "Can't find out this URL",
'h2': 'Oh, my god!',
'msg': 'Something seems to be lost...'
})
return
from_id = int(self.request.get('id', '0'))
if from_id<=0 and n_obj.count:
from_id = n_obj.count
to_id = from_id - EACH_PAGE_POST_NUM
if to_id<0:
to_id = 0
newest_node = Node.get_newest()
self.echo('nodedetail.html', {
'title': n_obj.name,
'n_obj': n_obj,
'from_id': from_id,
'to_id': to_id,
'topic_objs': Node.get_page_topic(nodeid, from_id, to_id),
'newest_node': newest_node,
'recent_node': Node.get_recent_node(),
'hot_node': Node.get_hot_node(),
'recent_topic_objs': KeyStrValue.get_topic_key_title('recent-topic-home'),
'reply_topic_objs': KeyStrValue.get_topic_key_title('recent-reply-topic'),
}, layout='_layout.html')
if len(newest_node)==10:
KeyStrValue.add_node_key(nodeid)
示例2: post
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import get_by_id [as 别名]
def post(self):
if self.cur_user and self.cur_user.flag==99:
n_id = self.request.get('id')
name = self.POST['name']
imgurl = self.POST['imgurl']
about = self.POST['about']
if name:
if n_id:
n_obj = Node.get_by_id(int(n_id))
else:
n_obj = None
if n_obj:
n_obj.name = name
n_obj.imgurl = imgurl
n_obj.about = about
n_obj.put()
else:
#get node id
nid_obj = Counter.get_or_insert('node_auto_increment', name='node_auto_increment', value = 1)
n_obj = Node(key=db.Key.from_path('Node', nid_obj.value))
n_obj.name = name
n_obj.imgurl = imgurl
n_obj.about = about
n_obj.put()
if n_obj.is_saved():
n_id = nid_obj.value
nid_obj.value += 1
db.run_in_transaction(obj_runput,nid_obj,['newest_add_node'])
self.redirect('/add-node?id=%s'%str(n_id))
else:
self.error(403)
self.write('403:forbidden')