예제 #1
0
    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
예제 #2
0
 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()
예제 #3
0
 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
예제 #4
0
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}
예제 #5
0
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")
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
 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)
예제 #9
0
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")
예제 #10
0
	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()
예제 #11
0
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()
예제 #13
0
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')
예제 #14
0
    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()
예제 #15
0
    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)
예제 #16
0
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)
예제 #17
0
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()
예제 #18
0
    def mutate(self,info,input):
        data = utils.input_to_dictionary(input)
        employee = EmployeeModel(**data)

        return CreateEmployee(employee=employee)
예제 #19
0
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()
예제 #20
0
 def get(self):
     if (request.args.get('employeeid')):
         return EmployeeModel.return_one(request.args.get('employeeid'))
     return EmployeeModel.return_all()
예제 #21
0
 def mutate(root, info, **kwargs):
     employee = EmployeeModel(**kwargs)
     db_session.add(employee)
     db_session.commit()
     return CreateEmployee(employee=employee)
예제 #22
0
 def list_employee(self):
     comp = db.Key.from_path('CompanyModel', 'Bellucci')
     employee_query = EmployeeModel.all()
     employee_query.ancestor(comp)
     return employee_query
예제 #23
0
	def list_employee (self):
		comp = db.Key.from_path('CompanyModel','Bellucci')
		employee_query = EmployeeModel.all()
		employee_query.ancestor(comp)
		return employee_query