예제 #1
0
    def find(self, article_id):
        conn = db.get_connection()
        sql = "".join(["select a.id as id,a.author_id as author_id,", 
            "u.name as author_name,a.title as title,a.content as content,a.create_time as create_time,", 
            "a.publish_time as publish_time,a.last_update_time as last_update_time",
            " from article as a left join user as u on a.author_id=u.id",
            " where a.id=%(article_id)s"])
        cursor = conn.cursor()
        cursor.execute(sql, {"article_id": article_id})
        article = None
        for (id, author_id, author_name, title, content, create_time, publish_time, last_update_time) in cursor:
            if (not article):
                article = Article()
            article.id = id
            article.title = title
            article.content = content
            article.create_time = create_time
            article.publish_time = publish_time
            article.last_update_time = last_update_time
            
            if (author_id):
                u = User()
                article.author = u
                u.id = author_id
                u.name = author_name

        cursor.close()
        conn.close()
        return article
예제 #2
0
    def query_most_published_article(self):
        conn = db.get_connection()
        sql = "".join(["select a.id as id,a.author_id as author_id,", 
            "u.name as author_name,a.title as title,a.content as content,a.create_time as create_time,", 
            "a.publish_time as publish_time,a.last_update_time as last_update_time",
            " from article as a left join user as u on a.author_id=u.id",
            " order by a.publish_time desc limit 0,%(page_size)s"])
        cursor = conn.cursor()
        cursor.execute(sql, {"page_size": settings.app_settings["page_size"]})
        articles = None
        for (id, author_id, author_name, title,
                content, create_time, publish_time, last_update_time) in cursor:
            if (not articles):
                articles = []
            article = Article()
            articles.append(article)
            article.id = id

            if (author_id):
                u = User()
                article.author = u
                u.id = author_id
                u.name = author_name
            article.title = title
            article.content = content
            article.create_time = create_time
            article.publish_time = publish_time
            article.last_update_time = last_update_time

        cursor.close()
        conn.close()
        return articles
예제 #3
0
    def find(self, article_id):
        conn = db.get_connection()
        sql = "".join([
            "select a.id as id,a.author_id as author_id,",
            "u.name as author_name,a.title as title,a.content as content,a.create_time as create_time,",
            "a.publish_time as publish_time,a.last_update_time as last_update_time",
            " from article as a left join user as u on a.author_id=u.id",
            " where a.id=%(article_id)s"
        ])
        cursor = conn.cursor()
        cursor.execute(sql, {"article_id": article_id})
        article = None
        for (id, author_id, author_name, title, content, create_time,
             publish_time, last_update_time) in cursor:
            if (not article):
                article = Article()
            article.id = id
            article.title = title
            article.content = content
            article.create_time = create_time
            article.publish_time = publish_time
            article.last_update_time = last_update_time

            if (author_id):
                u = User()
                article.author = u
                u.id = author_id
                u.name = author_name

        cursor.close()
        conn.close()
        return article
예제 #4
0
    def query_most_published_article(self):
        conn = db.get_connection()
        sql = "".join([
            "select a.id as id,a.author_id as author_id,",
            "u.name as author_name,a.title as title,a.content as content,a.create_time as create_time,",
            "a.publish_time as publish_time,a.last_update_time as last_update_time",
            " from article as a left join user as u on a.author_id=u.id",
            " order by a.publish_time desc limit 0,%(page_size)s"
        ])
        cursor = conn.cursor()
        cursor.execute(sql, {"page_size": settings.app_settings["page_size"]})
        articles = None
        for (id, author_id, author_name, title, content, create_time,
             publish_time, last_update_time) in cursor:
            if (not articles):
                articles = []
            article = Article()
            articles.append(article)
            article.id = id

            if (author_id):
                u = User()
                article.author = u
                u.id = author_id
                u.name = author_name
            article.title = title
            article.content = content
            article.create_time = create_time
            article.publish_time = publish_time
            article.last_update_time = last_update_time

        cursor.close()
        conn.close()
        return articles
예제 #5
0
 def post (self):
     title = self.get_argument("title", None)
     content = self.get_argument("content", None)
     article = Article()
     article.title = title
     article.content = content
     id = article_service.add(article)
     self.redirect("/article/" + str(id))
예제 #6
0
 def post(self):
     title = self.get_argument("title", None)
     content = self.get_argument("content", None)
     article = Article()
     article.title = title
     article.content = content
     id = article_service.add(article)
     self.redirect("/article/" + str(id))