def create_employee(self): from src.models import Employee employee = Employee(name="New Kaio", email="*****@*****.**", department="TI") employee.save() self.__data_create_employee = employee
def fill(session): for emp in emp_data: employee = Employee(id=emp[0], name=emp[1], surname=emp[2], salary=emp[3]) if emp[3] > 3000: i = random.randint(0, 6) car = Car(manufacturer=car_data[i][0], model=car_data[i][1]) employee.car = car session.add(car) session.add(employee) session.commit()
def add_employee(data): """ Handles addition of employee. :param data: data object to be added :return: Json with success/failure status and error message """ try: if not data['research_group']: data['research_group'] = None dao = EmployeeDataAccess(get_db()) picture = get_random_picture_location() employee = Employee(data["name"], data["name"], data["email"], data["office"], data.get("extra_info"), picture, data["research_group"], data["title"] if data.get("title") else None, data["is_external"], False, True) dao.add_employee(employee) return jsonify({'success': True}), 200, { 'ContentType': 'application/json' } except Exception as e: return jsonify({ 'success': False, "message": str(e) }), 400, { 'ContentType': 'application/json' }
def update_employee(data): """ Handles update of employee. :param data: data object with new data :return: Json with success/failure status and error message """ try: if "is_admin" not in data: data[ "is_admin"] = "TRUE" if current_user.role == "admin" else "FALSE" if not data['research_group']: data['research_group'] = None dao = EmployeeDataAccess(get_db()) employee = Employee(data["key"], data["name"], data["email"], data["office"], data["extra_info"], data["picture_location"], data["research_group"], data["title"] if data["title"] else None, data["is_external"], data['is_admin'], data['is_active']) dao.update_employee(employee) return jsonify({'success': True}), 200, { 'ContentType': 'application/json' } except Exception as e: return jsonify({ 'success': False, "message": str(e) }), 400, { 'ContentType': 'application/json' }
def post(self, slug): parser = reqparse.RequestParser() parser.add_argument("name") parser.add_argument("surname") parser.add_argument("salary") parser.add_argument("birth_date") args = parser.parse_args() try: department = Department.query.filter( Department.slug == slug).first() new_employee = Employee(name=args["name"], surname=args["surname"], department_id=department.id, salary=args["salary"], birth_date=args["birth_date"]) db.session.add(new_employee) db.session.commit() except: return 404 return { "id": new_employee.id, "name": new_employee.name, "surname": new_employee.surname, "slug": new_employee.slug, "salary": new_employee.salary, "birth_date": str(new_employee.birth_date), "department": department.name, "department_id": department.id }, 201
def new_person(user_id, password): """ Person is added to the DB with the data retrieved from LDAP :param user_id: student number or employee identification :param password: the user password :return: None if nothing found, else the new User """ # Make a search request to LDAP person = search_person(user_id, password) if person is None: return None if 'student' in person['distinguishedName'].value.lower(): # Make new student name = person['displayName'].value student = Student(name, user_id) StudentDataAccess(get_db()).add_student(student) return User(user_id, name, 'student', False) else: # Make new employee name = person['displayName'].value email = person['mail'].value office = person['physicalDeliveryOfficeName'].value picture = get_random_picture_location() employee = Employee(user_id, name, email, office, None, picture, None, None, False, False, True) EmployeeDataAccess(get_db()).add_employee(employee) return User(user_id, name, 'employee', True)
def test_database(self): department1 = Department(name="Test department 1", id=-1) department2 = Department(name="Test department 2", id=-2) department3 = Department(name="Test department 3", id=-3) db.session.add(department1) db.session.add(department2) db.session.add(department3) db.session.commit() self.assertEqual( Department.query.filter(Department.id == -1).first().name, "Test department 1" ) self.assertEqual( Department.query.filter(Department.id == -2).first().name, "Test department 2" ) self.assertEqual( Department.query.filter(Department.id == -3).first().name, "Test department 3" ) employee1 = Employee(name="Employee 1", surname="Test", department_id=-1, salary=5000, birth_date="2000-01-01") employee2 = Employee(name="Employee 2", surname="Test", department_id=-1, salary=7000, birth_date="2000-02-04") employee3 = Employee(name="Employee 3", surname="Test", department_id=-2, salary=8000, birth_date="2001-02-04") employee4 = Employee(name="Employee 4", surname="Test", department_id=-3, salary=7500, birth_date="1999-12-04") db.session.add(employee1) db.session.add(employee2) db.session.add(employee3) db.session.add(employee4) db.session.commit() self.assertEqual( len(Employee.query.filter(Employee.department_id == -1).all()), 2 ) self.assertEqual( Employee.query.filter(Employee.department_id == -1).first(), employee1 ) self.assertEqual( len(Employee.query.filter(Employee.department_id == -2).all()), 1 ) self.assertEqual( Employee.query.filter(Employee.department_id == -2).first(), employee3 ) self.assertEqual( len(Employee.query.filter(Employee.department_id == -3).all()), 1 ) self.assertEqual( Employee.query.filter(Employee.department_id == -3).first(), employee4 ) employee5 = Employee(name="Employee 5", surname="Test", department_id=-3, salary=9500, birth_date="1998-12-04") db.session.add(employee5) db.session.commit() self.assertEqual( len(Employee.query.filter(Employee.department_id == -3).all()), 2 ) Department.query.filter(Department.id == -2).delete() db.session.commit() self.assertEqual( len(Department.query.filter(Department.id == -2).all()), 0 ) self.assertEqual( len(Employee.query.filter(Employee.department_id == -2).all()), 0 ) Department.query.filter(Department.id < 0).delete() db.session.commit() rest = Employee.query.filter(Employee.department_id < 0).all() self.assertEqual(len(rest), 0)
session.commit() role=Role() role.name=u"VIP会员" session.add(role) session.commit() manage=Role() manage.name=u"管理员" session.add(manage) session.commit() role=Role() role.name=u"教练" session.add(role) session.commit() admin = Employee() admin.name = 'admin' admin.phone = '1888888888' admin.password = '******' admin.role=manage.id session.add(admin) session.commit() session.close() print(u'fitnessPlatform安装完成')