def delete_project(project_id):
    project = Projects.query.filter_by(project_id=project_id).first()

    db_session.delete(project)
    db_session.commit()

    return project
def insert_data(usage_date, cost, project_id, resource_type, account_id,
                usage_value, measurement_unit):
    done = False
    try:
        usage = Usage(usage_date, cost, project_id, resource_type, account_id,
                      usage_value, measurement_unit)
        db_session.add(usage)
        db_session.commit()
        done = True
    except IntegrityError as e:
        # log.info('---- DATA ALREADY IN DB --- UPDATE  ------')
        # log.info('{0}<---->{1}<----->{2}<------>{3}<------>{4}'.format(usage_date, cost, project_id, resource_type,usage_value))
        db_session.rollback()
        usage = Usage.query.filter_by(project_id=project_id,
                                      usage_date=usage_date,
                                      resource_type=resource_type).first()
        usage.cost = cost
        usage.usage_value = usage_value
        usage.measurement_unit = measurement_unit
        db_session.commit()

        done = True
    except Exception as e:
        log.error(
            ' ------------- ERROR IN ADDING DATA TO THE DB ------------- {0}'.
            format(e[0]))
    return done
Example #3
0
def insert_data(instanceId, key, value):
    done = False
    log.info('---- starting to add info to DB {0}, {1}, {2} ----'.format(
        instanceId, key, value))
    try:
        log.info(
            '--------------------- ADDED INFO TO DB ---------------------')
        instance = Instance(instanceId=instanceId, key=key, value=value)
        db_session.add(instance)
        db_session.commit()
        done = True
    except IntegrityError as e:
        log.info('---- DATA ALREADY IN DB --- UPDATE  ------')
        # log.info('instanceId = {0}<----> key = {1}<-----> value = {2}'.format(instanceId, key, value))
        db_session.rollback()
        instance = Instance.query.filter_by(instanceId=instanceId,
                                            key=key).first()
        instance.value = value
        db_session.commit()

        done = True
    except Exception as e:
        log.error(
            ' ------------- ERROR IN ADDING DATA TO THE DB ------------- {0}'.
            format(e[0]))

    return done
def insert_project_data(project_id, project_name):
    done = False
    try:
        project = Project('other', project_id, project_name, 'other', '', '',
                          '', 0)
        db_session.add(project)
        db_session.commit()
        done = True
    except IntegrityError as e:
        # log.info('---- Project DATA ALREADY IN DB --- UPDATE  ------')
        db_session.rollback()
        project = Project.query.filter_by(project_id=project_id).first()
        project.project_name = project_name
        db_session.commit()

        done = True
    except Exception as e:
        log.error(
            ' ------------- ERROR IN ADDING PROJECT DATA TO THE DB ------------- {0}'
            .format(e[0]))
        log.error(
            ' ------------- ERROR IN ADDING PROJECT DATA TO THE DB ------------- {0}<---->{1}'
            .format(project_id, project_name))

    return done
def create_project(cost_center, project_id, project_name, director, director_email, contact_name, contact_email,
                   alert_amount):
    project = Projects(cost_center, project_id, project_name, director, director_email, contact_name, contact_email,
                       alert_amount)
    db_session.add(project)
    db_session.commit()

    return project
def update_project(cost_center, project_id, project_name, director, director_email, contact_name, contact_email,
                   alert_amount):
    project = Projects.query.filter_by(project_id=project_id).first()
    project.cost_center = cost_center
    project.project_name = project_name
    project.director = director
    project.director_email = director_email
    project.contact_name = contact_name
    project.contact_email = contact_email
    project.alert_amount = alert_amount

    db_session.commit()

    return project
def insert_project_data(project_id, project_name):
    done = False
    log.info('{0}<---->{1}'.format(project_id, project_name))
    try:
        project = Project('other', project_id, project_name, 'other', '', '', '', 0)
        db_session.add(project)
        db_session.commit()
        done = True
    except IntegrityError as e:
        # log.info('---- Project DATA ALREADY IN DB --- UPDATE  ------')
        db_session.rollback()
        project = Project.query.filter_by(project_id=project_id).first()
        project.project_name = project_name
        db_session.commit()

        done = True
    except Exception as e:
        log.error(' ------------- ERROR IN ADDING DATA TO THE DB ------------- {0}'.format(e[0]))
    return done
def insert_data(usage_date, cost, project_id, resource_type, account_id, usage_value, measurement_unit):
    done = False
    try:
        usage = Usage(usage_date, cost, project_id, resource_type, account_id, usage_value, measurement_unit)
        db_session.add(usage)
        db_session.commit()
        done = True
    except IntegrityError as e:
        # log.info('---- DATA ALREADY IN DB --- UPDATE  ------')
        # log.info('{0}<---->{1}<----->{2}<------>{3}<------>{4}'.format(usage_date, cost, project_id, resource_type,usage_value))
        db_session.rollback()
        usage = Usage.query.filter_by(project_id=project_id, usage_date=usage_date, resource_type=resource_type).first()
        usage.cost = cost
        usage.usage_value = usage_value
        usage.measurement_unit = measurement_unit
        db_session.commit()

        done = True
    except Exception as e:
        log.error(' ------------- ERROR IN ADDING DATA TO THE DB ------------- {0}'.format(e[0]))
    return done