本文整理汇总了Python中db.Share类的典型用法代码示例。如果您正苦于以下问题:Python Share类的具体用法?Python Share怎么用?Python Share使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Share类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self):
action = self.request.path[7:]
share_res = Share.find()
if 'add' in action:
do, share_id, suggestscore = action.split('!')
share = Share.by_sid(share_id)
share.suggestscore = float(suggestscore)
share.save()
for share in share_res:
share.score = 0.001 * share.hitnum + share.likenum - \
share.dislikenum + 0.5 * share.commentnum - \
share.status + share.suggestscore + 0.5 * share.id
share.save()
# self.write_json({'objs': list(Share.find().sort('score',
# DESCENDING))})
share_res = Share.find().sort('score', DESCENDING)
display = ''
display += '<p>score sugg hit like dis comment status title id</p>'
for share in share_res:
display += '<p>%s %s %s %s %s %s %s %s %s</p>' % (
share.score,
share.suggestscore,
share.hitnum,
share.likenum,
share.dislikenum,
share.commentnum,
share.status,
share.title,
share.id)
self.write(display)
示例2: get
def get(self):
page = self.get_argument("page", 1)
per_page = self.get_argument("per_page", 10)
per_page = int(per_page)
page = int(page)
entity_type = self.get_argument("entity_type", 'share')
user_id = self.current_user["user_id"]
assert entity_type in 'share comment viewpoint'.split()
cond = {
'user_id': user_id,
'entity_type': entity_type,
'collectnum': 1,
}
number = Collect.find(cond, {'_id': 0}).count()
collects = Collect.find(cond, {'_id': 0}).sort(
'_id', -1).limit(per_page).skip((page - 1) * per_page)
res = []
print(collects.count())
for collect in collects:
# 'status': {'$gte': 1},
share = Share.find_one({'id': collect.id}, {'_id': 0})
share = fix_share(share)
res.append(share)
self.res = res
return self.write_json(number=number)
示例3: get
def get(self, node='home'):
page = self.get_argument("page", 1)
# share_res = Share.find({'status': 0}).sort(
# 'score', DESCENDING).limit(11).skip((int(page) - 1) * 11)
share_res = Share.find({'status': {'$gte': 1}}).sort(
'_id', DESCENDING).limit(11).skip((int(page) - 1) * 11)
pagesum = (share_res.count() + 10) / 11
shares = []
for share in share_res:
if share.id in (48, 47):
continue
user = User.by_sid(share.user_id)
share.name = user.user_name
share.published = time.strftime(
'%Y-%m-%d %H:%M:%S', time.localtime(share.published))
share.domain = user.user_domain
share.markdown = cutter(
markdown2.markdown(share.markdown))
share.title = share.title.split('_')[0]
shares.append(share)
self.render(
"node.html",
shares=shares,
pagesum=pagesum, page=page, node=node,
)
示例4: post
def post(self):
id = self.get_argument("id", None)
tags = self.get_argument("tags", '')
user_id = self.current_user["user_id"]
res = {
'title': self.get_argument("title"),
'markdown': self.get_argument("markdown"),
'sharetype': self.get_argument("type"),
'slug': self.get_argument("slug", ''),
'tags': tags,
'updated': time.time(),
}
if id:
share = Share.by_sid(id)
if not share:
self.redirect("/404")
share.update(res)
share.save()
else:
share = Share
res['user_id'] = user_id
share = share.new(res)
user = User.by_sid(user_id)
user.user_leaf += 10
user.save()
for i in tags.split(' '):
Tag.new(i, share.id)
self.redirect("/share/" + str(share.id))
示例5: todo_get_suggest
def todo_get_suggest(share, current_user):
posts = Share.find()
suggest = []
for post in posts:
post.score = 100 + post.id - post.user_id + post.commentnum * 3
post.score += post.likenum * 4 + post.hitnum * 0.01
post.score += randint(1, 999) * 0.001
common_tags = [i for i in post.tags.split(
' ') if i in share.tags.split(' ')]
# list(set(b1) & set(b2))
post.score += len(common_tags)
if post.sharetype == share.sharetype:
post.score += 1 # todo
if current_user:
is_hitted = Hit.find(
{'share_id': share.id},
{'user_id': int(current_user["user_id"])},
).count() > 0
# else:
# is_hitted = self.get_cookie(share.id)
if is_hitted:
post.score -= 50
suggest.append(post)
suggest.sort(key=lambda obj: obj.get('score'))
suggest = suggest[:5]
示例6: post
def post(self):
commentbody = self.get_argument("commentbody", None)
share_id = self.get_argument("share_id", None)
html = markdown2.markdown(commentbody)
comment = Comment
doc = {}
doc['user_id'] = self.current_user["user_id"]
doc['share_id'] = int(share_id)
doc['commentbody'] = commentbody
comment.new(doc)
share = Share.by_sid(share_id)
share.commentnum += 1
share.save()
name = tornado.escape.xhtml_escape(self.current_user["user_name"])
gravatar = get_avatar(self.current_user["user_email"], 50)
newcomment = ''.join([
'<div class="comment">',
'<div class="avatar">',
'<img src="', gravatar,
'</div>',
'<div class="name">', name,
'</div>',
'<div class="date" title="at"></div>', html,
'</div>',
])
self.write(newcomment)
示例7: get
def get(self, node):
page = self.get_argument("page", 1)
share_res = Share.find({'sharetype': node}).sort(
'_id', DESCENDING).limit(10).skip((int(page) - 1) * 10)
pagesum = (share_res.count() + 9) / 10
shares = []
for share in share_res:
user = User.by_sid(share.user_id)
share.name = user.user_name
share.published = time.strftime(
'%Y-%m-%d %H:%M:%S', time.localtime(share.published))
share.domain = user.user_domain
share.markdown = filter_tags(
markdown2.markdown(share.markdown))[:100]
share.gravatar = get_avatar(user.user_email, 16)
shares.append(share)
members = User.find().sort('_id', DESCENDING).limit(20)
members_dict = []
for member in members:
member.gravatar = get_avatar(member.user_email, 25)
members_dict.append(member)
node_about = options.node_about[node]
self.render(
"node.html", shares=shares, members=members_dict,
pagesum=pagesum, page=page, node=node, node_about=node_about)
示例8: post
def post(self):
share_id = self.get_argument("share_id", None)
tags = self.get_argument("tags", '')
# user_id = self.current_user["user_id"]
tags = tags.strip()
if share_id:
share = Share.by_sid(share_id)
if share and tags not in share.tags:
tags = share.tags + ' ' + tags
res = {
'tags': tags,
'updated': time.time(),
}
share.update(res)
share.save()
tags = tags.split(' ')
tags = list(set(tags))
for i in tags:
doc = {
'name': i,
'share_ids': share.id
}
Tag.new(doc)
示例9: get
def get(self):
user_id = self.current_user['user_id']
share_id = self.get_argument("delete", None)
s = self.get_argument("s", None)
if admin.is_admin(user_id):
if share_id and not s:
admin.delete_share(share_id)
if share_id and s and admin.is_superadmin(user_id):
admin.delete_share_by_s(share_id)
if s:
shares = Share.find({'status': {'$ne': 1}})
self.render('admin/super_share.html', shares=shares)
else:
shares = Share.find()
self.render('admin/share.html', shares=shares)
else:
self.render('admin/join_admin.html')
示例10: post
def post(self, action):
share_id = int(self.get_argument("share_id", None))
user_id = self.current_user["user_id"]
doc = {
'user_id': user_id,
'share_id': share_id
}
newlikes = None
if action == 'addlike':
Like.change_like(doc, 'likenum')
share = Share.by_sid(share_id)
share.likenum += 1
share.save()
user = User.by_sid(share.user_id)
user.user_leaf += 4
user.save()
user = User.by_sid(user_id)
user.user_leaf += 2
user.save()
newlikes = str(share.likenum)
elif action == 'dellike':
Like.change_like(doc, 'likenum')
share = Share.by_sid(share_id)
share.likenum -= 1
share.save()
user = User.by_sid(share.user_id)
user.user_leaf -= 4
user.save()
user = User.by_sid(user_id)
user.user_leaf -= 2
user.save()
newlikes = str(share.likenum)
elif action == 'adddislike':
Like.change_like(doc, 'dislikenum')
share = Share.by_sid(share_id)
share.dislikenum += 1
share.save()
newlikes = str(share.dislikenum)
elif action == 'deldislike':
Like.change_like(doc, 'dislikenum')
share = Share.by_sid(share_id)
share.dislikenum -= 1
share.save()
newlikes = str(share.dislikenum)
self.write(newlikes)
示例11: get
def get(self):
share_id = self.get_argument("id", None)
share = None
if share_id:
share = Share.by_sid(share_id)
editor = self.get_argument("editor", options.default_editor)
if editor:
self.render("share_wysiwyg.html", share=share)
else:
self.render("share.html", share=share)
示例12: get_share_by_slug
def get_share_by_slug(slug):
# 特殊id ramdom
if slug == 'random':
cond = {}
cond['status'] = {'$gte': 1}
# shares = Share.find(cond, {'_id': 0})
shares = Share.find(cond)
share = random.choice(list(shares))
elif slug.isdigit():
share = Share.by_sid(slug)
else:
share = Share.by_slug(slug)
if share:
share.hitnum += 1
if isinstance(share.tags, str):
share.tags = share.tags.split()
share.save()
share.pop('_id')
return share
示例13: get
def get(self, name):
user = User.find_one({'user_domain': name})
user.user_jointime = time.strftime(
'%Y-%m-%d %H:%M:%S', time.localtime(user.user_jointime))
likes = User.find({'user_id': user._id})
likenum = likes.count()
for like in likes:
share = Share.by_id(like.share_id)
like.title = share.title
like.id = share.id
like.type = share.sharetype
user.gravatar = get_avatar(user.user_email, 100)
self.render("userlike.html", user=user, likenum=likenum, likes=likes)
示例14: get
def get(self, name):
user = User.find_one({"user_domain": name})
user.user_jointime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(user.user_jointime))
like_res = Like.find({"user_id": user.id})
likenum = like_res.count()
likes = []
for like in like_res:
share = Share.by_sid(like.share_id)
like.title = share.title
like.id = share.id
like.type = share.sharetype
likes.append(like)
user.gravatar = get_avatar(user.user_email, 100)
self.render("userlike.html", user=user, likenum=likenum, likes=likes)
示例15: post
def post(self):
# print self.request.arguments
share_id = self.get_argument("id", None)
title = self.get_argument("title", '')
markdown = self.get_argument("markdown", '')
content = self.get_argument("content", '')
sharetype = self.get_argument("type", '')
slug = self.get_argument("slug", '')
status = 1 if self.get_argument("dosubmit", None) == u'保存草稿' else 0
tags = self.get_argument("tags", '')
upload_img = self.get_argument("uploadImg", '')
post_img = self.get_argument("post_Img", '')
post_img = '' if post_img == 'None' else post_img
user_id = self.current_user["user_id"]
res = {
'title': title,
'markdown': markdown,
'content': content,
'sharetype': sharetype,
'slug': slug,
'tags': tags,
'status': status,
'upload_img': upload_img,
'post_img': post_img,
'updated': time.time(),
}
if share_id:
share = Share.by_sid(share_id)
if not share:
self.redirect("/404")
share.update(res)
share.save()
else:
share = Share
res['user_id'] = user_id
share = share.new(res)
user = User.by_sid(user_id)
user.user_leaf += 10
user.save()
for i in tags.split(' '):
doc = {
'name': i,
'share_ids': share.id
}
Tag.new(doc)
if status == 1:
self.redirect("/share/?id=" + str(share.id))
self.redirect("/share/" + str(share.id))