def post(self): data = self.parser.parse_args() audience_profile = TargetAudienceProfileModel(**data) audience_profile.created_by = 1 audience_profile.created_on = datetime.now() audience_profile.modified_by = 0 audience_profile.deleted_by = 0 audience_profile.modified_on = None audience_profile.deleted_on = None try: validateObj = TargetAudienceProfileModel.validateData( data, request) if type(validateObj) is dict: return {"success": False, "errors": validateObj}, 400 if TargetAudienceProfileModel.find_by_name( data['audience_profile_name']): return { "success": False, "message": "A audience_profile with that Record Name already exists" }, 400 name = data['audience_profile_name'] if name.strip(): audience_profile.save_to_db() audience_profile.token = encodeID( audience_profile.target_audience_profile_id) audience_profile.save_to_db() else: return { "success": False, "message": "String Should not be empty" } except Exception as e: return { "message": "An error occurred creating the Record.'{}'".format(e) }, 500 return audience_profile.json(), 201
def post(self, audience_profile_name): db.create_all() db.session.commit() if TargetAudienceProfileModel.find_by_name(audience_profile_name): return {'message': "An Record with name '{}' already exists.".format(audience_profile_name)}, 400 data = self.parser.parse_args() audience_profile = TargetAudienceProfileModel(audience_profile_name,**data,) audience_profile.created_by = 1 audience_profile.created_on = datetime.now() audience_profile.modified_by = 0 audience_profile.deleted_by = 0 try: audience_profile.save_to_db() except Exception as e: return {"message": "An error occurred while inserting the Record.'{}'".format(e)} return audience_profile.json(), 201