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)
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)
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
def get(self, article_id): """ @description: 查询一个文章的所有分类 @rtype: L{ClientsResp} @raise 400: Invalid Input @raise 500: Internal Server Error """ categories = yield article_categories_dao.article_categories_dao( ).find_all(article_id) for category in categories: category_info = yield category_dao.category_dao().find( category["category_id"]) category["name"] = category_info["name"] logging.debug("OK[200]: query article=[%r] categories=[%r]", article_id, len(categories)) self.set_status(200) # OK self.write( JSON.dumps({ "errCode": 200, "errMsg": "Success", "rs": categories })) self.finish() return
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")
def put(self, article_id): """ @description: 修改一个文章的所有分类 @param body: @type body: C{CategoriesReq} @in body: body @required body: True @rtype: L{Resp} @raise 400: Invalid Input @raise 500: Internal Server Error """ logging.debug(self.request.body) categories = None try: categories = json_decode(self.request.body) except: logging.warn("Bad Request[400]: update article=[%r]", self.request.body) self.set_status(200) # Bad Request self.write(JSON.dumps({"errCode": 400, "errMsg": "Bad Request"})) self.finish() return 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.debug("Success[200]: update article=[%r] categories=[%r]", article_id, categories) self.set_status(200) # Created self.write(JSON.dumps({"errCode": 200, "errMsg": "Success"})) self.finish() return
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 delete(self, _id): """ @description: 删除一个文章 @rtype: L{Resp} @raise 400: Invalid Input @raise 500: Internal Server Error """ yield article_categories_dao.article_categories_dao().delete_all(_id) yield article_dao.article_dao().delete(_id) symbol_dao.symbol_dao().delete(_id) logging.debug("Success[200]: delete article=[%r]", _id) self.set_status(200) # OK self.write(JSON.dumps({"errCode": 200, "errMsg": "Success"})) self.finish() return