def employees(dept_id): this_department = DepartmentModel.fetch_by_id(dept_id) employees = this_department.employees departments = DepartmentModel.fetch_all() return render_template('employees.html', this_department=this_department, idara=departments)
def home(): departments = DepartmentModel.fetch_all() all_employees = EmployeesModel.fetch_all() male = 0 female = 0 others = 0 for each in all_employees: if each.gender == 'm': male += 1 elif each.gender == 'f': female += 1 else: others += 1 pie_chart = pygal.Pie() pie_chart.title = 'Comparing Company Employees by Gender' pie_chart.add('Male', male) pie_chart.add('Female', female) pie_chart.add('Others', others) graph = pie_chart.render_data_uri() line_chart = pygal.Bar() line_chart.title = 'Salary cost per Department' for each_dept in departments: line_chart.add(each_dept.name, DepartmentModel.fetch_total_payroll_by_id(each_dept.id)) bar_graph = line_chart.render_data_uri() # print(graph) # print(departments) # print(departments) return render_template('index.html', idara=departments, graph=graph, bar_graph=bar_graph)
def home(): departments = DepartmentModel.fetch_all() #creating a pie chart in the home page all_employees = EmployeesModel.fetch_all() male = 0 female = 0 others = 0 for each in all_employees: if each.gender == 'male': male += 1 elif each.gender == 'female': female += 1 else: others += 1 pie_chart = pygal.Pie() # instantiating the pie class pie_chart.title = 'Analysing Company Employees By Gender' pie_chart.add('Male', male) pie_chart.add('Female', female) pie_chart.add('Others', others) chart=pie_chart.render_data_uri() # creating a bar graph in the home page line_chart = pygal.Bar() # instantiating the bar graph class line_chart.title = 'Salary Cost Per Department' #loop over departments for each_dept in departments: line_chart.add(each_dept.name, DepartmentModel.fetch_total_payroll_by_id(each_dept.id)) bar_graph = line_chart.render_data_uri() return render_template('index.html',idara = departments, chart=chart, bar_graph=bar_graph)
def newDepartment(): department_name = request.form['department'] if DepartmentModel.fetch_by_name(department_name): # read more on bootsrap alerts with flash flash("Department" + department_name + "already exist") return redirect(url_for('home')) department = DepartmentModel(name=department_name) department.insert_to_db() return redirect(url_for('home'))
def new_department(): department_name = request.form['department'] if DepartmentModel.fetch_by_name(department_name): #read more on bootstrap alerts with flash and ensure the message pops up flash('department ' + department_name + ' already exists') return redirect(url_for('home')) department = DepartmentModel(name=department_name)#name is the field name on the database and department is on form in html code department.insert_to_db() return redirect(url_for('home'))
def employees(dept_id): #new_department=DepartmentModel.fetch_all() this_department=DepartmentModel.fetch_by_id(dept_id) employees=this_department.employees #department_id =dept_id #dept = DepartmentModel.fetch_by_id(dept_id) #dept_name = dept.name departments=DepartmentModel.fetch_all() return render_template('employees.html', this_department=this_department, idara=departments)
def new_department(): department_name = request.form['department'] if DepartmentModel.fetch_by_name(department_name): #read more on bootstrap alerts with flash flash('Department' + department_name + ' already exists.') return redirect(url_for('home')) department = DepartmentModel(name=department_name) department.insert_to_db() flash('Department ' + department_name + ' has been added.') return redirect(url_for('home'))
def newDepartment(): department_name = request.form['department'] if DepartmentModel.fetch_by_name(department_name): # read more on bootstrap alerts with flash flash('Department ' + department_name + ' already exists.', 'danger') # now create the alerts with flash. return redirect(url_for('hello_world')) department = DepartmentModel(name=department_name) department.insert2DB() return redirect(url_for('hello_world'))
def newDepartment(): department_name = request.form['department'] if DepartmentModel.fetch_by_name(department_name): flash(department_name + " already exists") return redirect(url_for('departments')) department = DepartmentModel( dpt_name=department_name) #dpt_name is same as in database department.instert_into_database() return redirect(url_for('departments'))
def employees(dept_id): this_dept = DepartmentModel.fetch_by_id(dept_id) return render_template('employees.html', this_dept=this_dept)
def home(): departments = DepartmentModel.fetch_all() return render_template('flask.html', idara=departments)
def deleteDepartment(id): id = DepartmentModel.fetch_by_id(id) #this_emp = this_dept.employee DepartmentModel.delete_by_id(id) return redirect(url_for('deleteDepartment', id=id))
def editDepartment(id): name = request.form['name'] DepartmentModel.update_department(id, name=name) this_dept = DepartmentModel.fetch_by_id(id) #this_emp = this_dept.id return redirect(url_for('hello_world', dept_id=this_dept.id))
def departments(): employees = EmployeeModel.fetch_all() departments = DepartmentModel.fetch_all() return render_template('departments.html', employees=employees, departments=departments)