Пример #1
0
    def put(self, _id):
        """
            @description: 修改一个文章

            @param body:
            @type body: C{SymbolReq}
            @in body: body
            @required body: True

            @rtype: L{Resp}
            @raise 400: Invalid Input
            @raise 500: Internal Server Error
        """
        logging.debug(self.request.body)

        symbol = None
        try:
            symbol = json_decode(self.request.body)
        except:
            logging.warn("Bad Request[400]: update symbol=[%r]",
                         self.request.body)

            self.set_status(200)  # Bad Request
            self.write(JSON.dumps({"errCode": 400, "errMsg": "Bad Request"}))
            self.finish()
            return

        symbol["mtime"] = current_timestamp()
        symbol_dao.symbol_dao().insert(_id, symbol)

        logging.debug("Success[200]: update symbol=[%r]", symbol)
        self.set_status(200)  # Created
        self.write(JSON.dumps({"errCode": 200, "errMsg": "Success"}))
        self.finish()
        return
Пример #2
0
    def post(self):
        title = self.get_argument("title", "")
        sub_title = self.get_argument("sub_title", "")
        article_img = self.get_argument("article_img", "")
        paragraphs = self.get_argument("paragraphs", "")
        categories = self.get_arguments("categories")

        symbol = {
            "symbol": {
                "title": title,
                "sub_title": sub_title,
                "img": article_img,
                "paragraphs": paragraphs
            }
        }
        article_id = generate_uuid_str()
        symbol["_id"] = article_id
        symbol["ctime"] = current_timestamp()
        symbol["mtime"] = symbol["ctime"]
        symbol_dao.symbol_dao().insert(article_id, symbol)
        yield article_dao.article_dao().insert(symbol)
        logging.info("Success[200]: create symbol=[%r]", symbol)

        for category_id in categories:
            yield article_categories_dao.article_categories_dao().insert(
                article_id, category_id)
        logging.info("Success[200]: insert article=[%r] categories=[%r]",
                     article_id, categories)

        self.redirect("/admin/blog-grid")
Пример #3
0
    def post(self):
        article_id = self.get_argument("article_id", "")
        title = self.get_argument("title", "")
        sub_title = self.get_argument("sub_title", "")
        article_img = self.get_argument("article_img", "")
        paragraphs = self.get_argument("paragraphs", "")
        categories = self.get_arguments("categories")

        if not article_img:
            old_symbol = symbol_dao.symbol_dao().find(article_id)
            if old_symbol and old_symbol["symbol"].has_key("img"):
                article_img = old_symbol["symbol"]["img"]

        symbol = {
            "symbol": {
                "title": title,
                "sub_title": sub_title,
                "img": article_img,
                "paragraphs": paragraphs
            }
        }
        symbol["_id"] = article_id
        symbol["mtime"] = current_timestamp()
        symbol_dao.symbol_dao().insert(article_id, symbol)
        logging.info("Success[200]: modify symbol=[%r]", symbol)

        yield article_categories_dao.article_categories_dao().delete_all(
            article_id)
        for category_id in categories:
            yield article_categories_dao.article_categories_dao().insert(
                article_id, category_id)
        logging.info("Success[200]: update article=[%r] categories=[%r]",
                     article_id, categories)

        self.redirect("/admin/blog-details/" + article_id)
Пример #4
0
    def get(self):
        category_id = "db957c6ed38611e8be700017fa03296f"
        articles = yield article_categories_dao.article_categories_dao(
        ).find_pagination(category_id, 0, 3)
        news = []
        for article in articles:
            data = symbol_dao.symbol_dao().find(article["article_id"])
            data["mtime"] = timestamp_to_date(data["mtime"])
            news.append(data)

        category_id = "9771de04d38811e8ab5c0017fa03296f"
        articles = yield article_categories_dao.article_categories_dao(
        ).find_pagination(category_id, 0, 3)
        projects = []
        for article in articles:
            data = symbol_dao.symbol_dao().find(article["article_id"])
            projects.append(data)

        category_id = "475d7b40d37d11e887b20017fa03296f"
        articles = yield article_categories_dao.article_categories_dao(
        ).find_pagination(category_id, 0, 3)
        services = []
        for article in articles:
            data = symbol_dao.symbol_dao().find(article["article_id"])
            services.append(data)

        self.render('index.html',
                    services=services,
                    projects=projects,
                    news=news)
Пример #5
0
    def delete(self, _id):
        """
            @description: 删除一个对象

            @rtype: L{Resp}
            @raise 400: Invalid Input
            @raise 500: Internal Server Error
        """
        symbol_dao.symbol_dao().delete(_id)

        logging.debug("Success[200]: delete symbol=[%r]", _id)
        self.set_status(200)  # OK
        self.write(JSON.dumps({"errCode": 200, "errMsg": "Success"}))
        self.finish()
        return
Пример #6
0
    def post(self):
        """
            @description: 创建一个对象

            @param body:
            @type body: C{SymbolReq}
            @in body: body
            @required body: True

            @rtype: L{Resp}
            @raise 400: Invalid Input
            @raise 500: Internal Server Error
        """
        logging.debug(self.request.body)

        symbol = None
        try:
            symbol = json_decode(self.request.body)
        except:
            logging.warn("Bad Request[400]: create symbol=[%r]",
                         self.request.body)

            self.set_status(200)  # Bad Request
            self.write(JSON.dumps({"errCode": 400, "errMsg": "Bad Request"}))
            self.finish()
            return

        symbol_id = None
        if symbol.has_key("_id"):
            symbol_id = symbol["_id"]
            symbol["mtime"] = current_timestamp()
            symbol_dao.symbol_dao().insert(symbol_id, symbol)
            logging.debug("Success[200]: update symbol=[%r]", symbol)
        else:
            symbol_id = generate_uuid_str()
            symbol["_id"] = symbol_id
            symbol["ctime"] = current_timestamp()
            symbol_dao.symbol_dao().insert(symbol_id, symbol)
            logging.debug("Success[200]: create symbol=[%r]", symbol)
        self.set_status(200)  # Created
        self.write(
            JSON.dumps({
                "errCode": 200,
                "errMsg": "Success",
                "rs": symbol_id
            }))
        self.finish()
        return
Пример #7
0
    def get(self, _id):
        """
            @description: 读取一个文章

            @rtype: L{Resp}
            @raise 400: Invalid Input
            @raise 500: Internal Server Error
        """
        symbol = symbol_dao.symbol_dao().find(_id)
        if symbol:
            logging.debug("OK(200): got symbol=[%r] from ssdb", symbol)
            self.set_status(200)  # OK
            self.write(
                JSON.dumps({
                    "errCode": 200,
                    "errMsg": "Success",
                    "rs": symbol
                }))
            self.finish()
            return
        else:
            logging.warn("Not Found[404]: got symbol=[%r] from ssdb", _id)
            self.set_status(200)  # Not Found
            self.write(JSON.dumps({"errCode": 404, "errMsg": "Not Found"}))
            self.finish()
            return
Пример #8
0
 def get(self, article_id):
     data = symbol_dao.symbol_dao().find(article_id)
     data["symbol"]["mtime"] = timestamp_to_datehourmin(data["mtime"])
     categories = yield category_dao.category_dao().find_all()
     self.render('blog-details.html',
                 article=data["symbol"],
                 categories=categories)
Пример #9
0
    def get(self, article_id):
        data = symbol_dao.symbol_dao().find(article_id)
        categories = yield category_dao.category_dao().find_all()

        self.render('admin/blog-details.html',
                    article_id=article_id,
                    article=data["symbol"],
                    categories=categories)
Пример #10
0
    def get(self, article_id):
        data = symbol_dao.symbol_dao().find(article_id)

        categories = yield category_dao.category_dao().find_all()
        for category in categories:
            category["checked"] = False
            info = yield article_categories_dao.article_categories_dao(
            ).find_one(article_id, category["_id"])
            if info:
                category["checked"] = True

        self.render('admin/blog-modify.html',
                    article_id=article_id,
                    article=data["symbol"],
                    categories=categories)
    def get(self, category_id):
        """
            @description: 分页查询一个分类的所有文章

            @param page: default=1
            @type page: L{int}
            @in page: query
            @required page: False

            @param limit: default=20
            @type limit: L{int}
            @in limit: query
            @required limit: False

            @rtype: L{ClientsResp}
            @raise 400: Invalid Input
            @raise 500: Internal Server Error
        """
        page = self.get_argument("page", 1)
        limit = self.get_argument("limit", 20)

        idx = (int(page) - 1) * int(limit)
        total_num = 0
        total_page = 0

        articles = yield article_categories_dao.article_categories_dao(
        ).find_pagination(category_id, idx, limit)
        total_num = yield article_categories_dao.article_categories_dao(
        ).count_pagination(category_id, idx, limit)

        datas = []
        for article in articles:
            data = symbol_dao.symbol_dao().find(article["article_id"])
            datas.append(data)

        if total_num % int(limit) == 0:
            total_page = int(total_num / int(limit))
        else:
            total_page = int(total_num / int(limit)) + 1
        rs = {"page": page, "total_page": total_page, "data": datas}

        logging.debug(
            "OK[200]: query articles: page=[%r] total_page=[%r] num=[%r]",
            page, total_page, len(datas))
        self.set_status(200)  # OK
        self.write(JSON.dumps({"errCode": 200, "errMsg": "Success", "rs": rs}))
        self.finish()
        return
Пример #12
0
 def get(self, article_id):
     data = symbol_dao.symbol_dao().find(article_id)
     self.render('service-details.html', article=data["symbol"])