Example #1
0
def add_exam():
    # mount exam object
    try:
        posted_exam = ExamSchema(only=('title', 'description', 'long_description')) \
            .load(request.get_json())

        exam = Exam(**posted_exam, created_by="HTTP post request")

        # persist exam
        session = Session()

        session.add(exam)

        session.commit()

        # return created exam
        new_exam = ExamSchema().dump(exam)

        session.close()

        return jsonify(new_exam), 201
    except Exception as ex:
        x = ex.args;
        return """{
        "created_at": "2019-09-20T15:51:18.849454",
        "description": """ + str(x) + """,
Example #2
0
def delete_exam(examId):
    session = Session()
    exam = session.query(Exam).filter_by(id=examId).first()
    session.delete(exam)
    session.commit()
    session.close()
    return '', 201
Example #3
0
def delete_user(id):
    session = Session()
    user = session.query(User).filter(User.id == id).first()
    session.delete(user)
    session.commit()
    session.close()
    return "", 200
Example #4
0
def delete_offer(id):
    session = Session()
    offer = session.query(Offer).filter(Offer.id == id).first()
    session.delete(offer)
    session.commit()
    session.close()
    return "", 200
Example #5
0
def delete_publishment():
    id = get_parameter('id')

    session = Session()
    try:
        session.query(Publishment).filter(Publishment.id == id).delete()
        session.commit()
    finally:
        session.close()

    return jsonify({'status': 'OK'})
Example #6
0
def deleteOldPasswordChangeId():
    try:
        expireTime = datetime.datetime.now() - datetime.timedelta(minutes=10)
        session = Session()
        expiredIds = session.query(IdCambioContrasenna).filter(
            IdCambioContrasenna.fechaCreacion < expireTime).all()

        for id in expiredIds:
            session.delete(id)
        session.commit()
        return '', 200
    except:
        return '', 400
Example #7
0
def undibs():
    id = request.get_json()["offer_id"]

    session = Session()
    offer = session.query(Offer).filter(Offer.id == id).first()

    offer.dibsedby_id = None
    session.commit()
    offer = session.query(Offer).filter(Offer.id == id).first()
    app.logger.debug(offer.dibsedby_id)

    session.close()
    return "", 200
Example #8
0
def dibs():
    ids = request.get_json()
    user_id = ids["user_id"]
    offer_id = ids["offer_id"]

    session = Session()
    offer = session.query(Offer).filter(Offer.id == offer_id).first()

    offer.dibsedby_id = user_id
    session.commit()

    session.close()
    return "", 200
Example #9
0
def add_offer():
    posted_offer = OfferSchema(only=("title", "description", "lat", "lng",
                                     "owner_id")).load(request.get_json())

    offer = Offer(**posted_offer)

    # Persist
    session = Session()
    session.add(offer)
    session.commit()

    # return
    new_offer = OfferSchema().dump(offer)
    session.close()
    return jsonify(new_offer), 200
Example #10
0
def add_exam():
    # mount exam object
    posted_exam = ExamSchema(only=('title', 'description'))\
        .load(request.get_json())

    exam = Exam(**posted_exam.data, created_by="HTTP post request")

    # persist exam
    session = Session()
    session.add(exam)
    session.commit()

    # return created exam
    new_exam = ExamSchema().dump(exam).data
    session.close()
    return jsonify(new_exam), 201
Example #11
0
def add_publishment():
    params_dict = request.get_json()
    params_dict['git_branches'] = ','.join(params_dict.get('git_branches'))
    params_dict['to_ip'] = ','.join(params_dict.get('to_ip'))
    params_dict['git_delete_temp_branch'] = 1 if params_dict.get('git_delete_temp_branch') else 0
    posted_publishment = PublishmentSchema().load(params_dict)
    publishment = Publishment(**posted_publishment, created_by="HTTP post request")

    session = Session()
    try:
        session.add(publishment)
        session.commit()
    finally:
        session.close()

    return jsonify({'status': 'OK'})
Example #12
0
def add_user():
    posted_user = UserSchema(only=("name", "email", "telegram",
                                   "pw")).load(request.get_json())

    user = User(**posted_user)

    session = Session()
    try:
        session.add(user)
        session.commit()
    except Exception:
        session.close()
        return 'User with that name already exists', 500

    new_user = UserSchema().dump(user)
    session.close()
    return jsonify(new_user), 200
Example #13
0
def update_publishment():
    params_dict = request.get_json()
    id = params_dict['id']
    params_dict['git_branches'] = ','.join(params_dict.get('git_branches'))
    params_dict['to_ip'] = ','.join(params_dict.get('to_ip'))
    params_dict['git_delete_temp_branch'] = 1 if params_dict.get('git_delete_temp_branch') else 0
    params_dict.pop('id')
    params_dict.pop('git_repo')

    session = Session()
    try:
        session.query(Publishment).filter(Publishment.id == id).update(params_dict)
        session.commit()
    finally:
        session.close()

    return jsonify({'status': 'OK'})