def step_change(request): """ 编辑指定步骤类别的步骤序号的数据 """ form = StepForm(request.POST) if not form.is_valid(): return render_json({'result': False, 'msg': u"参数不合法"}) b_name = form.cleaned_data['business_name'] t_name = form.cleaned_data['template_name'] step_xh = form.cleaned_data['step_xh'] operate_attention = form.cleaned_data['operate_attention'] comment = form.cleaned_data['comment'] responser = form.cleaned_data['responser'] instance_flag = form.cleaned_data['instance_flag'] if not check_users_from_paas(responser, request.COOKIES['bk_token'])[0]: return render_json({'result': False, 'msg': u'参数不合法!'}) if instance_flag: status = update_task_step("instance", b_name, t_name, step_xh, request.user.username, operate_attention, comment, responser) else: status = update_task_step("template", b_name, t_name, step_xh, request.user.username, operate_attention, comment, responser) if not status: return render_json({'result': False, 'msg': u"修改步骤 %s失败" % step_xh}) else: return render_json({'result': True, 'msg': u"修改步骤%s成功" % step_xh})
def enreg_steps(request, projet_slug): project = get_object_or_404(Projet, slug=projet_slug) if request.method == "POST": form = StepForm(request.POST) if form.is_valid(): step = form.save(commit=False) step.project = project step.save() else: form = StepForm() return render(request, 'projet/step.html', { 'form': form, })
def addStep(event_id): event = Event.query.get(event_id) form = StepForm() suggestions = Suggestion.query.filter(Suggestion.category == event.category) event_steps = Step.query.order_by(Step.step_num).filter(Step.event_id == event.id) step_num = event_steps.count() + 1 def add_step(event_id, step_num, step): new_step = Step(event_id = event_id, step_num = step_num, step=step) sqldb.session.add(new_step) sqldb.session.commit() if form.validate_on_submit(): add_step(event_id, step_num, form.step.data) return redirect("addStep/"+str(event_id)) return render_template("addStep.html", form = form, event=event, suggestions = suggestions, event_steps=event_steps)
def createstep(request): if request.method == 'POST': # If the form has been submitted... form = StepForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... form.save() return HttpResponseRedirect('/createpage/') # Redirect after POST else: form = StepForm() # An unbound form return render(request, "createpage/createstep.html", { 'form': form, })
def edit_step(id): check_admin() add_step = False step = Step.query.get_or_404(id) form = StepForm(obj=step) if form.validate_on_submit(): step.name = form.name.data step.description = form.description.data step.step_action = form.step_action.data step.action_string = form.action_string.data step.secondary_regex = form.secondary_regex.data step.filename_mask = form.filename_mask.data db.session.commit() flash('You have successfully edited a step.') return redirect(url_for('admin.list_steps', task_id=step.task_id)) return add_edit_form_template("Edit", "Step", form)
def step_create(request): """ @运维配置——编辑业务模板,新增指定位置步骤 """ form = StepForm(request.POST) if not form.is_valid(): return render_json({'result': False, 'msg': u"参数错误"}) b_name = form.cleaned_data['business_name'] t_name = form.cleaned_data['template_name'] step_xh = form.cleaned_data['step_xh'] operate_attention = form.cleaned_data['operate_attention'] comment = form.cleaned_data['comment'] responser = form.cleaned_data['responser'] instance_flag = form.cleaned_data['instance_flag'] if not check_users_from_paas(responser, request.COOKIES['bk_token'])[0]: return render_json({'result': False, 'msg': u'参数不合法!'}) if instance_flag: business = BUSINESS_MODEL['instance'] else: business = BUSINESS_MODEL['template'] try: business.objects.get(business_name=b_name, template_name=t_name) except ObjectDoesNotExist: logger.error( u'查询任务实例步骤失败,business_name: %s, template_name: %s, step_xh:%s' % (b_name, t_name, step_xh)) return render_json({'result': False, 'msg': u"任务实例不存在"}) if instance_flag: status = create_task_step("instance", b_name, t_name, step_xh, request.user.username, operate_attention, comment, responser) else: status = create_task_step("template", b_name, t_name, step_xh, request.user.username, operate_attention, comment, responser) if not status: return render_json({'result': False, 'msg': u"添加步骤 %s数据时失败" % step_xh}) else: return render_json({'result': True, 'msg': u"添加步骤%s成功" % step_xh})
def add_step(task_id): check_admin() add_step = True form = StepForm() if form.validate_on_submit(): step = Step(name=form.name.data, description=form.description.data, step_action=form.step_action.data, action_string=form.action_string.data, secondary_regex=form.secondary_regex.data, filename_mask=form.filename_mask.data, task_id=task_id) try: db.session.add(step) db.session.commit() flash('You have successfully added a new step.') except: flash('Error: name already exists.') return redirect(url_for('admin.list_steps', task_id=task_id)) return add_edit_form_template("Add", "Step", form)
def ProcStep(request): try: if CheckAccess(request,'6') != 'OK': return render_to_response("proc/notaccess/proc.html") except: return HttpResponseRedirect('/') proc_id = request.session['proc_id'] next_person = NextPerson(proc_id) proc = GetProc(proc_id) if request.method == 'POST': form = StepForm(request.POST) if form.is_valid() and next_person['kod'] == GetUserKod(request) and proc['status'] == u'Выполняется': yesno = form.cleaned_data['yesno'] comment = form.cleaned_data['comment'] result = PointStep(proc_id,yesno,comment,next_person) SendNextPerson(request,proc_id) if result == 'OVER': ### -- Уведомление о завершении --- ProcOver(proc_id) proc = GetProc(proc_id) form = StepForm(None) author = proc['author_name'].split()[1]+u' '+proc['author_name'].split()[0] data = ListStepHistory(proc_id) c = RequestContext(request,{'form':form,'proc':proc_id,'status':proc['status'],'name':proc['proc_name'],'author':author,'nextperson':next_person,'data':data}) c.update(csrf(request)) return render_to_response("proc/procstep.html",c)
def SchemeEdit(request): try: if CheckAccess(request,'12') != 'OK': return render_to_response("scheme/notaccess/scheme.html") except: return HttpResponseRedirect('/') #del request.session['schemed'] ### --- Редактирование схемы --- try: scheme_id = request.GET['edit_id'] data = GetSchemeData(scheme_id) data['scheme_id'] = scheme_id request.session['schemed'] = pickle.dumps(data) return HttpResponseRedirect('/schemeedit') except: scheme = request.session['schemed'] data = pickle.loads(scheme) steps = data['stepdata'] if request.method == 'GET': try: delete_step = request.GET['delete_step'] data = DeleteStep(data,delete_step) request.session['schemed'] = pickle.dumps(data) except: pass ### --- Сохранение схемы --- try: edit = request.GET['edit'] scheme = request.session['schemed'] data = pickle.loads(scheme) if SaveScheme(data) == 'OK': return HttpResponseRedirect('/scheme') except: pass if request.method == 'POST': form = SchemeForm(request.POST) if form.is_valid(): name = form.cleaned_data['name'] data = pickle.loads(request.session['schemed']) data['name'] = name request.session['schemed'] = pickle.dumps(data) stepform = StepForm(request.POST) if stepform.is_valid(): step_number = stepform.cleaned_data['step_number'] step_name = stepform.cleaned_data['step_name'] user = stepform.cleaned_data['user'] action = stepform.cleaned_data['action'] step_yes = stepform.cleaned_data['step_yes'] step_no = stepform.cleaned_data['step_no'] function = stepform.cleaned_data['function'] data = pickle.loads(request.session['schemed']) if CheckStep(data,step_number): j = JsonUser(user) steps = data['stepdata'] steps.append({'step_number':step_number, 'step_name':step_name, 'user_id':j.j['user_id'], 'user_name':j.j['name2']+' '+j.j['name1'], 'user_email':j.j['email'], 'user_phone':j.j['phone_office'], 'action_kod':action, 'action_name':GetActionName(action), 'step_yes':step_yes, 'step_no':step_no, 'function':function }) data['stepdata'] = steps steps = sorted(steps) request.session['schemed'] = pickle.dumps(data) form = SchemeForm(None) stepform = StepForm(None) form.fields['name'].initial = data['name'] c = RequestContext(request,{'form':form,'stepform':stepform,'steps':steps}) c.update(csrf(request)) return render_to_response("scheme/schemeedit.html",c)