def post(self, request): res = dict() work_order = get_object_or_404(WorkOrder, pk=request.POST['id']) work_order_form = WorkOrderUpdateForm(request.POST, instance=work_order) if int(work_order.status) <= 1: if work_order_form.is_valid(): work_order_form.save() res['status'] = 'success' if work_order.status == "2": res['status'] = 'submit' try: SendMessage.send_workorder_email( request.POST['number']) res['status'] = 'submit_send' except Exception: pass else: pattern = '<li>.*?<ul class=.*?><li>(.*?)</li>' errors = str(work_order_form.errors) work_order_form_errors = re.findall(pattern, errors) res = { 'status': 'fail', 'work_order_form_errors': work_order_form_errors[0] } else: res['status'] = 'ban' return HttpResponse(json.dumps(res), content_type='application/json')
def post(self, request): res = dict(status='fail') work_order_record_form = WorkOrderRecordForm(request.POST) if work_order_record_form.is_valid(): work_order = get_object_or_404(WorkOrder, pk=request.POST['work_order']) status = work_order.status if status in ['0', '2' ] and request.user.id == work_order.approver_id: work_order_record_form.save() work_order.receiver_id = request.POST['receiver'] work_order.status = "3" work_order.do_time = request.POST['do_time'] work_order.save() res['status'] = 'success' try: SendMessage.send_workorder_email(request.POST['number']) res['status'] = 'success_send' except Exception: pass else: res['status'] = 'ban' return HttpResponse(json.dumps(res, cls=DjangoJSONEncoder), content_type='application/json')
def post(self, request): res = dict() work_order = get_object_or_404(WorkOrder, pk=request.POST['id']) work_order_form = WorkOrderUpdateForm(request.POST, instance=work_order) if int(work_order.status) <= 1: if work_order_form.is_valid(): work_order_form.save() res['status'] = 'success' if work_order.status == "2": res['status'] = 'submit' try: SendMessage.send_workorder_email(request.POST['number']) res['status'] = 'submit_send' except Exception: pass else: pattern = '<li>.*?<ul class=.*?><li>(.*?)</li>' errors = str(work_order_form.errors) work_order_form_errors = re.findall(pattern, errors) res = { 'status': 'fail', 'work_order_form_errors': work_order_form_errors[0] } else: res['status'] = 'ban' return HttpResponse(json.dumps(res), content_type='application/json')
def workOrderUpdateView(request): if request.method == 'GET': type_list = [] filters = dict() if 'id' in request.GET and request.GET['id']: work_order = get_object_or_404(WorkOrder, pk=request.GET['id']) for work_order_type in WorkOrder.type_choices: type_dict = dict(item=work_order_type[0], value=work_order_type[1]) type_list.append(type_dict) if request.user.department_id == 9: filters['belongs_to_id'] = request.user.id customer = Customer.objects.values().filter(**filters) role = get_object_or_404(Role, title='审批') approver = role.userprofile_set.all() ret = { 'work_order': work_order, 'type_list': type_list, 'customer': customer, 'approver': approver, } return render(request, 'personal/workorder/workorder_update.html', ret) else: res = dict() work_order = get_object_or_404(WorkOrder, pk=request.POST['id']) work_order_form = WorkOrderUpdateForm(request.POST, instance=work_order) if int(work_order.status) <= 1: if work_order_form.is_valid(): work_order_form.save() res['status'] = 'success' if work_order.status == "2": res['status'] = 'submit' try: SendMessage.send_workorder_email( request.POST['number']) res['status'] = 'submit_send' except Exception: pass else: pattern = '<li>.*?<ul class=.*?><li>(.*?)</li>' errors = str(work_order_form.errors) work_order_form_errors = re.findall(pattern, errors) res = { 'status': 'fail', 'work_order_form_errors': work_order_form_errors[0] } else: res['status'] = 'ban' return HttpResponse(json.dumps(res), content_type='application/json')
def workOrderCreateView(request): if request.method == 'GET': type_list = [] filters = dict() for work_order_type in WorkOrder.type_choices: type_dict = dict(item=work_order_type[0], value=work_order_type[1]) type_list.append(type_dict) if request.user.department_id == 9: # 新建工单时销售部门只能选择自己的用户信息 filters['belongs_to_id'] = request.user.id customer = Customer.objects.values().filter(**filters) role = get_object_or_404(Role, title='审批') approver = role.userprofile_set.all() try: number = WorkOrder.objects.latest('number').number except WorkOrder.DoesNotExist: number = "" new_number = ToolKit.bulidNumber('SX', 9, number) ret = { 'type_list': type_list, 'customer': customer, 'approver': approver, 'new_number': new_number } return render(request, 'personal/workorder/workorder_create.html', ret) else: res = dict() work_order = WorkOrder() work_order_form = WorkOrderCreateForm(request.POST, instance=work_order) if work_order_form.is_valid(): work_order_form.save() res['status'] = 'success' if work_order.status == "2": res['status'] = 'submit' try: SendMessage.send_workorder_email(request.POST['number']) res['status'] = 'submit_send' except Exception: pass else: pattern = '<li>.*?<ul class=.*?><li>(.*?)</li>' errors = str(work_order_form.errors) work_order_form_errors = re.findall(pattern, errors) res = { 'status': 'fail', 'work_order_form_errors': work_order_form_errors[0] } return HttpResponse(json.dumps(res), content_type='application/json')
def post(self, request): res = dict(status='fail') work_order_record_form = WorkOrderRecordForm(request.POST) work_order = get_object_or_404(WorkOrder, pk=request.POST['work_order']) if work_order_record_form.is_valid() and work_order.proposer.id == request.user.id: status = work_order.status if status == '4' and request.user.id == work_order.proposer_id: work_order_record_form.save() work_order.status = "5" work_order.save() res['status'] = 'success' try: SendMessage.send_workorder_email(request.POST['number']) res['status'] = 'success_send' except Exception as e: pass else: res['status'] = 'ban' return HttpResponse(json.dumps(res, cls=DjangoJSONEncoder), content_type='application/json')
def post(self, request): res = dict(status='fail') work_order_record_form = WorkOrderRecordForm(request.POST) work_order = get_object_or_404(WorkOrder, pk=request.POST['work_order']) if work_order_record_form.is_valid(): status = work_order.status if status == '3': work_order_record_form.save() work_order.status = "0" work_order.save() res['status'] = 'success' try: SendMessage.send_workorder_email(request.POST['number']) res['status'] = 'success_send' except Exception as e: pass work_order.receiver = None work_order.save() else: res['status'] = 'ban' return HttpResponse(json.dumps(res, cls=DjangoJSONEncoder), content_type='application/json')