def index(): screens = Screen.get_all(g.user.company_id) return render_template('page/event/index.html', category="user", screens=screens, purpose=VisitorPurpose.state_mapping, subject_type=SubjectType.get_select_options())
def subject_employee(): gender = Gender.state_mapping return render_template( 'page/subject/index.html', subject_type_options=SubjectType.get_select_options(), gender=gender, category='employee', subject_type=SubjectType.TYPE_EMPLOYEE)
def subject_visitor(): gender = Gender.state_mapping return render_template( 'page/subject/index.html', subject_type_options=SubjectType.get_select_options(), gender=gender, category='visitor', subject_type=SubjectType.TYPE_VISITOR, purpose=VisitorPurpose.state_mapping)
def subjects_list(): ORDER_TYPE_TIME = 'time' ORDER_TYPE_NAME = 'name' params = request.args name = params.get('name') category = params.get('category') order = params.get('order') subject_type = SubjectType.parse_param(category) if subject_type is None: return error_result(ErrorCode.ERROR_INVALID_PARAM) if ((subject_type == SubjectType.TYPE_VISITOR and not g.user.has_permission(AccountPermission.ADD_VISITOR)) or (subject_type == SubjectType.TYPE_EMPLOYEE and not g.user.has_permission(AccountPermission.ADD_EMPLOYEE))): return error_result(ErrorCode.ERROR_PERMISSION_DENIED) query = g.user.company.subjects.options(db.eagerload_all(Subject.photos)) if name: name = name.replace('\\', '\\\\') query = query.filter( Subject.real_name.contains(name) | Subject.pinyin.contains(name)) if subject_type is not None: if subject_type == SubjectType.TYPE_VISITOR: # VIP is visitor, too query = query.filter( or_(Subject.subject_type == SubjectType.TYPE_VISITOR, Subject.subject_type == SubjectType.TYPE_VIP)) else: query = query.filter_by(subject_type=subject_type) #TODO add index to start_time and pinyin ... if order == ORDER_TYPE_TIME: query = query.order_by(Subject.start_time.desc()) elif order == ORDER_TYPE_NAME: query = query.order_by(Subject.pinyin.asc()) else: query = query.order_by(Subject.start_time.desc()) current, size = get_pagination(params) pagination = query.paginate(current, size, False) page = page_format(pagination) ret = [ subject.get_json(with_photos=True, with_visitor_type=True) for subject in pagination.items ] return success_result(ret, page)
def search(): return render_template('page/attendance/search.html', attendance_status=AttendanceStatus.get_select_options(), subject_type=SubjectType.get_select_options())
def warning(): screens = Screen.get_all(g.user.company_id) return render_template('page/event/index.html', category="warning", screens=screens, subject_type=SubjectType.get_select_options())
def exports(export_name): params = request.get_json() or request.form or request.args _, query = _build_query(params, g.user.company_id) events = query.all()[:1000] temp = tempfile.TemporaryFile() workbook = xlsxwriter.Workbook(temp) worksheet = workbook.add_worksheet("events") worksheet.set_column(0, 0, 30) worksheet.write(0, 0, u'因为导出文件大小限制,最多只导出1000条(请选择日期用来导出不同时段记录)') if params.get('category', 'user') == 'user': worksheet.write(1, 0, u'头像') worksheet.write(1, 1, u'工号') worksheet.write(1, 2, u'姓名') worksheet.write(1, 3, u'性别') worksheet.write(1, 4, u'部门') worksheet.write(1, 5, u'职位') worksheet.write(1, 6, u'识别位置') worksheet.write(1, 7, u'用户类型') worksheet.write(1, 8, u'识别时间') for i, event in enumerate(events): row_index = i + 2 if event.photo: filename = storage.get_path(event.photo) if _check_photo_file(filename): image = Image.open(filename) width, height = image.size x_scale = 200.0 / width y_scale = 200.0 / height worksheet.insert_image(row_index, 0, filename, { 'x_scale': x_scale, 'y_scale': y_scale }) worksheet.write(row_index, 1, event.subject and event.subject.job_number) worksheet.write(row_index, 2, event.subject and event.subject.name) worksheet.write( row_index, 3, event.subject and Gender.get_desc(event.subject.gender)) worksheet.write(row_index, 4, event.subject and event.subject.department) worksheet.write(row_index, 5, event.subject and event.subject.title) worksheet.write(row_index, 6, event.screen and event.screen.camera_position) worksheet.write( row_index, 7, event.subject and SubjectType.get_desc(event.subject.subject_type)) worksheet.write(row_index, 8, format_timestamp(event.timestamp)) worksheet.set_row(row_index, 160) else: worksheet.write(0, 0, u'头像') worksheet.write(0, 1, u'摄像头') worksheet.write(0, 2, u'识别位置') worksheet.write(0, 3, u'识别时间') for i, event in enumerate(events): row_index = i + 1 if event.photo: filename = storage.get_path(event.photo) if _check_photo_file(filename): image = Image.open(filename) width, height = image.size x_scale = 200.0 / width y_scale = 200.0 / height worksheet.insert_image(row_index, 0, filename, { 'x_scale': x_scale, 'y_scale': y_scale }) worksheet.write(row_index, 1, event.screen and event.screen.camera_name) worksheet.write(row_index, 2, event.screen and event.screen.camera_position) worksheet.write(row_index, 3, format_timestamp(event.timestamp)) worksheet.set_row(row_index, 160) workbook.close() temp.seek(0) sio = StringIO(temp.read()) temp.close() return send_file(sio, mimetype='application/octet-stream', attachment_filename=export_name)