def paticipant_details(): data = { 'client_id': request.args.get('client_id'), 'cycle_id': request.args.get('cycle_id') } schema = { 'client_id': { 'required': True, 'type': 'string' }, 'cycle_id': { 'required': True, 'type': 'string' } } res = validator.validate(data, schema) if not res: response = Response() response.success = False response.status = 400 response.errors = "Required data not provided." return response.response_json() data["assessment_role"] = "participant" employee = hp.Employee() response = employee.select(data) if response.success: response.message = "Employe details added " response.data = {"participant_details": response.data} elif not response.success: response.success = False response.status = 400 response.errors = "Participants details not fetched." return response.response_json()
def get_assessment_status(): data = { 'client_id': request.args.get('client_id'), 'cycle_id': request.args.get('cycle_id') } schema = { 'client_id': { 'required': True, 'type': 'string' }, 'cycle_id': { 'required': True, 'type': 'string' } } res = validator.validate(data, schema) if not res: response = Response() response.success = False response.status = 400 response.errors = "Required data not provided." return response.response_json() status = hp.Participant() status_response = status.get_participant_assessment_status(data) if status_response.success: status_response.message = "Employe details added " elif not status_response.success: status_response.success = False status_response.status = 400 status_response.errors = "Participants details not fetched." return status_response.response_json()
def employee_details(): data = request.get_json() schema = { 'emp_id': { 'required': True, 'type': 'string' }, 'client_id': { 'required': True, 'type': 'string' }, 'cycle_id': { 'required': False, 'type': 'string' } } res = validator.validate(data, schema) if not res: response = Response() response.success = False response.status = 400 response.errors = "Required data not provided." employee = hp.Employee() response = employee.delete(data) if not response.success: response.success = False response.status = 400 response.errors = "Employee relation not added" return response.response_json()
def send_bulk_mail(): data = request.get_json() schema = { 'client_id': { 'required': True, 'type': 'string' }, 'cycle_id': { 'required': True, 'type': 'string' }, 'dept_id': { 'required': True, 'type': 'list' } } res = validator.validate(data, schema) if not res: response = Response() response.success = False response.status = 400 response.message = "Required data not found" bulk_mail = hp.BulkMailEmp() bulk_mail_resp = bulk_mail.send_alert_mail_emp(data) if not bulk_mail_resp.success: bulk_mail_resp.success = False bulk_mail_resp.status = 400 bulk_mail_resp.message = "Employee details not found" return bulk_mail_resp.response_json()
def store_assessment_answers(): data = request.get_json() schema = { 'que_id': { 'required': True, 'type': 'string' }, 'opt_id': { 'required': True, 'type': 'string' }, 'map_id': { 'required': True, 'type': 'string' }, 'answer_score': { 'required': True, 'type': 'string' } } res = validator.validate(data, schema) if not res: response = Response() response.success = False response.status = 400 response.errors = "Required data not provided." store = hp.StoreAssessmentAnswers() store_response = store.insert(data) if not store_response.success: store_response.status = 400 store_response.success = False store_response.message = "Assessment Answer Not stored!!" return store_response.response_json()
def get_dept_details(): data = { 'client_id': request.args.get('client_id'), 'cycle_id': request.args.get('cycle_id') } response = Response() schema = { 'client_id': { 'required': True, 'type': 'string' }, 'cycle_id': { 'required': True, 'type': 'string' } } res = validator.validate(data, schema) if not res: response.success = False response.status = 400 response.message = "Required data not found" return response.response_json() department = hp.ClientDeptDetails() dept_response = department.select(data) if not dept_response.success: dept_response.success = False dept_response.status = 400 dept_response.message = "Department Details not fetched." return dept_response.response_json()
def add_dept_details(): data = request.get_json() response = Response() schema = { 'client_id': { 'required': True, 'type': 'string' }, 'cycle_id': { 'required': True, 'type': 'integer' }, 'function': { 'required': True, 'type': 'string' }, 'role': { 'required': True, 'type': 'string' }, 'location': { 'required': True, 'type': 'string' }, 'band': { 'required': True, 'type': 'string' } } res = validator.validate(data, schema) if not res: response.success = False response.status = 400 response.message = "Required data not found" department = hp.ClientDeptDetails() add_dept = department.create(data) if add_dept: response.success = True response.status = 200 response.message = "Success" elif not add_dept: response.success = False response.status = 400 response.message = "Failure" return response.response_json()
def get_cycle_details(): data = {'client_id': request.args.get('client_id')} response = Response() schema = {'client_id': {'required': True, 'type': 'string'}} res = validator.validate(data, schema) if not res: response.success = False response.status = 400 response.message = "Required data not found" return response.response_json() cycle_details = hp.ClientCycleDetails() cycle_response = cycle_details.select(data) if not cycle_response.success: cycle_response.success = False cycle_response.status = 400 cycle_response.data = list() cycle_response.message = "Failed to load client cycle details" return cycle_response.response_json()
def all_respondant_details(): data = { 'client_id': request.args.get('client_id'), 'cycle_id': request.args.get('cycle_id') } if request.args.get('part_id') is not None: data['part_id'] = request.args.get('part_id') response = Response() schema = { 'client_id': {'required': True, 'type': 'string'}, 'cycle_id': {'required': True, 'type': 'string'} } validator.allow_unknown = True res = validator.validate(data, schema) if not res: response.success = False response.status = 400 response.errors = "Required data not provided." return response.response_json() data["assessment_role"]="respondant" emp_ids = hp.EmployeeRelationMapping() emp_ids_response = emp_ids.select(data) if emp_ids_response.success: data['emp_ids'] = list() for ids in emp_ids_response.data: data['emp_ids'].append(ids['pat_emp_id']) employee = hp.Employee() employee_response = employee.select(data) if employee_response.success: response.message = "Respondents details fetched." response.status = 200 response.data = { "respondants_details":employee_response.data } elif not employee_response.success: response.success = False response.status = 400 response.errors = "Respondents details not fetched." else: emp_ids.success = False emp_ids.status = 400 emp_ids.errors = "Respondents details not fetched." return response.response_json()
def store_feedback(): data = request.get_json() response = Response() schema = { 'client_id': { 'required': True, 'type': 'string' }, 'cycle_id': { 'required': True, 'type': 'integer' }, 'map_id': { 'required': True, 'type': 'integer' }, 'level_id': { 'required': True, 'type': 'integer' }, 'feedback_text': { 'required': True, 'type': 'string' } } res = validator.validate(data, schema) if not res: response.success = False response.status = 400 response.message = "Required data not found" store_feed = hp.StoreFeedback() response = store_feed.create(data) if response.success: response.success = True response.status = 200 response.data = {} response.message = "Success" elif not response: response.success = False response.status = 400 response.message = "Failure" return response.response_json()
def login(): data = request.get_json() schema = { 'emp_id': { 'required': True, 'type': 'string' }, 'client_id': { 'required': True, 'type': 'string' }, 'password': { 'required': True, 'type': 'string' }, 'user_role': { 'required': True, 'type': 'string' } } res = validator.validate(data, schema) if not res: response = Response() response.success = False response.status = 400 response.errors = "Required data not provided." login = hp.LogIn() response = login.validate(data) if response.success: response.data = { "client_id": response.data['client_id'], "cycle_id": response.data['cycle_id'], "user_type": data["user_role"], "user_info": { "name": response.data['name'], "emp_id": response.data['emp_id'], "email_id": response.data['email_id'] } } response.message = "Login Success!!" return response.response_json()
def add_cycle_details(): data = request.get_json() response = Response() schema = { 'client_id': { 'required': True, 'type': 'string' }, 'cycle_name': { 'required': True, 'type': 'string' }, 'from_date': { 'required': True, 'type': 'string' }, 'to_date': { 'required': True, 'type': 'string' } } res = validator.validate(data, schema) if not res: response.success = False response.status = 400 response.message = "Required data not found" client_cycle = hp.ClientCycleDetails() response = client_cycle.create(data) if response.success: response.status = 200 response.data = { "client_id": response.data['client_id'], "cycle_id": response.data['cycle_id'] } response.message = "Success" elif not response: response.success = False response.status = 400 response.message = "Failure" return response.response_json()
def table(request): url = url_for("table") # подключаем необходимые таблицы для списков в jinja2 regions = Region.query.all() queries = Users.query.all() # инициируем и преобразуем для чтетия выгрузку таблицы Users db = sqlite3.connect('data.db', uri=True) c = db.cursor() script = """ SELECT * FROM Users """ c.execute(script) columns = [desc[0] for desc in c.description] data = c.fetchall() df = pd.DataFrame(list(data), columns=columns) writer = pd.ExcelWriter(basedir2 + r'/database.xlsx') df.to_excel(writer, sheet_name='0', index=False) writer.save() replace_id_loc2(basedir2, r'/database.xlsx') # получаем данные из формы далее записывает данные в таблицу users if request.method == "POST": # запись в db полученой информации из формы try: firstName = request.form['firstName'] middleName = request.form['middleName'] lastName = request.form['lastName'] phone = request.form['phone'] email = request.form['email'] city = request.form['city'] rel_city = City.query.filter(City.name == city).first() try: done_db = Users( firstName=firstName, middleName=middleName, lastName=lastName, phone=phone, email=email, region_id=rel_city.region_id, city_id=rel_city.id, ) session.add(done_db) session.commit() return redirect(url_for("table")) except Exception as e: # обработаем исключение если город и регин не заполнен выведим пустую ячейку try: error = e.args[0].split() error_str = error[5].replace("'", "") if error_str == 'region_id' or error_str == 'city_id': done_db = Users( firstName=firstName, middleName=middleName, lastName=lastName, phone=phone, email=email, region_id=None, city_id=None, ) session.add(done_db) session.commit() finally: return redirect(url_for("table")) except Exception as e: try: return e finally: # сереализуем post запрос в json для ajax if request.form['region']: region = request.form['region'] records = [ z.to_json() for z in Region.query.filter_by(name_region=region) ] cont = json.dumps(records[0], sort_keys=True) return Response(cont, content_type="application/json") return render_template("table.html", url=url, queries=queries, regions=regions)
def add_emp_details(): data = request.get_json() schema = { 'emp_id': { 'required': True, 'type': 'string' }, 'client_id': { 'required': True, 'type': 'string' }, 'cycle_id': { 'required': True, 'type': 'string' }, 'emp_name': { 'required': True, 'type': 'string' }, 'emp_email': { 'required': True, 'type': 'string' }, 'function': { 'required': True, 'type': 'string' }, 'location': { 'required': True, 'type': 'string' }, 'band': { 'required': True, 'type': 'string' }, 'role': { 'required': True, 'type': 'string' }, 'assessment_role': { 'required': True, 'type': 'string' }, 'relationship': { 'required': True, 'type': 'dict', 'schema': { 'relation_type': { 'type': 'string' }, 'target_emp_id': { 'type': 'string' } } } } res = validator.validate(data, schema) if not res: response = Response() response.success = False response.status = 400 response.errors = "Required data not provided." employee = hp.Employee() response = employee.create([data]) if response.success: maping = hp.EmployeeRelationMapping() db_res = maping.create({ "emp_id": data["emp_id"], "cycle_id": data["cycle_id"], "relation_type": data['relationship']["relation_type"], "target_emp_id": data['relationship']["target_emp_id"] }) if not db_res.success: response.success = False response.status = 400 response.errors = "Employee relation not added" elif not response.success: response.success = False response.status = 400 response.errors = "Employee relation not added" return response.response_json()
def __init__(self): self.response = Response()