本文整理匯總了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')