Example #1
0
 def post(self):
     #new comment
     sessionhelper = SessionHelper(self,self.db)
     correct_user = sessionhelper.checkSession()
     response = {}
     if correct_user!=None:
         try:
             article_id = self.get_argument("article_id")
             comment_content = self.get_argument("comment_content")
             posttime = time.strftime('%Y-%m-%d %X',time.localtime(time.time()))
             comment = Comment(
                 article_id=article_id, 
                 comment_content=comment_content,
                 commenter_id=correct_user.user_id,
                 commenter_name=correct_user.user_name,
                 comment_time=posttime
                 )
             self.db.add(comment)
             self.db.commit()
             response["status"]=200
             response["data"]='comment success'
             self.write(response)
             self.redirect("/article?article_id=%s"%(article_id))
         except Exception, e:
             response["status"]=400
             response["data"]=str(e)
             self.db.rollback()
             self.write(response)
Example #2
0
 def post(self):
     # new article
     sessionhelper = SessionHelper(self,self.db)
     correct_user = sessionhelper.checkSession()
     response = {}
     if correct_user!=None:
         try:
             article_content = self.get_argument("article_content")
             print article_content
             article_title = self.get_argument("article_title")
             username = correct_user.user_name
             posttime = time.strftime('%Y-%m-%d %X',time.localtime(time.time()))
             article = Article(
                 user_id = correct_user.user_id,
                 user_name = username,
                 title = article_title,
                 content = article_content,
                 time = posttime)
             self.db.add(article)
             self.db.commit()
             response["status"]=200
             response["data"]='success'
             self.write(response)
         except Exception, e:
             response["status"]=400
             response["data"]=str(e)
             self.db.rollback()
             self.write(response)
Example #3
0
 def get(self):
     #page for write article
     sessionhelper = SessionHelper(self,self.db)
     correct_user = sessionhelper.checkSession()
     if correct_user==None:
         self.render("homepage/login.html",correct_user=correct_user)
     else:
         self.render("articlewrite.html",correct_user=correct_user)
Example #4
0
 def get(self):
     #get article by id
     sessionhelper = SessionHelper(self,self.db)
     article_id = self.get_argument("article_id")
     article = self.db.query(Article).filter(Article.article_id == article_id).first()
     comments = self.db.query(Comment).filter(Comment.article_id == article_id).order_by(Comment.comment_id).all()
     urls={}
     for comment in comments:
         commenter = self.db.query(User).filter(User.user_id == comment.commenter_id).first()
         urls[commenter.user_id]=GravatarHelper(commenter.user_email,240).getUrl()
     self.render("article.html",
         article=article,
         comments=comments,
         urls=urls,
         correct_user=sessionhelper.checkSession())
     pass
Example #5
0
 def get(self):
     sessionhelper = SessionHelper(self,self.db)
     correct_user = sessionhelper.checkSession()
     blog_user_id = self.get_argument("id")
     blog_user = self.db.query(User).filter(User.user_id == blog_user_id).first()
     if blog_user == None:
         self.render("homepage/404error.html",
             correct_user=correct_user)
     else:
         articles = self.db.query(Article).filter(Article.user_id == blog_user_id).all()
         gravatar_url =GravatarHelper(blog_user.user_email,240).getUrl()
         self.render("blog.html",
             correct_user=correct_user,
             articles=articles,
             blog_user=blog_user,
             gravatar_url=gravatar_url)
Example #6
0
 def get(self,args):
     askurl = args[0::]
     print "In home handler:"+askurl
     session_helper = SessionHelper(self,self.db)
     correct_user = session_helper.checkSession()
     # correct_user = self.checkSession()
     if askurl == "login":
         ####login
         if correct_user == None:
             self.render('homepage/login.html',
                 correct_user=correct_user)
         else:
             print correct_user.user_id
             self.render('homepage/index.html',
                 correct_user=correct_user)
     elif askurl == "index":
         self.render('homepage/index.html',
             correct_user=correct_user)
     elif askurl == "rank":
         self.RankPageHandler(correct_user)
     else:
         self.render('homepage/%s.html'%(askurl),
             correct_user=correct_user)