Beispiel #1
0
 def _get_handler(self):
     params = self.validator.data
     log.debug('class=QuestionViewHandler|params=%s', params)
     name = self.req.input()['name']
     params['name'] = name
     question_id = params.get('question_id')
     question = Questions(question_id)
     question.load()
     if question.data['content']:
         content = base64.decode(question.data['content'])
         params['content'] = content
     return success(data=question.data)
Beispiel #2
0
 def _post_handler(self):
     data = {}
     values = {}
     params = self.validator.data
     question_id = params.pop('question_id')
     status = params.pop('status')
     name = params.pop('name')
     content = self.req.input().get('content')
     if status:
         values['status'] = status
     if name:
         values['name'] = name
     if content:
         content_str = base64.b64encode(content)
         values['content'] = content_str
     values['utime'] = tools.gen_now_str()
     question = Questions(question_id)
     ret = question.update(values)
     return success(data=data)
Beispiel #3
0
 def _get_handler(self):
     data = {}
     params = self.validator.data
     parent = params.get('parent')
     ret = Questions.load_by_parent_single(parent)
     if ret:
         for record in ret:
             if not record['content']:
                 continue
             content = base64.b64decode(record['content'])
             record['content'] = content
     data['children'] = ret if ret else []
     return success(data=data)
Beispiel #4
0
 def _get_handler(self):
     ret = []
     params = self.validator.data
     parent = params.get('parent')
     if not parent:
         parent = -1
     data = Questions.load_current_children(parent=parent)
     if data:
         for record in data:
             if not record['content']:
                 continue
             else:
                 content = base64.b64decode(record['content'])
                 record['content'] = content
     ret.extend(data)
     return json.dumps(ret)
Beispiel #5
0
    def _post_handler(self):
        data = {}
        params = self.validator.data
        log.debug('class=QuestionAddHandler|params=%s', params)
        name = self.req.input()['name']
        save_type = params['save_type']
        category = params['category']
        content = self.req.input()['content']
        # 如果是答案且存储类型为富文本校验content
        if content:
            base64_str = base64.b64encode(content)
            params['content'] = base64_str

        params['name'] = name
        params.update({
            'utime': tools.gen_now_str(),
            'ctime': tools.gen_now_str(),
        })
        ret = Questions.create(params)
        return success(data=data)
Beispiel #6
0
    def _get_handler(self):
        data = {}

        params = self.validator.data
        info, num = Questions.page(**params)
        data['num'] = num
        if info:
            for item in info:
                item['id'] = str(item['id'])
                item['parent'] = str(item['parent'])
                item['ctime'] = tools.trans_datetime(item['ctime'])
                item['utime'] = tools.trans_datetime(item['utime'])
                item['status_desc'] = define.QUESTION_STATUS[item['status']]
                item['category_desc'] = define.QUESTION_MAP[item['category']]
                if item['parent'] != -1:
                    question = Questions(item['id'])
                    question.load()
                    parent_parent = question.find_parent_parent()
                    item['parent_parent'] = parent_parent
                else:
                    item['parent_parent'] = -1
        data['info'] = info
        return success(data=data)
Beispiel #7
0
 def _get_handler(self):
     ret = []
     data = Questions.load_all()
     ret.extend(data)
     return json.dumps(ret)