def post(self): data = request.get_json(force=True) print(data) if EmployeeModel.find_by_employeeid(data['employeeid']): return { 'message': 'Employee with employeeid {} already exists'.format( data['employeeid']) } new_employee = EmployeeModel(employeeid=data['employeeid'], name=data['name'], designation=data['designation'], address=data['address'], gender=data['gender'], status=data['status'], dob=datetime(2012, 3, 3, 10, 10, 10)) try: new_employee.save_to_db() return { 'message': 'Employee with employee id {} has been created'.format( data['employeeid']), } except: return {'message': 'Something went wrong'}, 500
def put(self, name): """Todo convert the json data to python format""" """Todo search the book if exists update it else not found 404""" data = request.get_json() employee = EmployeeModel.query.filter_by(name=name).first() if employee: employee.employee_id = data['employee_id'] employee.name = data['name'] employee.age = data['age'] employee.position = data['position'] else: employee = EmployeeModel(name=name, **data) # hit on data base using database class method employee.create() return employee.json()
def post(self): """Todo user send data and convert this data as Json and then this json format data converted into python native code and then after solving specific task this will return as a Json again. """ # get json from user or from api. data = request.get_json() # print("dattttttttttttttttttttta",data) new_employee = EmployeeModel(employee_id=data['employee_id'], name=data['name'], age=data['age'], position=data['position']) new_employee.create() # again python readable code to json return new_employee.json(), 201
async def add_employee(emp: Employee, response: Response, db: Session = Depends(get_db)): record = EmployeeModel(**emp.dict()) db.add(record) db.commit() return {"id": record.id}
def add(): if request.form: department = DepartmentModel(name=request.form.get("department")) employee = EmployeeModel(name=request.form.get("name"),department=department) db_session.add(employee) db_session.commit() return render_template("addEmployee.html")
def mutate(self, info, input): data = utils.input_to_dictionary(input) employee = EmployeeModel(**data) db_session.add(employee) db_session.commit() return CreateEmployee(employee = employee)
def mutate(self, info, **kwargs): name = kwargs.get('name') department_id = kwargs.get('department_id') employee = EmployeeModel(name=name, department_id=department_id) db_session.add(employee) db_session.commit() return createEmployee(employee=employee)
def mutate(cls, _, info, **args): employee = EmployeeModel(name=args.get('name'), hobbies=args.get('hobbies'), results=args.get('results'), department_id=args.get('department_id')) db_session.add(employee) db_session.commit() ok = True return CreateEmployee(employee=employee, ok=ok)
async def prepare_test_data(monkeysession): monkeysession.setattr(EmployeeModel.Meta, "collection", "app_employee_test") with open("employees.json", "r") as file: employees = json.load(file) for e in employees[:10]: employee = EmployeeModel(**e) await employee.save() yield await app.mongodb.drop_collection("app_employee_test")
def save_employee (self,first_name,last_name,marital_status,gender,date_of_birth,id): #id will be greater than zero when EDIT action is triggered. if id>0: emp_k = db.Key.from_path('CompanyModel','Bellucci','EmployeeModel',long(id)) emp = db.get(emp_k) else: comp = CompanyModel(key_name='Bellucci',name='Bellucci Enterprise') comp.put() emp = EmployeeModel(parent = comp) emp.first_name = first_name emp.last_name = last_name emp.marital_status = marital_status emp.gender = gender emp.date_of_birth = datetime.date(year=int(date_of_birth[6:10]), month=int(date_of_birth[3:5]), day=int(date_of_birth[0:2])) emp.user_name = users.get_current_user().email() emp.put()
def add_employee(): nama = request.form['add_name'] email = request.form['add_email'] address = request.form['add_address'] phone = request.form['add_phone'] print(nama + email + address + phone) if db.session.query(EmployeeModel).filter( EmployeeModel.name == nama).count() == 0: data = EmployeeModel(nama, email, address, phone) db.session.add(data) db.session.commit() return redirect("/")
def main(): # Drop everything for a clean slate. Base.metadata.drop_all(engine) Base.metadata.create_all(bind=engine) # Fill the tables with some data engineering = DepartmentModel(name='Engineering') db_session.add(engineering) hr = DepartmentModel(name='Human Resources') db_session.add(hr) peter = EmployeeModel(name='Peter', salary=90000, department=engineering) db_session.add(peter) roy = EmployeeModel(name='Roy', salary=120000, department=engineering) db_session.add(roy) tracy = EmployeeModel(name='Tracy', salary=75000, department=hr) db_session.add(tracy) db_session.commit()
def create(): if request.method == 'GET': return render_template('createpage.html') if request.method == 'POST': employee_id = request.form['employee_id'] name = request.form['name'] age = request.form['age'] position = request.form['position'] employee = EmployeeModel(employee_id=employee_id, name=name, age=age, position = position) db.session.add(employee) db.session.commit() return redirect('/data')
def save_employee(self, first_name, last_name, marital_status, gender, date_of_birth, id): #id will be greater than zero when EDIT action is triggered. if id > 0: emp_k = db.Key.from_path('CompanyModel', 'Bellucci', 'EmployeeModel', long(id)) emp = db.get(emp_k) else: comp = CompanyModel(key_name='Bellucci', name='Bellucci Enterprise') comp.put() emp = EmployeeModel(parent=comp) emp.first_name = first_name emp.last_name = last_name emp.marital_status = marital_status emp.gender = gender emp.date_of_birth = datetime.date(year=int(date_of_birth[6:10]), month=int(date_of_birth[3:5]), day=int(date_of_birth[0:2])) emp.user_name = users.get_current_user().email() emp.put()
def mutate(self, info, name, hiredOn, departmentid): print('----------------------------------------') print(info.context.headers['Authorization']) print('----------------------------------------') hiredDate = datetime.strptime(hiredOn, '%d/%m/%Y') newEmployee = EmployeeModel(name=name, hired_on=hiredDate, department_id=departmentid) db_session.add(newEmployee) db_session.commit() return CreateEmployee(id=newEmployee.id, name=newEmployee.name, hiredOn=newEmployee.hired_on, departmentid=newEmployee.department_id)
def update(id): employee = EmployeeModel.query.filter_by(employee_id=id).first() if request.method == 'POST': if employee: db.session.delete(employee) db.session.commit() name = request.form['name'] age = request.form['age'] position = request.form['position'] employee = EmployeeModel(employee_id=id, name=name, age=age, position = position) db.session.add(employee) db.session.commit() return redirect(f'/data/{id}') return f"Employee with id = {id} Does nit exist" return render_template('update.html', employee = employee)
from models import engine, db_session, Base, DepartmentModel, EmployeeModel Base.metadata.create_all(bind=engine) engineering = DepartmentModel(name="Engineering") db_session.add(engineering) hr = DepartmentModel(name="Human Resources") db_session.add(hr) peter = EmployeeModel(name="Peter", department=engineering) db_session.add(peter) roy = EmployeeModel(name="Roy", department=engineering) db_session.add(roy) tracy = EmployeeModel(name="Tracy", department=hr) db_session.add(tracy) db_session.commit()
def mutate(self,info,input): data = utils.input_to_dictionary(input) employee = EmployeeModel(**data) return CreateEmployee(employee=employee)
async def _fill_db(): with open("employees.json", "r") as file: employees = json.load(file) for e in employees: employee = EmployeeModel(**e) await employee.save()
def get(self): if (request.args.get('employeeid')): return EmployeeModel.return_one(request.args.get('employeeid')) return EmployeeModel.return_all()
def mutate(root, info, **kwargs): employee = EmployeeModel(**kwargs) db_session.add(employee) db_session.commit() return CreateEmployee(employee=employee)
def list_employee(self): comp = db.Key.from_path('CompanyModel', 'Bellucci') employee_query = EmployeeModel.all() employee_query.ancestor(comp) return employee_query
def list_employee (self): comp = db.Key.from_path('CompanyModel','Bellucci') employee_query = EmployeeModel.all() employee_query.ancestor(comp) return employee_query