Ejemplo n.º 1
0
 def create(self, validated_data):
     company = Company()
     company.name = validated_data.get('name', 'default name')
     company.description = validated_data.get('description',
                                              'default description')
     company.save()
     return company
Ejemplo n.º 2
0
    def create(self, validated_data):
        company = Company()
        company.name = validated_data.get('name')
        company.description = validated_data.get('description')
        company.city = validated_data.get('city')
        company.address = validated_data.get('address')

        company.save()
        return company
Ejemplo n.º 3
0
def create_company():
    data = request.get_json()

    logger.info("Data recieved: %s", data)
    if "name" not in data:
        msg = "Please supply a company name."
        logger.info(msg)
        return create_response(status=422, message=msg)

    if "company_type" not in data:
        msg = "Please supply a company_type."
        logger.info(msg)
        return create_response(status=422, message=msg)

    if "description" not in data:
        msg = "Please supply a company description."
        logger.info(msg)
        return create_response(status=422, message=msg)

    if "address" not in data:
        msg = "Please supply a company address."
        logger.info(msg)
        return create_response(status=422, message=msg)
    try:
        # create SQLAlchemy Objects
        new_company = Company(name=data["name"])
        company_type = data[
            "company_type"]  #CompanyType(id=data["company_type"])
        print(company_type)
        new_company.company_type = company_type
        new_company.description = data["description"]
        new_company.address = data["address"]
        new_company.phone = data["phone"]
        new_company.MSA = data["MSA"]
        new_company.NDS = data["NDS"]
        new_company.url = data["url"]
        new_company.logo = data["logo"]
        db.session.add_all([new_company])
        db.session.commit()
    except Exception as e:
        print("+++++++++++++++++++++++++++++")
        print(e)
        return create_response(status=422, message=e)
    return create_response(
        message=
        f"Successfully created company {new_company.name} with id: {new_company.id}"
    )