Пример #1
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
Пример #2
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) + """,
Пример #3
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
Пример #4
0
def publishment_list():
    page_size = 10
    keyword = request.args.get('keyword')
    current_page = request.args.get('current_page')

    session = Session()
    try:
        base_statement = session.query(Publishment).select_from(Publishment) \
            .join(GitRepo, Publishment.git_repo_id == GitRepo.id)
        if keyword:
            base_statement = base_statement.filter(or_(Publishment.name.like('%' + keyword + '%'),
                                                       Publishment.description.like('%' + keyword + '%'),
                                                       Publishment.to_project_home.like('%' + keyword + '%'),
                                                       Publishment.to_process_name.like('%' + keyword + '%'),
                                                       GitRepo.name.like('%' + keyword + '%'),
                                                       GitRepo.description.like('%' + keyword + '%'),
                                                       GitRepo.ssh_url_to_repo.like('%' + keyword + '%'),
                                                       GitRepo.http_url_to_repo.like('%' + keyword + '%'),
                                                       GitRepo.web_url.like('%' + keyword + '%'),
                                                       GitRepo.path_with_namespace.like('%' + keyword + '%')
                                                       ))
        publishment_git_repos_objects = base_statement.limit(page_size).offset(
            (int(current_page) - 1) * page_size).all()
        if len(publishment_git_repos_objects) != 0:
            publishment_git_repos_counts = base_statement.count()
        else:
            publishment_git_repos_counts = 0
    finally:
        session.close()

    result_list = PublishmentSchema(many=True).dump(publishment_git_repos_objects)
    result = {'data': result_list, 'total': publishment_git_repos_counts}

    return jsonify(result)
Пример #5
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
Пример #6
0
def get_publishment_by_repo_id(git_repo_id):
    session = Session()
    try:
        return session.query(Publishment).select_from(Publishment).join(GitRepo,
                                                                        Publishment.git_repo_id == GitRepo.id).filter(
            Publishment.git_repo_id == git_repo_id).all()
    finally:
        session.close()
Пример #7
0
def get_publishment_detail(id):
    session = Session()
    try:
        return session.query(Publishment).select_from(
            Publishment).join(GitRepo,
                              Publishment.git_repo_id == GitRepo.id).filter(Publishment.id == id).one_or_none()
    finally:
        session.close()
Пример #8
0
def get_user(id):
    session = Session()
    user_object = session.query(User).filter(User.id == id).first()

    schema = UserSchema()
    user = schema.dump(user_object)

    session.close()
    return jsonify(user), 200
Пример #9
0
def get_dibses(user):
    session = Session()
    offer_objects = session.query(Offer).filter(Offer.dibsedby_id == user)

    schema = OfferSchema(many=True)
    offers = schema.dump(offer_objects)

    session.close()
    return jsonify(offers), 200
Пример #10
0
def get_exams():
    # fetching from the database
    session = Session()
    exam_objects = session.query(Exam).all()
    # transforming into JSON-serializable objects
    schema = ExamSchema(many=True)
    exams = schema.dump(exam_objects)
    # serializing as JSON
    session.close()
    return jsonify(exams)
Пример #11
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'})
Пример #12
0
def get_offers():
    # Database
    session = Session()
    offer_objects = session.query(Offer).all()

    # Create serializable object
    schema = OfferSchema(many=True)
    offers = schema.dump(offer_objects)

    session.close()
    return jsonify(offers), 200
Пример #13
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
Пример #14
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
Пример #15
0
def publishment_detail(id):
    session = Session()
    try:
        result_object = session.query(Publishment).filter(Publishment.id == id).one_or_none()
    finally:
        session.close()

    result = PublishmentSchema().dump(result_object)
    if result_object:
        result['git_branches'] = result.get('git_branches').split(',')
        result['to_ip'] = result.get('to_ip').split(',')
        result['git_delete_temp_branch'] = True if result.get('git_delete_temp_branch') == 1 else False

    return jsonify(result)
Пример #16
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
Пример #17
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'})
Пример #18
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
Пример #19
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'})
Пример #20
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
Пример #21
0
def login():
    posted_creds = request.get_json()
    username = posted_creds["name"]

    session = Session()

    user_object = session.query(User).filter(User.name == username).first()

    schema = UserSchema()
    user = schema.dump(user_object)
    session.close()

    if not user:
        return jsonify({"error": "No user with that name"}), 200

    if posted_creds["pw"] == user["pw"]:
        return jsonify({"id": user["id"], "name": user["name"]}), 200
    else:
        return jsonify({"error": "Incorrect password"}), 200