Ejemplo n.º 1
0
def autoRobotAnswer(id, question_model):
    pid = os.fork()
    if pid != 0:
        return
    url = "http://47.104.98.154:8080/anonymous/wordManage/wenda"
    headers = {'content-type': "application/json"}
    query_string = {"question": question_model.title, "robotid": "1791"}

    if (len(question_model.answers) < 1):

        response = requests.post(url, data=json.dumps(query_string), headers=headers)
        jstr = response.text
        # error : {"result":false,"message":"服务器处理异常!","data":null}
        print jstr
        if (jstr['message'] == 'success'):
            print jstr['message']
            question_id = id
            print question_id

            content = jstr['data']['answers']
            print content
            answer_model = AnswerModel(content=content)
            answer_model.author = 'robot'
            answer_model.question = question_model
            db.session.add(answer_model)
            db.session.commit()
Ejemplo n.º 2
0
def comment():
    question_id = flask.request.form.get('question_id')
    content = flask.request.form.get('content')
    answer_model = AnswerModel(content=content)
    answer_model.author = flask.g.user
    answer_model.question = QuestionModel.query.get(question_id)
    db.session.add(answer_model)
    db.session.commit()
    return flask.redirect(flask.url_for('detail',id=question_id))
Ejemplo n.º 3
0
def comment():
    question_id = flask.request.form.get('question_id')
    content = flask.request.form.get('content')
    answer_model = AnswerModel(content=content)
    answer_model.author = UserModel.query.filter_by(username='******').first()
    answer_model.question = QuestionModel.query.get(question_id)
    db.session.add(answer_model)
    db.session.commit()
    return flask.redirect(flask.url_for('detail',id=question_id))
Ejemplo n.º 4
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('id_survey',
                            help='This field cannot be blank',
                            required=True)
        parser.add_argument('id_company',
                            help='This field cannot be blank',
                            required=True)
        parser.add_argument('file_dari',
                            help='This field cannot be blank',
                            required=False)

        data = parser.parse_args()

        items = SurveyCompanyModel.find_by_company_id(
            id_company=data['id_company'])
        company = CompanyModel.find_by_id(id=data['id_company'])
        version = len(items) + 1
        new_surveycompany = SurveyCompanyModel(
            id_survey=data['id_survey'],
            name_survey=company.commercial_name + ".v" + str(version),
            id_company=data['id_company'],
            version=version,
            status='created',
            start_date=datetime.utcnow(),
            last_date=datetime.utcnow(),
            score=0,
            file_dari=data['file_dari'])
        try:
            survey = SurveyModel.find_by_id(id=data['id_survey'])
            questions = [int(s) for s in survey.questions.split(',')]
            answers_id = []
            for question in questions:
                answer = AnswerModel(id_question=question,
                                     score=-1,
                                     future=False,
                                     id_option=-1,
                                     justification_text='',
                                     justification_file='')
                answer.save_to_db()
                answers_id.append(answer.id)
            new_surveycompany.answers = ','.join([str(i) for i in answers_id])

            new_surveycompany.save_to_db()
            return {
                'message':
                'Survey company ' + str(new_surveycompany.id) + ' was created'
            }
        except Exception as e:
            print(e)
            return {'message': 'Something went wrong ' + str(e)}, 500
Ejemplo n.º 5
0
Archivo: yan.py Proyecto: yanfujin/yan
def comment():
    upload_id = request.form.get('upload_id')
    content = request.form.get('contentt')

    answermodel = AnswerModel(content=content)
    id = session.get('id')
    user = UserModel.query.filter(UserModel.id == id).first()
    answermodel.author = user

    upload = UploadModel.query.filter(UploadModel.id == upload_id).first()
    answermodel.upload = upload
    db.session.add(answermodel)
    db.session.commit()
    return redirect(url_for('detial', id=upload_id))
Ejemplo n.º 6
0
    def get(self):
        results = []
        ids = request.args.get('ids')
        if (ids == None):
            answers = AnswerModel.find_all()
        else:
            answers = AnswerModel.find_by_array(array=ids)
        if (len(answers) == 0):
            return {'data': []}
        else:
            #return jsonify(json_list = questions)
            for item in answers:
                results.append({
                    "id": item.id,
                    "id_question": item.id_question,
                    "id_option": item.id_option,
                    "score": item.score,
                    "future": item.future,
                    "justification_text": item.justification_text,
                    "justification_file": item.justification_file
                })

            return {'data': results}
Ejemplo n.º 7
0
    def get(self, id):
        results = []
        ids = request.args.get('ids')

        item = AnswerModel.find_by_id(id=id)
        if (item == None):
            return {'data': []}
        else:
            #return jsonify(json_list = questions)
            return {
                "id": item.id,
                "id_question": item.id_question,
                "id_option": item.id_option,
                "score": item.score,
                "future": item.future,
                "justification_text": item.justification_text,
                "justification_file": item.justification_file
            }
Ejemplo n.º 8
0
 def put(self, id):
     item = AnswerModel.find_by_id(id=id)
     if (item == None):
         return {'data': []}
     else:
         data = request.json['answer']
         if (data['id_option'] != None):
             item.id_option = data['id_option']
         if (data['justification_text'] != None):
             item.justification_text = data['justification_text']
         if (data['justification_file'] != None):
             item.justification_file = data['justification_file']
         if (data['score'] != None):
             item.score = data['score']
         try:
             item.save_to_db()
             return {'message': 'answer {} was updated'.format(str(id))}
         except Exception as e:
             print(e)
             return {'message': 'Something went wrong ' + str(e)}, 500