本文整理汇总了Python中model.Node.get_by_key方法的典型用法代码示例。如果您正苦于以下问题:Python Node.get_by_key方法的具体用法?Python Node.get_by_key怎么用?Python Node.get_by_key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Node
的用法示例。
在下文中一共展示了Node.get_by_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import get_by_key [as 别名]
def get(self, nodeid):
n_obj = Node.get_by_key('n-'+str(nodeid))
if not n_obj:
self.set_status(404)
self.write('404')
return
from_id = int(self.get_argument('id', '0'))
if from_id<=0 and n_obj['count']:
from_id = int(n_obj['count'])
to_id = from_id - EACH_PAGE_POST_NUM
if to_id<0:
to_id = 0
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(str(nodeid), from_id, to_id),
'newest_node': Node.get_newest(),
'recent_node': Node.get_recent_node(),
'hot_node': Node.get_hot_node(),
'recent_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-topic-home'),
'comment_topic_objs': Commomkvdb.get_comment_topic_by_keys('recent-comment-topic-home'),
}, layout='_layout.html')
Node.add_node_key('n-'+str(nodeid))
示例2: post
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import get_by_key [as 别名]
def post(self, nodeid='1'):
n_obj = Node.get_by_key('n-'+str(nodeid))
if not n_obj:
self.set_status(404)
self.write('404')
return
errors = []
author = str(self.get_cookie('username',''))
title = self.get_argument('title','')
content = self.get_argument('content','')
t_obj = TOPIC_DICT.copy()
if title and content:
if len(title)<=TITLE_MAX_S and len(content)<=CONTENT_MAX_S:
int_time = int(time())
#check spam
u_topic_time = kv.get('u_topic_time:'+author)
if u_topic_time:
tlist = u_topic_time.split(',')
if len(tlist)== MEMBER_RECENT_TOPIC and (int_time-int(tlist[-1])) < 3600:
self.write(u'403:不要发帖太频繁了 <a href="/newpost/%s">请返回</a>' % nodeid)
return
#check repeat
content = textilize(content)
#content = safe_encode(content)
con_md5 = md5(content.encode('utf-8')).hexdigest()
if mc.get('c_'+con_md5):
self.write(u'403:请勿灌水 <a href="/newpost/%s">请返回</a>' % nodeid)
return
else:
mc.set('c_'+con_md5, '1', 36000)
t_obj['title'] = title
t_obj['nodeid'] = str(nodeid)
t_obj['nodename'] = n_obj['name']
t_obj['author'] = author
t_obj['add'] = int_time
t_obj['content'] = content
if n_obj['count']:
topic_id = int(n_obj['count']) + 1
else:
topic_id = 1
if Topic.add(topic_id, t_obj):
topic_key = 't-%s-%s' % (str(nodeid), str(topic_id))
#node count +1
n_obj['count'] = str(topic_id)
Commomkvdb.save('n-'+str(nodeid), n_obj)
#member recent +key
#Member.add_key_rencent_topic(author, topic_key)
rt_obj = kv.get('topic-'+author)
if rt_obj:
olist = rt_obj.split(',')
if topic_key not in olist:
olist.insert(0, topic_key)
rt_obj = ','.join(olist[:MEMBER_RECENT_TOPIC])
kv.set('topic-'+author, rt_obj)
else:
rt_obj = topic_key
kv.set('topic-'+author, topic_key)
#recent in home +key
Commomkvdb.add_key_rencent_topic('recent-topic-home', topic_key)
#all topic counter +1
Count.key_incr('all-topic-num')
#hot node
tqueue = TaskQueue('default')
tqueue.add(Task('/task/hotnode/%s/%s' % ('n-'+str(nodeid), str(topic_id)), delay=5))
#notifications
mentions = findall_mentions(t_obj['content'], author)
if mentions:
tqueue.add(Task('/task/mentions/'+topic_key, 'member='+','.join(mentions), delay=8))
#set for check spam
#u_topic_time = kv.get('u_topic_time:'+author)
if u_topic_time:
tlist = u_topic_time.split(',')
if str(int_time) not in tlist:
tlist.insert(0, str(int_time))
u_topic_time = ','.join(tlist[:MEMBER_RECENT_TOPIC])
kv.set('u_topic_time:'+author, u_topic_time)
else:
u_topic_time = str(int_time)
kv.set('u_topic_time:'+author, u_topic_time)
##set new sr_code
cur_user = self.cur_user()
code_list = [cur_user['code'],u_topic_time]
u_comment_time = kv.get('u_comment_time:'+author)
if u_comment_time:
code_list.append(u_comment_time)
self.set_cookie('usercode', md5(''.join(code_list)).hexdigest(), path="/", expires_days = 365 )
#del cache
clear_cache_multi(['get_topic_by_keys:recent-topic-home','get_topic_by_keys:topic-' + author, 'get_comment_topic_by_keys:recent-topic-home', 'get_comment_topic_by_keys:recent-comment-topic-home','cur_user:' + author])
#.........这里部分代码省略.........