本文整理汇总了Python中models.node_model函数的典型用法代码示例。如果您正苦于以下问题:Python node_model函数的具体用法?Python node_model怎么用?Python node_model使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了node_model函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: POST
def POST(self, cat_name):
cat = cat_model().get_one({"name": cat_name})
if cat is None:
self.crumb.append("分类不存在")
return admin_render.cat_nf("分类不存在", self.crumb.output())
if self.form.validates():
if node_model().unique_insert({"name": self.form.d.name}):
# 为了保证不插入空的display_name的节点,故此
try:
node_model().update(
{"name": self.form.d.name},
{
"category_id": cat.id,
"display_name": self.form.d.display_name,
"description": self.form.d.description,
},
)
except:
node_model().delete({"name": self.form.d.name})
web.SeeOther("/admin/node/" + self.form.d.name)
else:
return admin_render.create_cat("节点名已存在", self.crumb.output(), self.form)
else:
return admin_render.create_node("添加新节点", self.crumb.output(), cat, self.form)
示例2: POST
def POST(self, node_name):
node = node_model().get_one({'name':node_name})
if node is None:
return admin_render.node_nf('节点不存在', self.crumb.output())
if self.form.validates():
node_model().update({'name':node.name}, {'display_name':self.form.d.display_name, 'description':self.form.d.description})
raise web.SeeOther('/admin/node/'+node.name)
示例3: GET
def GET(self):
title = '首页'
#sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
#post_ids = post_model().query_result(sql)
post_results = post_model().get_all(order='last_update DESC', limit=20)
posts = []
for post_result in post_results:
#post_result = post_model().get_one({'id':row.post_id})
post = {'post':post_result}
user = user_model().get_one({'id':post_result.user_id})
post['user'] = user
node = node_model().get_one({'id':post_result.node_id})
post['node'] = node
comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
if comment:
comment_user = user_model().get_one({'id':comment.user_id})
post['comment_user'] = comment_user
else:
post['comment_user'] = None
posts.append(post)
cats_result = cat_model().get_all()
cats = []
for cat_result in cats_result:
cat = {'cat':cat_result}
node = node_model().get_all({'category_id':cat_result.id})
cat['node'] = node
cats.append(cat)
return render.index(cats, posts, title)
示例4: GET
def GET(self):
# sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
# post_ids = post_model().query_result(sql)
crumb = Crumb()
limit = 50
total = post_model().count_table()
pagination = Pagination("/recent", total, limit=limit)
page = pagination.true_page(web.input(p=1)["p"])
post_results = post_model().get_all(limit=limit, offset=(page - 1) * limit, order="time DESC")
posts = []
for post_result in post_results:
# post_result = post_model().get_one({'id':row.post_id})
post = {"post": post_result}
user = user_model().get_one({"id": post_result.user_id})
post["user"] = user
node = node_model().get_one({"id": post_result.node_id})
post["node"] = node
comment = comment_model().get_one({"post_id": post_result.id}, order="time DESC")
if comment:
comment_user = user_model().get_one({"id": comment.user_id})
post["comment_user"] = comment_user
else:
post["comment_user"] = None
posts.append(post)
crumb.append("最近的主题")
return render.recent("最近的主题", total, crumb.output(), posts, pagination.output())
示例5: GET
def GET(self):
cat_result = cat_model().get_all()
cats = []
for cat in cat_result:
node_total = node_model().count_table({"category_id": cat.id})
cats.append({"cat": cat, "node_total": node_total})
return admin_render.index("后台", cats, self.crumb.output())
示例6: POST
def POST(self, node_name):
if session.user_id is None:
raise web.SeeOther('/login?next=/post/create' + node_name)
conditions = {'name' : node_name}
node = node_model().get_one(conditions)
if node is None:
return render.not_found('节点未找到', '节点未找到')
if not self.form.validates():
return render.create_post(self.form, '创建失败, 请重创:D', self.crumb.output())
user_model().update_session(session.user_id)
length, cost = money_model().cal_post(self.form.d.content)
if session.money < cost:
self.crumb.append('财富不够')
return render.no_money('财富不够', '你的财富值不够,不能创建改主题 :(', self.crumb.output())
title = strip_tags(self.form.d.title)
content = html2db(self.form.d.content)
content, receiver_list = notify_model().convert_content(content)
create_time = time.time()
post_id = post_model().insert({'title' : title, 'content' : content, 'node_id' : node.id, 'time' : create_time, 'last_update':create_time, 'user_id' : session.user_id})
# money
money_type_id = money_type_model().get_one({'name':'post'})['id']
money_model().insert({'user_id':session.user_id, 'money_type_id':money_type_id, 'amount':-cost, 'length':length, 'balance':user_model().update_money(session.user_id, -cost), 'foreign_id':post_id})
# notify
receiver_list = list_diff(receiver_list, [session.name])
notify_model().insert_notify(session.user_id, receiver_list, 'post_at', post_id)
user_model().update_session(session.user_id)
raise web.seeother('/post/' + str(post_id))
示例7: GET
def GET(self, node_name):
limit = 10
node = node_model().get_one({'name': node_name})
if node is None:
self.crumb.append('节点未找到')
return render.node_nf('节点未找到', self.crumb.output())
else:
self.crumb.append(node.display_name)
node_fav = False
if session.user_id:
if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'node_fav', 'meta_value':node.id}):
node_fav = True
total_rows = post_model().count_table({'node_id':node.id})
pagination = Pagination('/node/'+node_name, total_rows, limit = limit)
page = pagination.true_page(web.input(p=1)['p'])
posts_result = post_model().get_all({'node_id' : node.id}, limit = limit, offset = (page-1)*limit , order = 'time DESC')
posts = []
for post_result in posts_result:
post = {'post':post_result}
user = user_model().get_one({'id':post_result.user_id})
post['user'] = user
comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
if comment:
comment_user = user_model().get_one({'id':comment.user_id})
post['comment_user'] = comment_user
else:
post['comment_user'] = None
posts.append(post)
return render.node_posts(posts, node, total_rows, node_fav, self.crumb.output(), pagination.output())
示例8: GET
def GET(self):
limit = 10
self.crumb.append('我关注的人的最新主题')
# 取出收藏的节点id
followings = user_meta_model().get_all({'user_id':session.user_id, 'meta_key':'follow'})
if len(followings) > 0 :
user_favs = []
for following in followings:
user_favs.append(following.meta_value)
total_rows = post_model().count_table({'user_id':user_favs})
pagination = Pagination('/my/following', total_rows, limit = limit)
page = pagination.true_page(web.input(p=1)['p'])
posts_result = post_model().get_all(conditions = {'user_id': user_favs}, order = 'time DESC', limit = limit, offset = (page-1)*limit)
posts = []
for post_result in posts_result:
post = {'post':post_result}
user = user_model().get_one({'id':post_result.user_id})
post['user'] = user
node = node_model().get_one({'id':post_result.node_id})
post['node'] = node
comment = comment_model().get_one({'post_id':post_result.id}, order='time DESC')
if comment:
comment_user = user_model().get_one({'id':comment.user_id})
post['comment_user'] = comment_user
else:
post['comment_user'] = None
posts.append(post)
else:
posts = None
total_rows = 0
pagination = Pagination('/my/nodes', total_rows)
page = pagination.true_page(web.input(p=1)['p'])
return render.following_posts('来自我收藏的节点的最新主题', posts, total_rows, self.crumb.output(), pagination.output())
示例9: GET
def GET(self):
cat_result = cat_model().get_all()
cats = []
for cat in cat_result:
node_total = node_model().count_table({'category_id':cat.id})
cats.append({'cat':cat, 'node_total':node_total})
return admin_render.index('后台', cats, self.crumb.output())
示例10: GET
def GET(self, node_name):
node = node_model().get_one({'name':node_name})
if node is None:
return admin_render.node_nf('节点不存在', self.crumb.output())
cat = cat_model().get_one({'id':node.category_id})
self.crumb.append(cat.display_name, '/admin/cat/'+cat.name)
self.crumb.append(node.display_name, '/admin/node/'+node.name)
self.crumb.append('设置节点图标')
return admin_render.set_node_icon('设置节点图标', self.crumb.output(), node)
示例11: GET
def GET(self, method):
web.header('Content-Type', 'application/json')
if method.lower() == 'show':
cats_result = cat_model().get_all()
cats = []
for cat_result in cats_result:
cat = {'cat':cat_result}
node = node_model().get_all({'category_id':cat_result.id})
cat['node'] = node
cats.append(cat)
return json.dumps(cats)
示例12: GET
def GET(self, node_name):
if session.user_id is None:
raise web.SeeOther('/login?next=/post/create/' + node_name)
conditions = {'name' : node_name}
node = node_model().get_one(conditions)
self.crumb.append(node.display_name, '/node/'+node.name)
self.crumb.append('创建新主题')
if node is None:
self.crumb.claer()
return render.not_found('节点未找到', '节点未找到')
title = '创建主题'
return render.create_post(self.form, title, self.crumb.output())
示例13: POST
def POST(self, cat_name):
cat = cat_model().get_one({'name':cat_name})
if cat is None:
self.crumb.append('分类不存在')
return admin_render.cat_nf('分类不存在', self.crumb.output())
if self.form.validates():
if node_model().unique_insert({'name':self.form.d.name, 'category_id':cat.id, 'display_name':self.form.d.display_name, 'description':self.form.d.description}):
web.SeeOther('/admin/node/'+self.form.d.name)
else:
return admin_render.create_cat('节点名已存在', self.crumb.output(), self.form)
else:
return admin_render.create_node('添加新节点', self.crumb.output(), cat, self.form)
示例14: GET
def GET(self):
title = '首页'
#sql = 'SELECT post_id FROM comment GROUP BY post_id ORDER BY MAX(time) DESC LIMIT 20'
#post_ids = post_model().query_result(sql)
posts = post_model().trends()
cats_result = cat_model().get_all()
cats = []
for cat_result in cats_result:
cat = {'cat':cat_result}
node = node_model().get_all({'category_id':cat_result.id})
cat['node'] = node
cats.append(cat)
return render.index(cats, posts, title)
示例15: GET
def GET(self, node_name):
limit = 10
node = node_model().get_one({'name': node_name})
if node is None:
self.crumb.append('节点未找到')
return render.node_nf('节点未找到', self.crumb.output())
else:
self.crumb.append(node.display_name)
node_fav = False
if session.user_id:
if user_meta_model().get_one({'user_id':session.user_id, 'meta_key':'node_fav', 'meta_value':node.id}):
node_fav = True
total_rows = post_model().count_table({'node_id':node.id})
pagination = Pagination('/node/'+node_name, total_rows, limit = limit)
page = pagination.true_page(web.input(p=1)['p'])
posts = post_model().trends(limit, (page-1) * limit, node.id)
return render.node_posts(posts, node, total_rows, node_fav, self.crumb.output(), pagination.output())