示例#1
0
def add_user():
    request_body = request.get_json()
    now = datetime.datetime.now()
    user = User(name=request_body["name"], email=request_body["email"], password=request_body["password"], id_role=2, created=now, last_update=now)
    user.save()
    DBManager.commitSession()
    return jsonify("User added"), 200
示例#2
0
def add_answer_image():
    request_body = request.get_json()
    now = datetime.datetime.now()
    answer_image = AnswerImages(id_answer=request_body["id_answer"], url=request_body["url"],
    size=request_body["size"], created=now, last_update=now)
    answer_image.save()
    DBManager.commitSession()
    return jsonify("Answer Image added"), 200
示例#3
0
def add_question_image():
    request_body = request.get_json()
    now = datetime.datetime.now()
    question_image = QuestionImages(id_question=request_body["id_question"], url=request_body["url"],
    size=request_body["size"], created=now, last_update=now)
    question_image.save()
    DBManager.commitSession()   
    return jsonify("Question Image added"), 200
示例#4
0
def add_answer():
    request_body = request.get_json()
    now = datetime.datetime.now()
    answer = Answer(id_question=request_body["id_question"], id_user=request_body["id_user"],  
    description=request_body["description"], link=request_body["link"], created=now, last_update=now)
    answer.save()
    DBManager.commitSession()
    return jsonify({"status": "OK", "msg": "Answer added", "answer": answer.serialize()}), 200
示例#5
0
def add_question():
    request_body = request.get_json()
    now = datetime.datetime.now()
    question = Question(id_user=request_body["id_user"], title=request_body["title"], 
    description=request_body["description"], link=request_body["link"], created=now, last_update=now)
    question.save()
    DBManager.commitSession()
    return jsonify({"status": "OK", "msg": "Question added", "question": question.serialize()}), 200
示例#6
0
def create_roles():
    print("create_roles")
    now = datetime.datetime.now()
    if not Role.query.get(1):
        role = Role(id=1, name="Admin", created=now, last_update=now)
        role.save()
    if not Role.query.get(2):
        role = Role(id=2, name="User", created=now, last_update=now)
        role.save()
    DBManager.commitSession()
    return
示例#7
0
def upload_answer_images():
    files = request.files
    id_answer = request.form.get('id_answer')
    for key in files:
        file = files[key]
        if file:
            url_image = upload_file_to_s3(file, os.environ.get('S3_BUCKET_NAME'))
            now = datetime.datetime.now()
            answer_image = AnswerImages(id_answer=id_answer, url=url_image, 
            size=0, created=now, last_update=now)
            answer_image.save()
            DBManager.commitSession()
    return jsonify("OK"), 200
示例#8
0
def upload_question_images():
    print("upload_question_images")
    files = request.files
    print(files)
    id_question = request.form.get('id_question')
    for key in files:
        print(key)
        file = files[key]
        if file:
            print(file)
            url_image = upload_file_to_s3(file, os.environ.get('S3_BUCKET_NAME'))
            print(url_image)
            now = datetime.datetime.now()
            question_image = QuestionImages(id_question=id_question, url=url_image, 
            size=0, created=now, last_update=now)
            question_image.save()
            DBManager.commitSession()
    return jsonify("OK"), 200