def post(self): data = self.parser.parse_args() language = LanguageModel(**data) language.created_by = 1 language.created_on = datetime.now() language.modified_by = 0 language.deleted_by = 0 language.modified_on = None language.deleted_on = None try: validateObj = LanguageModel.validateData(data, request) if type(validateObj) is dict: return {"success": False, "errors": validateObj}, 400 if LanguageModel.find_by_name(data['language_name']): return {"success": False, "message": "A language with that Record Name already exists"}, 400 name=data['language_name'] if name.strip(): language.save_to_db() language.token = encodeID(language.language_id) language.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 language.json(), 201
def post(self, language_name): db.create_all() db.session.commit() if LanguageModel.find_by_name(language_name): return { 'message': "An Record with name '{}' already exists.".format( language_name) }, 400 language = LanguageModel(language_name) language.created_by = 1 language.created_on = datetime.now() language.modified_by = 0 language.deleted_by = 0 try: language.save_to_db() except Exception as e: return { "message": "An error occurred while inserting the Record.'{}'".format(e) } return language.json(), 201