Example #1
0
def db_test():
    try:
        DBHelper.connect()
        DBHelper.create_db_tables()
        return str(Token.select().count())
    finally:
        DBHelper.close()
Example #2
0
def remove(team_id):
    try:
        DBHelper.connect()
        token = Token.get(Token.issuer == team_id)
        delete_count = token.delete_instance()
    finally:
        DBHelper.close()
Example #3
0
def store(team_id, auth_token, app):
    try:
        DBHelper.connect()
        token, created = Token.get_or_create(issuer=team_id,
                                             app=app,
                                             defaults={'token': auth_token})
        token.token = auth_token
        token.save()
    finally:
        DBHelper.close()
Example #4
0
 def createEntity(self, entity):
     result = {}
     try:
         DBHelper.insert(entity, True)
         result = {"id": entity.id}
     except:
         DBHelper.rollback()
         print(sys.exc_info())
     finally:
         DBHelper.close()
     return result
Example #5
0
def delete_challenge(jwt, challenge_id):
    error = False
    try:
        challenge = Challenge.query.get(challenge_id)
        if challenge is None:
            error = True
        else:
            DBHelper.delete(challenge)
    except:
        DBHelper.rollback()
        error = True
    finally:
        DBHelper.close()
    if error:
        abort(404)
    return jsonify({"success": True})
Example #6
0
def delete_series(jwt, series_id):
    error = False
    try:
        series = Series.query.get(series_id)
        if series is None:
            error = True
        else:
            DBHelper.delete(series)
    except:
        DBHelper.rollback()
        error = True
    finally:
        DBHelper.close()
    if error:
        abort(404)
    return jsonify({"success": True})
Example #7
0
def delete_task(jwt, task_id):
    error = False
    try:
        task = Task.query.get(task_id)
        if task is None:
            error = True
        else:
            DBHelper.delete(task)
    except:
        DBHelper.rollback()
        erro = True
    finally:
        DBHelper.close()
    if error:
        abort(404)
    return jsonify({"success": True})
Example #8
0
def create_series(jwt):
    data = request.get_json()
    error = False
    try:
        series = Series(name=data["name"], description=data["description"])
        isTest = False
        if "isTest" in data:
            isTest = data["isTest"]
        DBHelper.insert(series)
    except:
        DBHelper.rollback()
        error = True
    finally:
        DBHelper.close()
    if error:
        abort(404)
    return jsonify({"success": True})
Example #9
0
def create_challenge(jwt):
    data = request.get_json()
    error = False
    try:
        challenge = Challenge(task_id=data["task_id"],
                              series_id=data["series_id"])
        isTest = False
        if "isTest" in data:
            isTest = data["isTest"]
        DBHelper.insert(challenge)
    except:
        DBHelper.rollback()
        error = True
    finally:
        DBHelper.close()
    if error:
        abort(404)
    return jsonify({"success": True})
Example #10
0
def create_task(jwt):
    data = request.get_json()
    error = False
    try:
        task = Task(name=data["name"],
                    state=data["state"],
                    country=data["country"])

        isTest = False
        if "isTest" in data:
            isTest = data["isTest"]

        DBHelper.insert(task, isTest)
    except:
        DBHelper.rollback()
        error = True
    finally:
        DBHelper.close()

    if error:
        abort(404)
    return jsonify({"success": True})
Example #11
0
def update_challenge(jwt, challenge_id):
    data = request.get_json()
    error = False
    try:
        challenge = Challenge.query.get(challenge_id)
        if challenge is None:
            error = True
        else:
            if "task_id" in data and "series_id" in data:
                challenge.task_id = data["task_id"]
                challenge.series_id = data["series_id"]

            DBHelper.update()
    except:
        print(sys.exc_info())
        DBHelper.rollback()
        error = True
    finally:
        DBHelper.close()
    if error:
        abort(404)
    return jsonify({"success": True})
Example #12
0
def update_series(jwt, series_id):
    error = False
    data = request.get_json()
    try:
        series = Series.query.get(series_id)
        if series is None:
            error = True
        else:
            if "name" in data:
                series.name = data["name"]
            if "description" in data:
                series.state = data["description"]

        DBHelper.update()
    except:
        print(sys.exc_info())
        DBHelper.rollback()
        error = True
    finally:
        DBHelper.close()
    if error:
        abort(404)
    return jsonify({"success": True})
Example #13
0
def update_task(jwt, task_id):
    data = request.get_json()
    error = False
    try:
        task = Task.query.get(task_id)
        if task is None:
            error = True
        else:
            if "name" in data:
                task.name = data["name"]
            if "state" in data:
                task.state = data["state"]
            if "country" in data:
                task.country = data["country"]
            DBHelper.update()
    except:
        print(sys.exc_info())
        DBHelper.rollback()
        error = True
    finally:
        DBHelper.close()
    if error:
        abort(404)
    return jsonify({"success": True})
Example #14
0
def after_request(response):
    DBHelper.close()  # close if necessary
    return response
Example #15
0
def get(team_id):
    try:
        DBHelper.connect()
        return Token.get(Token.issuer == team_id).token
    finally:
        DBHelper.close()