Exemplo n.º 1
0
 def detailData(self, iKwargs):
     category = CategoryModel.find({'mk': iKwargs['mk']})
     articlelist = category.getArticleIDList()
     allList = []
     for articleId in articlelist:
         article = ArticleModel.mustFindOne(articleId)
         articledata = {
             'id': str(article.get('_id', '')),
             'mk': article.get('mk', ''),
             'title': article.get('title', ''),
             'summary': article.get('summary', ''),
             'createYear': article.get('createDate', '')[:4],
             'createDate': article.get('createDate', '')[5:10],
             'updateDate': article.get('updateDate', '')[:10],
             'category': article.get('category', ''),
         }
         allList.append(articledata)
     data = {'articlelist': allList, 'name': category.get('name', '')}
     return data
Exemplo n.º 2
0
    def post(self):
        iKwargs = request.form.to_dict()
        VaiLogs.info(iKwargs)
        # 创建一篇新文章
        newarticle = ArticleModel.create(iKwargs)
        # 添加文章目录分类 只能一个目录分类
        article = ArticleModel.mustFindOne(str(newarticle.get('_id')))
        if 'category' in iKwargs:
            category = CategoryModel.find({'name': iKwargs["category"]})
            # if 'cateid' in iKwargs:
            #     category = CategoryModel.mustFindOne(iKwargs['cateid'])
            category.addArticleModel(article)
            VaiLogs.info(category)
            cate = {
                "mk": category.get("mk", ""),
                "name": category.get("name", "")
            }
            article.set('category', cate)
            article.save()

        # 添加文章tag属性 可以多个tag属性
        if 'taglist' in iKwargs:
            tagList = eval(iKwargs['taglist'])
            for tagid in tagList:
                tag = TagModel.mustFindOne(tagid)
                tag.addArticleModel(article)
                article.addTagModel(tag)

        resp = {
            'id': str(article.get('_id', '')),
            'mk': str(article.get('mk', '')),
            'title': article.get('title', ''),
            'summary': article.get('summary', ''),
            'content': article.get('content', ''),
            'category': article.get('category', ''),
            'tag': article.get('tag', ''),
            'createDate': article.get('createDate', ''),
            'updateDate': article.get('updateDate', '')
        }
        return resp
Exemplo n.º 3
0
class Controller:
    def __init__(self):
        self.category = Category()

    def create(self, request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            data['creator'] = res['data']['username']
            result = self.category.save(data)
            if result == None:
                return response({}, code=50000, message='该分类已存在!')
            return response({}, code=20000, message='创建成功!')
        else:
            return p

    def getList(self, request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            result = self.category.find(data)
            return response(result, code=20000, message='获取成功!')
        else:
            return p
    def delete(self,request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            result = self.category.delete(data)
            print(type(result))
            return response({}, code=20000, message='删除成功!')
        else:
            return p
    def edit(self,request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            result = self.category.update_one(data['id'],data)
            if result == None:
                return response({}, code=50000, message='该分类已存在!')
            return response({}, code=20000, message='修改成功!')
        else:
            return p
    def delete(self,request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            data = json.loads(request.get_data())
            result = self.category.delete(data)
            print(type(result))
            return response({}, code=20000, message='删除成功!')
        else:
            return p
    def getCascader(self,request):
        p = Jwt.authHeader(request)
        res = json.loads(p)
        if res['code'] == 20000:
            results=self.category.findAll()
            series = []
            for result in results:
                series.append(result['series'])
            formatList = list({}.fromkeys(series).keys())
            data = []
            for i in formatList:
                children = []
                for result in results:
                    if result['series'] == i:
                        children.append({"label": result['label'], "value": result['value']})
                data.append({"value": i, "label": i, "children": children})
            return response(data, code=20000, message='获取成功!')
        else:
            return p