def wrap(*args, **kwargs): """Checks user is logged in or not in the session""" session.permanent = True try: if session['username'] is False: flash('You must login first!') return redirect(url_for('module_employee.login')) return f(*args, **kwargs) except KeyError: flash('Your session is timeout!') return redirect(url_for('module_employee.login'))
def wrap(*args, **kwargs): """Checks if there is any employee or not""" employee = Employee.check_records() if not employee: flash("You don't have administrator. Register one now.") return redirect(url_for('module_employee.setup')) return f(*args, **kwargs)
def dispatch_request(self): employee = model.Employee.check_records() if employee: return redirect(url_for('module_employee.public_list')) setupForm = AddEmployeeForm() isFormValid = self.is_form_valid(setupForm) if isFormValid: add = model.Employee.add(request.form) flash(u'Employee successfully added.', 'success') return redirect(url_for('module_employee.public_list')) else: flash_errors(setupForm) return render_template('admin/add-employee.html', school=self.get_site_data(), form=setupForm)
def dispatch_request(self): assignAsTeacherForm = AssignAsTeacherForm() subjectChoices = model.Subject.get_choices() assignAsTeacherForm.subject.choices = subjectChoices subjects = assignAsTeacherForm.subject.choices isAssignAsTeacherValid = self.is_form_valid(assignAsTeacherForm) employee_id = request.args.get('employee_id') if isAssignAsTeacherValid: teacherData = { 'user_id': employee_id, 'subject_id': request.form['subject'] } createTeacher = model.Teacher(teacherData) db.session.add(createTeacher) db.session.commit() flash('Teacher Successfully added.') return redirect(url_for('module_employee.dashboard')) else: flash_errors(assignAsTeacherForm) return render_template('admin/assign.html', school=self.get_site_data(), form=assignAsTeacherForm, subjects=subjects, employee_id=employee_id)
def dispatch_request(self): setting = Setting() existingSetting = setting.get_existing_name() siteSettingForm = SiteSettingForm() isFormValid = self.is_form_valid(siteSettingForm) if existingSetting and isFormValid: updateSetting = setting.update(request.form) flash(u'Succesfully updated.', 'success') return redirect(url_for('module_employee.dashboard')) elif not existingSetting and isFormValid: setSetting = setting.insert(request.form) flash(u'Succesfully set.', 'success') return redirect(url_for('module_employee.dashboard')) else: flash_errors(siteSettingForm) return render_template('admin/site-setting.html', school=self.get_site_data(), data=setting, form=siteSettingForm)
def dispatch_request(self): addEmployeeForm = AddEmployeeForm() isAddEmployeeValid = self.is_form_valid(addEmployeeForm) if isAddEmployeeValid: add = model.Employee.add(request.form) flash(u'Employee Successfully Added.') return redirect(url_for('module_employee.dashboard')) else: flash_errors(addEmployeeForm) return render_template('admin/add-employee.html', form=addEmployeeForm, school=self.get_site_data())
def dispatch_request(self): loginForm = LoginForm() isFormValid = self.is_form_valid(loginForm) if isFormValid: username = request.form['username'] password = request.form['password'] employees = model.Employee.query.filter_by(username=username) employee = employees.first() if employee and check_werkzeug(employee.password, password): encodeUsername = session_encode(employee.username) session['is_admin'] = True session['username'] = encodeUsername return redirect(url_for('module_employee.dashboard')) flash(u'Username or password did not match.', 'error') flash_errors(loginForm) return render_template('admin/login.html', school=self.get_site_data(), form=loginForm)
def dispatch_request(self): employee_id = request.args.get('employee_id') employee = model.Employee.query.filter_by(id=employee_id).first() editEmployee = EditEmployeeForm(employee) isEditEmployeeValid = self.is_form_valid(editEmployee) if isEditEmployeeValid: employee.username = request.form['username'] employee.fullname = request.form['fullname'] employee.nip = request.form['nip'] db.session.commit() flash('Successfully updated.!') url = url_for('module_employee.edit', employee_id=employee.id) return redirect(url) else: flash_errors(editEmployee) return render_template('admin/edit.html', school=self.get_site_data(), data=employee, form=editEmployee)
def dispatch_request(self): addSubjectForm = AddSubjectForm() isAddSubjectFormValid = addSubjectForm.validate_on_submit() if isAddSubjectFormValid: data = { 'code': request.form['code'], 'name': request.form['name'], 'major': request.form['major'], 'grade': request.form['grade'], 'weight': request.form['weight'], 'category': request.form['category'], 'curriculum': request.form['curriculum'], 'alias': request.form['alias'] } subject = model.Subject(data) db.session.add(subject) db.session.commit() return redirect(url_for('module_employee.dashboard')) else: flash_errors(addSubjectForm) return render_template('admin/add-subject.html', school=self.get_site_data(), form=addSubjectForm)
def dispatch_request(self): employee_id = request.args.get('employee_id') model.Employee.query.filter_by(id=employee_id).delete() db.session.commit() flash('Successfully deleted.') return redirect(url_for('module_employee.dashboard'))