def post(self): id = self.get_argument("id", None) title = self.get_argument("title") tag = self.get_argument("tag", None) markdown = self.get_argument("markdown") sharetype = self.get_argument("type") if id: try: share = Share.get(id=id) except: self.redirect("/404") share = Share.update(title=title, markdown=markdown, sharetype=sharetype, updated=datetime.datetime.now()).where( id=id).execute() else: share = Share.create(title=title, markdown=markdown, sharetype=sharetype, user_id=self.current_user["user_id"], ) user = User.update( user_leaf=F('user_leaf') + 10).where( id=self.current_user["user_id"]).execute() id = str(share.id) self.redirect("/share/" + str(id))
def post(self): share_id = self.get_argument("share_id", None) likenum = self.get_argument("likenum", 0) like_id = Like.create( user_id=self.current_user["user_id"], share_id=share_id) share = Share.get(id=share_id) like_share = Share.update( likenum=F('likenum') + 1).where(id=share_id).execute() user_leaf = User.update( user_leaf=F('user_leaf') + 4).where(id=share.user).execute() user_leaf = User.update( user_leaf=F('user_leaf') + 2).where( id=self.current_user["user_id"]).execute() likenum = int(likenum) + 1 newlikes = ':) ' + str(likenum) self.write(newlikes)
def post(self): commentbody = self.get_argument("commentbody", None) share_id = self.get_argument("share_id", None) html = markdown2.markdown(commentbody) Comment.create( user_id=self.current_user["user_id"], share_id=share_id, commentbody=commentbody) Share.update( commentnum=F('commentnum') + 1).where(id=share_id).execute() name = tornado.escape.xhtml_escape(self.current_user["user_name"]) gravatar = get_avatar(self.current_user["user_email"], 50) newcomment = '' newcomment += ' <div class="comment">' newcomment += '<div class="avatar">' newcomment += '<img src="' + gravatar + '" />' newcomment += '</div>' newcomment += '<div class="name">' + name + '</div>' newcomment += '<div class="date" title="at"></div>' newcomment += html newcomment += '</div>' self.write(newcomment)
def get(self, name): try: user = User.get(user_domain=name) except: self.redirect("/404") likes = Like.select().where(user_id=user.id).order_by(('id','desc')) likenum = likes.count() for like in likes: share = Share.get(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)
def get(self, id): try: post = Share.get(id=id) except: self.redirect("/404") shares = Share.select() suggest = {} for share in shares: share.score = 100 + share.id - share.user_id + share.commentnum * 3 share.score += share.likenum * 4 + share.hitnum * 0.01 share.score += randint(1, 999) * 0.001 if share.sharetype == post.sharetype: share.score += 5 suggest[share.score] = share.id realsuggest = [] for key in sorted(suggest.iterkeys(), reverse=True): share = Share.get(id=suggest[key]) #share_post = {share.id:share.title} share_post = { 'id': share.id, 'title': share.title, } realsuggest.append(share_post) self.write_json(realsuggest)
def get(self, name): try: user = User.get(user_domain=name) except: self.redirect("/404") likes = Like.select().where(user_id=user.id).order_by(('id', 'desc')) likenum = likes.count() for like in likes: share = Share.get(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)
def get(self): page = self.get_argument("page", "1") realpage = int(page) shares = Share.select().order_by(('id', 'desc')).paginate(realpage, 10) sharesum = shares.count() pagesum = (sharesum + 9) / 10 for share in shares: user = User.get(id=share.user_id) share.name = user.user_name share.domain = user.user_domain share.markdown = markdown.markdown(share.markdown) share.markdown = filter_tags(share.markdown)[:100] share.gravatar = get_avatar(user.user_email, 16) members = User.select().order_by('id').paginate(1, 20) for member in members: user = User.get(id=member.id) member.gravatar = get_avatar(user.user_email, 35) print(type(shares)) suggests = Share.select().order_by( ('status', 'desc'), ('id', 'desc')).limit(5) self.render( "index.html", shares=shares, members=members, pagesum=pagesum, page=page, node='home')
def get(self): page = self.get_argument("page", "1") realpage = int(page) shares = Share.select().order_by(('id', 'desc')).paginate(realpage, 10) sharesum = shares.count() pagesum = (sharesum + 9) / 10 for share in shares: user = User.get(id=share.user_id) share.name = user.user_name share.domain = user.user_domain share.markdown = filter_tags( markdown.markdown(share.markdown))[:100] share.gravatar = get_avatar(user.user_email, 16) members = User.select().order_by(('id', 'desc')).paginate(1, 20) for member in members: user = User.get(id=member.id) member.gravatar = get_avatar(user.user_email, 25) Share.select().order_by( ('status', 'desc'), ('id', 'desc')).limit(5) node = 'home' node_about = options.node_about[node] self.render( "node.html", shares=shares, members=members, pagesum=pagesum, page=page, node=node, node_about=node_about)
def get(self, node): page = self.get_argument("page", "1") realpage = int(page) shares = Share.select().where( sharetype=node).order_by('id').paginate(realpage, 10) sharesum = shares.count() pagesum = (sharesum + 9) / 10 for share in shares: user = User.get(id=share.user_id) share.name = user.user_name share.domain = user.user_domain share.markdown = filter_tags(share.markdown)[:100] share.gravatar = get_avatar(user.user_email, 16) members = User.select().order_by('id').paginate(1, 20) for member in members: user = User.get(id=member.id) member.gravatar = get_avatar(user.user_email, 35) self.render( "node.html", shares=shares, members=members, pagesum=pagesum, page=page, node=node)
def get(self): realpath = self.request.path[1:] try: share = Share.get(slug=realpath) except: self.redirect("/404") share.markdown = markdown.markdown(share.markdown) if self.current_user: share.is_liking = Like.select().where( share_id=share.id, user_id=self.current_user["user_id"]).count() > 0 comments = Comment.select().where(share_id=share.id) for comment in comments: user = User.get(id=comment.user_id) comment.name = user.user_name comment.domain = user.user_domain comment.gravatar = get_avatar(user.user_email, 50) Share.update(hitnum=F('hitnum') + 1).where( id=share.id).execute() if self.current_user: is_hitted = Hit.select().where( share_id=share.id, user_id=self.current_user["user_id"]).count() > 0 Hit.create( hitnum=1, share_id=share.id, user_id=self.current_user["user_id"], ) else: is_hitted = self.get_cookie(share.id) if not is_hitted: self.set_cookie(str(share.id), "1") posts = Share.select() 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 if post.sharetype == share.sharetype: post.score += 5 if self.current_user: is_hitted = Hit.select().where( share_id=post.id, user_id=self.current_user["user_id"]).count() > 0 else: is_hitted = self.get_cookie(share.id) if is_hitted: post.score -= 50 suggest[post.score] = post.id print(post.id) print(post.score) realsuggest = [] i = 1 for key in sorted(suggest.iterkeys(), reverse=True): post = Share.get(id=suggest[key]) share_post = {'id': post.id, 'title': post.title, } realsuggest.append(share_post) i = i + 1 if i > 3: break self.render( "sharee.html", share=share, comments=comments, realsuggest=realsuggest)
def get(self): shares = Share.select() self.set_header("Content-Type", "application/atom+xml") self.render("feed.xml", shares=shares)
def get(self): id = self.get_argument("id", None) share = None if id: share = Share.get(id=id) self.render("share.html", share=share)