def is_save(self, request): cleaned_data = super(WorkOrderCloseForm, self).clean() id = cleaned_data.get('id') status = cleaned_data.get('status') addition_info = cleaned_data.get('addition_info') data = AuditContents.objects.get(pk=id) context = {} # 当记录关闭时 if data.progress == '5': context = {'status': 2, 'msg': '该记录已被关闭、请不要重复提交'} # 当记录未关闭时 else: if len(addition_info) >= 5: # 当进度为:处理中或已完成时 if status == u'提交': if data.progress == '3' or data.progress == '4': context = {'status': 2, 'msg': '操作失败、数据正在处理中或已完成'} else: data.progress = '5' data.close_user = request.user.username data.close_reason = addition_info data.close_time = timezone.now() data.save() # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, id=id, type='close', addition_info=addition_info) context = {'status': 0, 'msg': '操作成功、记录关闭成功'} elif status == u'结束': context = {'status': 2, 'msg': '操作失败、关闭窗口'} else: context = {'status': 2, 'msg': '操作失败、<关闭原因>输入不能少于5个字符'} return context
def is_save(self, request): cleaned_data = super(OnlineFeedbackForm, self).clean() id = cleaned_data.get('id') status = cleaned_data.get('status') addition_info = cleaned_data.get('addition_info') data = AuditContents.objects.get(pk=id) context = {} # 当记录关闭时 if data.progress == '5': context = {'status': 2, 'msg': '该记录已被关闭、请不要重复提交'} # 当记录未关闭时 else: # 当进度状态为:已批准或处理中时 if data.progress == '2' or data.progress == '3': # 当用户点击的是处理中, 状态变为:处理中 if status == u'处理中': data.progress = '3' data.save() send_verify_mail.delay(latest_id=id, type='feedback', username=request.user.username, user_role=request.user.user_role(), addition_info=addition_info) # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, title=data.title, type='feedback', progress='3') context = {'status': 0, 'msg': '操作成功、正在处理中'} # 当用户点击的是已完成, 状态变为:已完成 elif status == u'已完成': data.progress = '4' data.operate_time = timezone.now() data.save() send_verify_mail.delay(latest_id=id, type='feedback', username=request.user.username, user_role=request.user.user_role(), addition_info=addition_info) # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, title=data.title, type='feedback', progress='4') context = {'status': 0, 'msg': '操作成功、处理完成'} # 未批准 elif data.progress == '1' or data.progress == '0': context = {'status': 2, 'msg': '操作失败、审核未通过'} # 其他情况 else: context = {'status': 2, 'msg': '操作失败、请不要重复提交'} return context
def is_save(self, request): cleaned_data = super(OnlineApproveForm, self).clean() id = cleaned_data.get('id') status = cleaned_data.get('status') addition_info = cleaned_data.get('addition_info') data = AuditContents.objects.get(pk=id) context = {} # 当记录关闭时 if data.progress == '5': context = {'status': 2, 'msg': '该记录已被关闭、请不要重复提交'} # 当记录未关闭时 else: if data.progress == '0' or data.progress == '1': # 当用户点击的是通过, 状态变为:已批准 if status == u'通过': data.progress = '2' data.verifier_time = timezone.now() data.save() send_verify_mail.delay(latest_id=id, type='approve', username=request.user.username, user_role=request.user.user_role(), addition_info=addition_info) # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, title=data.title, type='approve', progress='2') context = {'status': 0, 'msg': '操作成功、审核通过'} # 当用户点击的是不通过, 状态变为:未批准 elif status == u'不通过': data.progress = '1' data.verifier_time = timezone.now() data.save() send_verify_mail.delay(latest_id=id, type='approve', username=request.user.username, user_role=request.user.user_role(), addition_info=addition_info) # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, title=data.title, type='approve', progress='1') context = {'status': 0, 'msg': '操作成功、审核未通过'} # 其他情况 else: context = {'status': 2, 'msg': '操作失败、请不要重复提交'} return context
def is_save(self, request): cleaned_data = super(WorkOrderReplyForm, self).clean() reply_id = cleaned_data.get('reply_id') reply_contents = cleaned_data.get('reply_contents') OlAuditContentsReply.objects.create( reply_id=reply_id, user_id=request.user.uid, reply_contents=reply_contents) data = AuditContents.objects.get(pk=reply_id) data.updated_at = timezone.now() data.save() # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, id=id, type='reply', addition_info=reply_contents) context = {'status': 0, 'msg': '回复成功'} return context
def save(self, request): cleaned_data = super(HookWorkOrderForm, self).clean() host, port, database = cleaned_data['database'].split(',') id = cleaned_data.get('id') envi_desc = cleaned_data['envi_desc'] jump_url = cleaned_data.get('jump_url') progress_choices = '2' if envi_desc == 1 else '0' data = AuditContents.objects.get(pk=id) if AuditContents.objects.filter(title=data.title, envi_desc=envi_desc).first(): # 如果指定的环境存在已被钩的工单,直接跳转 context = {'status': 0, 'jump_url': jump_url} else: # 工单状态必须为已完成 if data.progress in ('4', '6'): obj = AuditContents.objects.create( title=data.title, url=data.url, tasks=data.tasks, operate_type=data.operate_type, host=host, database=database, port=port, envi_desc=envi_desc, progress=progress_choices, remark=data.remark, proposer=data.proposer, operator=data.operator, contents=data.contents, updated_at=timezone.now()) # 更新状态为:已勾住 AuditContents.objects.filter(pk=id).update(progress='6') # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, id=obj.id, type='hook') # 跳转到工单记录页面 context = {'status': 0, 'jump_url': jump_url} else: context = {'status': 2, 'msg': '当前工单进度:未完成,无法勾住'} return context
def is_save(self, request): cleaned_data = super(OnlineAuditForm, self).clean() title = cleaned_data.get('title') + '_[' + datetime.now().strftime( "%Y%m%d%H%M%S") + ']' verifier = cleaned_data.get('verifier') operator = cleaned_data.get('operator') email_cc = self.data.get('email_cc_id') group_id = cleaned_data.get('group_id') host = cleaned_data.get('host') database = cleaned_data.get('database') operate_type = cleaned_data.get('operate_type') contents = cleaned_data.get('contents') result = IncepSqlCheck(contents, host, database, request.user.username).is_check_pass() if result.get('status') == 2: context = result else: AuditContents.objects.create(title=title, operate_type=operate_type, host=host, database=database, group_id=group_id, proposer=request.user.username, operator=operator, verifier=verifier, email_cc=email_cc) # 向子表插入关联数据 OlAuditDetail.objects.create(ol=AuditContents.objects.latest('id'), contents=contents) # 发送通知邮件 latest_id = AuditContents.objects.latest('id').id send_commit_mail.delay(latest_id=latest_id) # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, title=title, type='commit') context = {'status': 0, 'jump_url': '/projects/ol/ol_records/'} return context
def is_save(self, request): cleaned_data = super(WorkOrderFeedbackForm, self).clean() id = cleaned_data.get('id') status = cleaned_data.get('status') addition_info = cleaned_data.get('addition_info') data = AuditContents.objects.get(pk=id) context = {} # 当记录关闭时 if data.progress == '5': context = {'status': 2, 'msg': '该记录已被关闭、请不要重复提交'} # 当记录未关闭时 else: # 当进度状态为:已批准或处理中时 if data.progress == '2' or data.progress == '3': # 当用户点击的是处理中, 状态变为:处理中 if status == u'处理中': data.progress = '3' data.updated_at = timezone.now() data.save() # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, id=id, type='feedback', addition_info=addition_info) context = {'status': 0, 'msg': '操作成功、正在处理中'} # 当用户点击的是已完成, 状态变为:已完成 elif status == u'已完成': data.progress = '4' data.updated_at = timezone.now() data.save() # 发送钉钉推送(包括任务进度) xiaoding_pull.delay(user=request.user.username, id=id, type='feedback', addition_info=addition_info) context = {'status': 0, 'msg': '操作成功、处理完成'} # 未批准 elif data.progress == '1' or data.progress == '0': context = {'status': 2, 'msg': '操作失败、审核未通过'} # 其他情况 else: context = {'status': 2, 'msg': '操作失败、请不要重复提交'} return context
def is_save(self, request): cleaned_data = super(WorkOrderAuditForm, self).clean() title = cleaned_data.get('title') + '_[' + datetime.now().strftime("%Y%m%d%H%M%S") + ']' url = cleaned_data.get('url') tasks = cleaned_data.get('tasks') operator = cleaned_data.get('operator') envi_desc = cleaned_data.get('envi_desc') remark = cleaned_data.get('remark') jump_url = cleaned_data.get('jump_url') host, port, database = cleaned_data.get('database').split(',') operate_type = cleaned_data.get('operate_type') contents = cleaned_data.get('contents') result = IncepSqlCheck(contents, host, port, database, request.user.username).is_check_pass() if result.get('status') == 2: context = result else: obj = AuditContents.objects.create( title=title, url=url, tasks=tasks, operate_type=operate_type, host=host, database=database, port=port, envi_desc=envi_desc, remark=remark, proposer=request.user.username, operator=operator, contents=contents ) # 发送钉钉推送 xiaoding_pull.delay(user=request.user.username, id=obj.id, type='commit') # 跳转到工单记录页面 context = {'status': 0, 'jump_url': jump_url} return context