Пример #1
0
 def delete(self, p_id):
     department_data = DepartmentModel.find_by_id(p_id) #GET SINGLE DATA BY ID
     if department_data:
         department_data.db_to_delete()
         return {'message': 'Department data deleted successfully'}, 200
     else:
         return {'message': 'Department not found'}, 400
Пример #2
0
    def put(self, p_id):
        data = parser.parse_args()
        department_data = DepartmentModel.find_by_id(p_id)
        department_data.update_data(department_data,data)

        try:
            department_data.db_to_commit()
            return {
                'message': ' This {} department data  updated successfully'.format(data['name'])
            }, 200
        except:
            return {'message': 'Something went wrong'}, 500
    def post(self):
        data = parser.parse_args()

        if DepartmentModel.find_by_name(data['name']):
            return {
                'message':
                'This department {} already exists '.format(data['name'])
            }

        if DepartmentModel.find_by_code(data['code']):
            return {
                'message': 'This code {} already exists '.format(data['code'])
            }

        #CREATE MODEL DATA FOR SAVE
        new_department = DepartmentModel(
            name=data['name'],
            code=data['code'],
            class_id=data['class_id'],
        )
        try:
            new_department.save_to_db()  #CALL THIS FUNCTION FOR COMMIT DATA

            return {
                'message':
                ' This {} department data  created successfully'.format(
                    data['name'])
            }, 200
        except:
            return {'message': 'Something went wrong'}, 500
Пример #4
0
def departments():
    allDepts = DepartmentModel.fetch_all_departments()
    #print(type(allDepts))
    for x in allDepts:
        print(x.name)
    if request.method == 'POST':
        nameInput = request.form['department']
        if DepartmentModel.check_dept_exist((nameInput)):
            print('dept already exist')
        else:
            record = DepartmentModel(name=nameInput)
            record.create()
            print('added')
            return redirect(url_for('departments'))
        #print(name)

    return render_template('departments.html', depts=allDepts)
Пример #5
0
def employees():
    allDepts = DepartmentModel.fetch_all_departments()
    if request.method == 'POST':
        name = request.form['empName']
        email = request.form['email']
        phone = request.form['phonenum']
        natId = request.form['nationalId']
        krapin = request.form['kra']
        deptname = request.form['department']
        if EmployeeModel.check_employee_exist(natId):
            print('Employee already exist')
        else:
            emp = EmployeeModel(fullName=name,
                                email=email,
                                phoneNumber=phone,
                                nationalId=natId,
                                KRAPin=krapin,
                                dept_id=deptname)
            emp.create()
            print('added')
            return redirect(url_for('employees'))

    return render_template('employees.html', depts=allDepts)
Пример #6
0
    def post(self, name):

        department = DepartmentModel.find_by_name(name)
        if department:
            return {
                "message":
                "A department with name {} already exists.".format(name)
            }, 400

        department = DepartmentModel(name)
        try:
            department.save_to_db()
        except:
            return {
                "message": "An error occurred while inserting the details."
            }, 500
        return {
            "message": "Department added successfully",
            "Department": department.json()
        }, 201
Пример #7
0
 def get(self, p_id):
     department_data = DepartmentModel.find_by_id(p_id) #GET SINGLE DATA BY ID
     jsonify_data = department_data.to_json(department_data)
     return {'department': jsonify_data}
Пример #8
0
 def get(self):
     return DepartmentModel.return_all()
Пример #9
0
 def get(self, name):
     department = DepartmentModel.find_by_name(name)
     if department:
         return department.json()
     return {"message": "Department not found"}, 404
Пример #10
0
 def delete(self, name):
     department = DepartmentModel.find_by_name(name)
     if department:
         department.delete_from_db()
         return {"message": "Department deleted!"}
     return {"message": "Department not found"}, 404