Beispiel #1
0
 def get(self, article_sn=None):
     # Export one single article or a bunch of articles
     current_user = self.get_current_user()
     if article_sn:
         chunk = da.get_article_by_sn(int(article_sn))
         if chunk['author'] == current_user['uid']:
             chunk['date'] = (chunk['date'] + 
                        datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M") 
             chunk['review'] = (chunk['review'] + 
                        datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M")
             del chunk['_id'] 
             self.finish(chunk)     
         else:
             self.send_error(403)       
Beispiel #2
0
 def get(self, article_sn=None):
     # Export one single article or a bunch of articles
     current_user = self.get_current_user()
     if article_sn:
         chunk = da.get_article_by_sn(int(article_sn))
         if chunk['author'] == current_user['uid']:
             chunk['date'] = (chunk['date'] + 
                        datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M") 
             chunk['review'] = (chunk['review'] + 
                        datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M")
             del chunk['_id'] 
             self.finish(chunk)     
         else:
             self.send_error(403)       
Beispiel #3
0
    def get(self, article_sn):
        article = da.get_article_by_sn(int(article_sn))
        if not article or article['status'] == cst.DELETED:
            self.send_error(404)
            self.finish()
        else:
            article = Article(article) # wrapped

        article = dict(
            sn = article.sn, # usage: widgets/comment.html
            author = article.author,
            title = article.title,
            body = article.html,
            heat = article.heat, # usage: widgets/article-status.html
            date = article.date,
            review = article.review,
        )

        author = self.get_user(uid=article['author'])

        cmts = da.get_comment_list_by_sn(article_sn)
        comments = []
        for cmt in cmts:
            cmt = Comment(cmt)
            comments.append(dict(
                member = cmt.member,
                date = cmt.date,
                floor = cmt.cid,
                body = cmt.body
            ))

        current_user = self.get_current_user()

        da.heat_article_by_sn(int(article_sn)) # increase 'heat' tag then save

        adjoins = da.find_adjoins(article['date'])

        article['date'] = (article['date'] + 
                       datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M") 
        article['review'] = (article['review'] + 
                       datetime.timedelta(hours=8)).strftime("%Y-%m-%d %H:%M") 

        self.render("article.html", 
                    adjoins = adjoins,
                    master = current_user,
                    comments = comments, 
                    title = article['title'],
                    author = author, 
                    article = article)
Beispiel #4
0
 def get(self, sn):
     t = Article(da.get_article_by_sn(int(sn))) # wrapped
     current_user = self.get_current_user() # wrapped
     article = dict(
         sn = t.sn, # usage: widgets/comment.html
         title = t.title,
         sub_title = t.sub_title,
         markdown = t.markdown,
         author = t.author,
     )
     if article['author'] == current_user['uid']:
         self.render("edit.html", 
                     title = "Edit",
                     master=current_user,
                     article = article)
     else:
         self.send_error(403)
         self.finish()
Beispiel #5
0
 def get(self, sn):
     t = Article(da.get_article_by_sn(int(sn))) # wrapped
     current_user = self.get_current_user() # wrapped
     article = dict(
         sn = t.sn, # usage: widgets/comment.html
         title = t.title,
         sub_title = t.sub_title,
         markdown = t.markdown,
         author = t.author,
     )
     if article['author'] == current_user['uid']:
         self.render("edit.html", 
                     title = "Edit",
                     master=current_user,
                     article = article)
     else:
         self.send_error(403)
         self.finish()
Beispiel #6
0
 def delete(self, article_sn):
     # This currently is a ajax call
     # Request URL:/article/ARTICLE
     # Request Method:DELETE
     current_user = self.get_current_user()
     article = Article(da.get_article_by_sn(int(article_sn))) # wrapped
     if current_user['uid'] != article.author:
         self.finish(json.dumps(False))
     else:
         if article.status == cst.DELETED:
             # Remove related data, like comments
             # Remove article that already markded "deleted".
             article.remove()
             da.remove_comments_with_article(int(article_sn))
         else:
             # Just mark the article "deleted", not remove it.
             article.set_status(cst.DELETED)
             article.put()
         self.finish(json.dumps(True))
Beispiel #7
0
 def delete(self, article_sn):
     # This currently is a ajax call
     # Request URL:/article/ARTICLE
     # Request Method:DELETE
     current_user = self.get_current_user()
     article = Article(da.get_article_by_sn(int(article_sn))) # wrapped
     if current_user['uid'] != article.author:
         self.finish(json.dumps(False))
     else:
         if article.status == cst.DELETED:
             # Remove related data, like comments
             # Remove article that already markded "deleted".
             article.remove()
             da.remove_comments_with_article(int(article_sn))
         else:
             # Just mark the article "deleted", not remove it.
             article.set_status(cst.DELETED)
             article.put()
         self.finish(json.dumps(True))
Beispiel #8
0
    def post(self, sn):
        # get post values
        post_values = ['title', 'brief', 'content']
        args = {}
        for v in post_values:
            # Get nessary argument
            # Use None as default if argument is not supplied
            args[v] = self.get_argument(v, None)

        current_user = self.get_current_user() # wrapped

        article = Article(da.get_article_by_sn(int(sn)))
        
        article.set_title(args['title'])
        article.set_sub_title(args['brief'])
        article.set_markdown(args['content'])
        article.set_html(markdown(args['content'], 
                        ['fenced_code', 'codehilite'], 
                        safe_mode= "escape"))
        article.set_review()
        article.put()
        self.redirect("/article/%s" % sn)
Beispiel #9
0
    def post(self, sn):
        # get post values
        post_values = ['title', 'brief', 'content']
        args = {}
        for v in post_values:
            # Get nessary argument
            # Use None as default if argument is not supplied
            args[v] = self.get_argument(v, None)

        current_user = self.get_current_user() # wrapped

        article = Article(da.get_article_by_sn(int(sn)))
        
        article.set_title(args['title'])
        article.set_sub_title(args['brief'])
        article.set_markdown(args['content'])
        article.set_html(markdown(args['content'], 
                        ['fenced_code', 'codehilite'], 
                        safe_mode= "escape"))
        article.set_review()
        article.put()
        self.redirect("/article/%s" % sn)