def select_override(self, form_class, model=None): the_form_class = getattr(self, form_class) the_form_class.planeType = SelectField( '机型', choices=[(model.value, model.label) for model in get_allowed_models()]) choices = [] for aircraft in get_allowed_aircrafts(): choices.append(((aircraft.id, aircraft.model), aircraft.id)) the_form_class.jihao = WithTypeSelectField('飞行器注册号', choices=choices) return the_form_class
class _FaultReportsView(CustomView): extra_js = [ '/static/js/bootbox.min.js', '/static/js/custom_action.js', '/static/js/bootstrap-switch.min.js', '/static/js/switch_form.js', '/static/js/bootstrap-datetimepicker.min.js', '/static/js/datetimepicker.zh-cn.js', '/static/js/select_planeType.js', '/static/js/fault_report.js', '/static/js/upload_file.js', '/static/js/jquery.validate.min.js', '/static/js/customview_formvalidation.js', '/static/js/faultreports_validation.js', ] column_list = [ 'recordNum', 'planeType', 'jihao', 'faultDate', 'faultAdress', 'reportsMaker', 'aircraftNumber', 'statusName' ] column_labels = { 'recordNum': '编号', 'planeType': '机型', 'jihao': '飞机注册号', 'faultDate': '故障发生日期', 'faultAdress': '故障地点', 'reportsMaker': '故障报告人', 'aircraftNumber': '飞行编号', 'description': '故障描述', 'relateFileUrl': '上传附件', 'remark': '备注', 'statusName': '状态', } column_details_list = [ 'recordNum', 'planeType', 'jihao', 'faultDate', 'faultAdress', 'reportsMaker', 'aircraftNumber', 'remark', 'description', 'relateFileUrl' ] support_flow = partial(FaultReportsFlow, 'fault report flow', next_model=TroubleShooting) form_overrides = { 'faultDate': partial(DateField, widget=DateWidget()), 'relateFileUrl': partial(AirworthinessFileuploadField), 'planeType': partial(SelectField, choices=[(model.value, model.label) for model in get_allowed_models()]), 'jihao': partial(ComponentsDropdownsField), } column_searchable_list = ( 'recordNum', 'faultAdress', 'reportsMaker', 'aircraftNumber', 'jihao', ) form_excluded_columns = ['troubleShootings'] one_line_columns = ['description', 'relateFileUrl'] column_formatters = { 'relateFileUrl': accessory_formatter('relateFileUrl'), } form_widget_args = { 'recordNum': { 'readonly': True }, } @expose('/approve-edit-view/', methods=['GET', 'POST']) def approve_edit_view(self): return super(_FaultReportsView, self).approve_edit_view()
class _ExamineRepairRecordView(CustomView): # 排故检修记录列表视图应显示的内容 column_list = [ 'recordNum', 'faultType', 'planeType', 'jihao', 'maintainDate', 'faultAdress', 'maintainStaff', 'statusName' ] # 对应内容的中文翻译 column_labels = { 'recordNum': '编号', 'faultType': '故障类型', 'planeType': '机型', 'jihao': '飞机注册号', 'faultDate': '故障发生日期', 'faultAdress': '故障地点', 'reportsMaker': '故障报告人', 'aircraftNumber': '飞行编号', 'description': '故障描述', 'maintainStep': '维修措施', 'maintainDate': '维修日期', 'maintainStaff': '维修人员', 'repairFileUrl': '上传附件', 'checkDate': '检查日期', 'checkStaff': '检查人员', 'Soluted': '是否解决故障', 'remark': '备注', 'troubleShooting': '关联排故方案编号', 'statusName': '状态' } column_searchable_list = ( 'recordNum', 'faultType', 'jihao', 'faultAdress', 'maintainStaff', ) column_details_list = [ 'recordNum', 'faultType', 'planeType', 'jihao', 'faultDate', 'faultAdress', 'reportsMaker', 'aircraftNumber', 'maintainDate', 'maintainStaff', 'checkDate', 'checkStaff', 'Soluted', 'remark', 'troubleShooting', 'description', 'maintainStep', 'repairFileUrl' ] form_widget_args = { 'recordNum': { 'readonly': True }, } form_excluded_columns = ['reservedFault'] one_line_columns = ['description', 'maintainStep', 'repairFileUrl'] support_flow = partial(BasicFlow, 'Finish flow', support_create=True) extra_js = [ '/static/js/bootbox.min.js', '/static/js/custom_action.js', '/static/js/bootstrap-switch.min.js', '/static/js/switch_form.js', '/static/js/bootstrap-datetimepicker.min.js', '/static/js/datetimepicker.zh-cn.js', '/static/js/upload_file.js', # '/static/js/select_planeType.js', '/static/js/jquery.validate.min.js', '/static/js/customview_formvalidation.js', '/static/js/examine_repair_record_validation.js', ] form_overrides = { 'repairFileUrl': partial(AirworthinessFileuploadField), 'faultDate': partial(DateField, widget=DateWidget()), 'maintainDate': partial(DateField, widget=DateWidget()), 'checkDate': partial(DateField, widget=DateWidget()), 'description': partial(TextAreaField, render_kw={ 'rows': 3, 'style': 'resize:none;' }), 'maintainStep': partial(TextAreaField, render_kw={ 'rows': 3, 'style': 'resize:none;' }), 'planeType': partial(SelectField, choices=[(model.value, model.label) for model in get_allowed_models()]), 'jihao': partial(ComponentsDropdownsField), } column_formatters = { 'repairFileUrl': accessory_formatter('repairFileUrl'), } def on_model_change(self, form, model, is_created): super(_ExamineRepairRecordView, self).on_model_change(form, model, is_created) rf_id = request.args.get('id', '') view_url = request.args.get('view', '') if view_url and 'reservedfault' in view_url and is_created and rf_id: model.reservedFault_id = rf_id def __init__(self, *args, **kwargs): self.extra_js = getattr(self, 'extra_js', []) self.extra_css = getattr(self, 'extra_css', []) self.column_formatters.update({ 'faultDate': self.date_formatter_date, 'maintainDate': self.date_formatter_date, 'checkDate': self.date_formatter_date, }) super(_ExamineRepairRecordView, self).__init__(*args, **kwargs) def create_form(self, obj=None): self._create_form_class.troubleShooting.kwargs[ 'query_factory'] = trouble_shooting_choices ts_id = request.args.get('id', '') view_url = request.args.get('view', '') if ts_id: if view_url and 'troubleshooting' in view_url: ts = TroubleShooting.query.filter( TroubleShooting.id == ts_id).first() inst = FaultReports.query.join( TroubleShooting, TroubleShooting.faultReports_id == FaultReports.id).filter( TroubleShooting.id == ts_id) tmp_form_class = self.get_create_form() datas = [] for key, value in inst[0].__dict__.iteritems(): if key not in self.review_details_columns or\ key == 'recordNum': continue datas.append(key) tmp = getattr(tmp_form_class, key) tmp.kwargs['default'] = value tmp_form_class.troubleShooting.kwargs['default'] = ts tmp_form_class.faultType.kwargs['default'] = '严重故障' return tmp_form_class(get_form_data(), obj) if view_url and 'reservedfault' in view_url: rf = ReservedFault.query.filter( ReservedFault.id == ts_id).first() return self.create_form_with_default(rf) return super(_ExamineRepairRecordView, self).create_form(obj)
class _EngineeringOrderView(CustomView): extra_js = [ '/static/js/upload_file.js', '/static/js/bootbox.min.js', '/static/js/custom_action.js', '/static/js/bootstrap-switch.min.js', '/static/js/bootstrap-datetimepicker.min.js', '/static/js/datetimepicker.zh-cn.js', '/static/js/switch_form.js', '/static/js/select_planeType.js', '/static/js/jquery.validate.min.js', '/static/js/customview_formvalidation.js', '/static/js/engineeringorder_validation.js', ] # 工程指令列表视图应显示的内容 column_list = [ 'insNum', 'insTitle', 'insCategory', 'statusName', ] # 对应内容的中文翻译 column_labels = { 'insNum': '指令号', 'insTitle': '标题', 'insCategory': '指令类别', 'relateFileUrl': '相关文档', 'planeType': '机型', 'jihao': '飞机注册号', 'effectPart': '受影响部件', 'effectEngine': '受影响的发动机', 'grantTime': '发放期限', 'finishTime': '完成期限', 'executeTime': '执行日期', 'isClaim': '能否索赔', 'stopHours': '工时停场时', 'repeatePeriod': '重复周期', 'ataCode': 'ATA章节号', 'usability': '适用性', 'manualChange': '手册更改', 'isFeedback': '是否反馈', 'reason': '概述/理由', 'remark': '备注/说明', 'statusName': '状态', 'maintenanceRecord': '关联的维护保养记录', 'airworthiness': '关联的适航文件编号' } # 待复核的内容要少 column_details_list = [ 'insNum', 'insTitle', 'insCategory', 'planeType', 'jihao', 'effectPart', 'effectEngine', 'grantTime', 'finishTime', 'executeTime', 'isClaim', 'stopHours', 'repeatePeriod', 'ataCode', 'usability', 'manualChange', 'isFeedback', 'remark', 'maintenanceRecord', 'airworthiness', 'reason', 'relateFileUrl' ] support_flow = partial(EOFlow, 'Default basic approval flow') form_excluded_columns = ['troubleshooting', 'maintenanceRecord'] column_formatters = { 'relateFileUrl': accessory_formatter('relateFileUrl'), } one_line_columns = ['reason', 'relateFileUrl'] column_searchable_list = ( 'insNum', 'insTitle', 'insCategory', ) form_overrides = { 'relateFileUrl': partial(EngineeringOrderFileuploadField), 'repeatePeriod': partial(InputSelectMixinField), 'grantTime': partial(DateField, widget=DateWidget()), 'finishTime': partial(DateField, widget=DateWidget()), 'executeTime': partial(DateField, widget=DateWidget()), 'planeType': partial(SelectField, choices=[(model.value, model.label) for model in get_allowed_models()]), 'jihao': partial(ComponentsDropdownsField), } def create_form(self, obj=None): ao_id = request.args.get('id', '') if ao_id: inst = Airworthiness.query.filter( Airworthiness.id == ao_id).first() return self.create_form_with_default(inst, 'airworthiness') return super(_EngineeringOrderView, self).create_form(obj) def on_model_change(self, form, model, is_created): super(_EngineeringOrderView, self).on_model_change(form, model, is_created) ao_id = request.args.get('id', '') if is_created and ao_id: model.airworthiness_id = ao_id @property def form_widget_args(self): return { 'insNum': { 'readonly': True }, } def validate_form(self, form): if form.__class__.__name__ != self.get_delete_form().__name__: form.repeatePeriod.validators = [DataRequired('请输入正数')] form.insNum.validators = [DataRequired()] return super(_EngineeringOrderView, self).validate_form(form) def get_query(self): datas = super(_EngineeringOrderView, self).get_query() return self.get_recieved_query(datas, 'engineeringorder')
def get_aircraft_info(self): aircraft_id = get_allowed_aircrafts(bounded=True) aircraft_type = get_allowed_models() return jsonify( code=200, data={'id': aircraft_id, 'type': aircraft_type})
class _TroubleShootingView(CustomView): """排故方案""" list_template = 'trouble_shooting/list.html' create_template = 'trouble_shooting/create.html' approve_edit_template = 'trouble_shooting/approve_edit.html' # 排故方案列表视图应显示的内容 column_list = [ 'shootingNum', 'planeType', 'jihao', 'formulateDate', 'formulatePerson', 'enforceStaff', 'statusName' ] extra_js = [ '/static/js/bootbox.min.js', '/static/js/custom_action.js', '/static/js/bootstrap-switch.min.js', '/static/js/switch_form.js', '/static/js/bootstrap-datetimepicker.min.js', '/static/js/datetimepicker.zh-cn.js', '/static/js/select_planeType.js', '/static/js/trouble_shooting.js', '/static/js/upload_file.js', '/static/js/jquery.validate.min.js', ] # 对应内容的中文翻译 column_labels = { 'shootingNum': '编号', 'planeType': '机型', 'jihao': '飞机注册号', 'formulateDate': '制定日期', 'formulatePerson': '制定人', 'shootingFileUrl': '上传附件', 'description': '故障及方案描述', 'maintainStep': '维修措施', 'enforceDate': '执行日期', 'enforceStaff': '执行人员', 'remark': '备注', 'faultReports': '关联故障报告单号', 'statusName': '状态', 'erRecord': '关联的排故检修记录' } column_details_list = [ 'shootingNum', 'planeType', 'jihao', 'formulateDate', 'formulatePerson', 'enforceDate', 'enforceStaff', 'remark', 'faultReports', 'description', 'maintainStep', 'shootingFileUrl' ] form_widget_args = { 'shootingNum': { 'readonly': True }, } support_flow = partial(TroubleShootingFlow, 'Finish flow', next_model=ExamineRepairRecord) form_excluded_columns = ['erRecord'] column_searchable_list = ('shootingNum', 'jihao', 'formulatePerson', 'enforceStaff',) one_line_columns = ['description', 'maintainStep', 'shootingFileUrl'] form_overrides = { 'shootingFileUrl': partial(AirworthinessFileuploadField), 'formulateDate': partial(DateInt, widget=DateIntWidget()), 'enforceDate': partial(DateInt, widget=DateIntWidget()), 'description': partial(TextAreaField, render_kw={'rows': 3, 'style': 'resize:none;'}), 'maintainStep': partial(TextAreaField, render_kw={'rows': 3, 'style': 'resize:none;'}), 'planeType': partial(SelectField, choices=[ (model.value, model.label) for model in get_allowed_models()]), 'jihao': partial(ComponentsDropdownsField), } column_formatters = { 'shootingFileUrl': accessory_formatter('shootingFileUrl'), } def __init__(self, *args, **kwargs): self.extra_js = getattr(self, 'extra_js', []) self.extra_css = getattr(self, 'extra_css', []) self.column_formatters.update({ 'formulateDate': self.date_formatter_date, 'enforceDate': self.date_formatter_date, }) super(_TroubleShootingView, self).__init__(*args, **kwargs) def create_form(self, obj=None): if not request.form: self._create_form_class.formulatePerson.kwargs[ 'default'] = current_user.realName fr_id = request.args.get('id', '') if fr_id: inst = FaultReports.query.filter(FaultReports.id == fr_id).first() return self.create_form_with_default(inst, 'faultReports') return super(_TroubleShootingView, self).create_form(obj) @expose('/approve-edit-view/', methods=['GET', 'POST']) def approve_edit_view(self): return super(_TroubleShootingView, self).approve_edit_view() def validate_form(self, form): if form.__class__.__name__ != self.get_delete_form().__name__: form.faultReports.validators = [DataRequired()] return super(_TroubleShootingView, self).validate_form(form) def get_query(self): datas = super(_TroubleShootingView, self).get_query() return self.get_recieved_query(datas, 'troubleshooting')
class _MaintenanceRecordView(CustomView): """维护保养记录""" create_template = 'unvalidate/create.html' approve_edit_template = 'unvalidate/approve_edit.html' column_list = [ 'recordNum', 'planeType', 'jihao', 'checkType', 'checkPlace', 'involvePerson', 'checkDate', 'checkContent', 'statusName' ] column_labels = { 'recordNum': '编号', 'planeType': '机型', 'jihao': '飞机注册号', 'checkType': '检查类型', 'checkPlace': '检查地点', 'effectPart': '受影响部件', 'effectEngine': '受影响的发动机', 'stopTime': '工时停场时', 'involvePerson': '涉及人员', 'checkDate': '检查日期', 'checkContent': '检查内容', 'statusName': '状态', 'faultReports': '关联的工程指令' } column_details_list = [ 'recordNum', 'faultReports', 'planeType', 'jihao', 'checkType', 'checkPlace', 'effectPart', 'effectEngine', 'stopTime', 'involvePerson', 'checkDate', 'checkContent' ] support_flow = partial(BasicFlow, 'Finish flow', support_create=True) column_searchable_list = ( 'recordNum', 'checkType', 'involvePerson', 'checkPlace', 'jihao', ) one_line_columns = ['checkContent'] form_overrides = { 'checkDate': partial(DateField, widget=DateWidget()), 'involvePerson': partial(choiceRealNameSelectField), 'planeType': partial(SelectField, choices=[(model.value, model.label) for model in get_allowed_models()]), 'jihao': partial(ComponentsDropdownsField), } @property def form_widget_args(self): return { 'recordNum': { 'readonly': True }, } def __init__(self, *args, **kwargs): self.extra_js = getattr(self, 'extra_js', []) self.extra_js.extend([ '/static/js/bootstrap-datetimepicker.min.js', '/static/js/datetimepicker.zh-cn.js', '/static/js/select_planeType.js' ]) self.extra_css = getattr(self, 'extra_css', []) self.extra_css.extend([ '/static/css/datepicker.css', '/static/css/bootstrap-datetimepicker.min.css', ]) super(_MaintenanceRecordView, self).__init__(*args, **kwargs) def create_form(self, obj=None): self._create_form_class.faultReports.kwargs[ 'query_factory'] = engineer_choices eo_id = request.args.get('id', '') if eo_id: inst = EngineeringOrder.query.filter( EngineeringOrder.id == eo_id).first() return self.create_form_with_default(inst, 'faultReports') return super(_MaintenanceRecordView, self).create_form(obj) def on_model_change(self, form, model, is_created): super(_MaintenanceRecordView, self).on_model_change(form, model, is_created) eo_id = request.args.get('id', '') if is_created and eo_id: model.faultReports_id = eo_id def validate_form(self, form): if form.__class__.__name__ != self.get_delete_form().__name__: form.recordNum.validators = [DataRequired()] form.checkDate.validators = [DataRequired()] form.checkContent.validators = [DataRequired()] return super(_MaintenanceRecordView, self).validate_form(form)
class _ReservedFaultView(CustomView): # 保留故障列表视图应显示的内容 create_template = 'unvalidate/create.html' approve_edit_template = 'unvalidate/approve_edit.html' column_list = [ 'reservedNum', 'planeType', 'jihao', 'engineNum', 'statusName' ] extra_js = [ '/static/js/bootbox.min.js', '/static/js/custom_action.js', '/static/js/bootstrap-switch.min.js', '/static/js/switch_form.js', '/static/js/bootstrap-datetimepicker.min.js', '/static/js/datetimepicker.zh-cn.js', '/static/js/select_planeType.js', '/static/js/reserved_fault.js' ] # 对应内容的中文翻译 column_labels = { 'reservedNum': '编号', 'planeType': '机型', 'flyhours': '飞行小时数', 'jihao': '注册号', 'engineNum': '发动机序号', 'description': '保留故障描述', 'expectAlter': '预期更改方法', 'measure': '采取措施', 'reason': '申请保留原因', 'limit': '申请保留期限', 'proposer': '申请人', 'date': '申请日期', 'licenceNO': '执照号', 'remarks': '备注', 'createTime': '制单时间', 'updateTime': '修改时间', 'statusName': '状态', } column_details_list = [ 'reservedNum', 'planeType', 'flyhours', 'jihao', 'engineNum', 'measure', 'limit', 'proposer', 'date', 'licenceNO', 'remarks', 'description', 'expectAlter', 'reason', ] use_inheritance_operation = True support_flow = partial(RetainFlow, 'one approval flow', create_action=createER) form_excluded_columns = ['action', 'erRecord'] column_searchable_list = ('reservedNum', ) one_line_columns = ['description', 'expectAlter', 'reason'] form_overrides = { 'measure': partial(SelectField, choices=[ ('按备注栏的要求', '按备注栏的要求'), ('挂禁止操作指示牌', '挂禁止操作指示牌'), ('其他', '其他'), ]), 'date': partial(DateInt, widget=DateIntWidget()), 'limit': partial(DateInt, widget=DateIntWidget()), 'planeType': partial(SelectField, choices=[(model.value, model.label) for model in get_allowed_models()]), 'jihao': partial(ComponentsDropdownsField), } @property def form_widget_args(self): return { 'reservedNum': { 'readonly': True }, 'relateNum': { 'readonly': True }, } def __init__(self, *args, **kwargs): self.extra_js = getattr(self, 'extra_js', []) self.extra_css = getattr(self, 'extra_css', []) self.column_formatters.update({ 'date': self.date_formatter_date, 'limit': self.date_formatter_date, }) super(_ReservedFaultView, self).__init__(*args, **kwargs) @expose('/new/', methods=['GET', 'POST']) def create_view(self): for field in ['limit', 'date']: set_field = getattr(self._create_form_class, field) set_field.kwargs.update({'default': time.time()}) return super(_ReservedFaultView, self).create_view() @expose('/approve-edit-view/', methods=['GET', 'POST']) def approve_edit_view(self): return super(_ReservedFaultView, self).approve_edit_view() def validate_form(self, form): if form.__class__.__name__ != self.get_delete_form().__name__: form.description.validators = [DataRequired()] form.reason.validators = [DataRequired()] form.date.validators = [DataRequired()] if form.flyhours.data: form.flyhours.validators = [ NumberRange(min=0, message='请输入合理的数值') ] form.limit.validators = [ DataRequired(), NumberRange(min=form.date.data, message="申请保留期限应晚于申请日期") ] return super(_ReservedFaultView, self).validate_form(form)