def post_bot(id=0): incoming = request.get_json() print(incoming) new_rules = incoming["rules"] bot = Bot.query.get(id) if bot: bot.name = incoming["bot"]["name"] bot.prefix = incoming["bot"]["prefix"] bot.user_id = incoming["bot"]["userId"] bot.description = incoming["bot"]["description"] bot.is_draft = incoming["bot"]["isDraft"] for old_rule in bot.rules: db.session.delete(old_rule) for new_rule in new_rules: new_rule_content = json.dumps(new_rule["content"]) db.session.add(Rule(content=new_rule_content, bot_id=bot.id)) else: bot = Bot(name=incoming["bot"]["name"], prefix=incoming["bot"]["prefix"], user_id=incoming["bot"]["userId"], description=incoming["bot"]["description"], is_draft=incoming["bot"]["isDraft"]) db.session.add(bot) db.session.commit() print(bot) for new_rule in new_rules: new_rule_content = json.dumps(new_rule["content"]) db.session.add(Rule(content=new_rule_content, bot_id=bot.id)) db.session.commit() return jsonify(True)
def create_rule(term_id): ''' Add a rule to the database ''' check_admin() term = Term.query.filter(Term.id == term_id).first_or_404() form = RuleForm() if form.validate_on_submit(): rule = Rule() rule.name = form.name.data rule.identifier = form.identifier.data rule.description = form.description.data rule.notes = form.notes.data term.rules.append(rule) db.session.add(rule) db.session.commit() flash('You have successfully added the %s rule.' % rule.name) # Redirect to term page return redirect(url_for('main.show_term', selected_term=term.id)) # Load term template return render_template('admin/rules/rule.html', action="Add", form=form)
def add_rule(): form = AddRuleForm() if form.validate_on_submit(): reference = form.reference.data category = form.category.data fixedPayment = form.fixedPayment.data rule = Rule(reference=reference, category=category, fixedPayment=(fixedPayment == "True")) db.session.add(rule) db.session.commit() return redirect(url_for('list_records')) return render_template('home/addrule.html', form=form)
def test_check_rules_for_duplicate(self): u = User.query.get(1) # This one should match the FLUR rule above r_test1 = Rule(id=2, lat=47.6492247, lng=-122.34912, time=datetime(2018, 4, 20, 5, 55), user_id=1) # This one should not match because the location does not match either rule r_test2 = Rule(id=3, lat=47.6492247, lng=-112.32724, time=datetime(2018, 4, 20, 5, 55), user_id=1) # This one should not match because the time doesn't match either rule r_test3 = Rule(id=4, lat=47.6492247, lng=-122.34912, time=datetime(2018, 4, 20, 7, 55), user_id=1) self.assertTrue(u.check_rules_for_duplicate(r_test1)) self.assertFalse(u.check_rules_for_duplicate(r_test2)) self.assertFalse(u.check_rules_for_duplicate(r_test3))
def create_rule(): request_dict = RuleSchema.validate_request() rule = Rule() new_rule = rule.create(request_dict, commit=False) action_ids = request.get_json().get('actions') if not isinstance(action_ids, list): raise FormInvalid(field='actions') actions = Action.query \ .filter(Action.id.in_(action_ids)) \ .many() for action in actions: new_rule.actions.append(action) rule_json = get_rule_json(new_rule) url = f"{current_app.config.get('STREAM_RULE_URL')}/" stream_rule_http('post', url=url, json=rule_json) db.session.commit() record = new_rule.to_dict() return jsonify(record), 201
def post(self): ''' 添加 ''' args = parse_base.parse_args() name = args.get('name') url = args.get('url') menu_id = args.get('menu_id') method = args.get('method') # 权限规则名称可以重复,但是URL&请求方法不能重复 _data = Rule.query.filter_by(url=url, method=method, is_del='0').first() if _data: abort(RET.Forbidden, msg='权限规则已存在') model_data = Rule() model_data.name = name model_data.url = url model_data.menu_id = menu_id model_data.method = method model_data.last_editor = g.admin.username if model_data.add(): data = {'status': RET.Created, 'msg': '添加成功', 'data': model_data} return marshal(data, sing_fields) abort(RET.BadRequest, msg='添加失败,请重试')
name="fakebot6", prefix="%", description="The fifth fake bot ever here", is_draft=False) bot7 = Bot(user_id=1, name="fakebot7", prefix="%", description="The fifth fake bot ever here", is_draft=False) bot8 = Bot(user_id=1, name="fakebot8", prefix="%", description="The fifth fake bot ever here", is_draft=False) rule1 = Rule(bot_id=1, content=ruleString1) rule2 = Rule(bot_id=2, content=ruleString2) rule3 = Rule(bot_id=1, content=ruleString3) rule4 = Rule(bot_id=4, content=ruleString5) rule5 = Rule(bot_id=4, content=ruleString6) rule6 = Rule(bot_id=6, content=ruleString6) rule7 = Rule(bot_id=1, content=ruleString7) db.session.add(user1) db.session.add(user2) db.session.add(user3) db.session.add(user4) db.session.add(bot1) db.session.add(bot2) db.session.add(bot3) db.session.add(bot4)
db.session.commit() # Create Table and Columns l = Location(name='PROD_DB', description='/data/prod/risk_mart'); t = Table(name='ACCOUNT_HISTORY', location=l) c1 = Column(name='DATE_KEY', type='NUM', length='8', format='DATE9.', table=t) c2 = Column(name='ACCOUNT_ID', type='NUM', length='8', format='21.', table=t) c3 = Column(name='APPLICATION_ID', type='NUM', length='8', format='3.', table=t) c4 = Column(name='BALANCE_AMT', type='NUM', length='8', format='20.', table=t) db.session.add(l) db.session.add(t) db.session.add(c1) db.session.add(c2) db.session.add(c3) db.session.add(c4) # Create Business Rule t = Term.query.filter_by(id=1).first() r = Rule(identifier='BR_001', name='New Customer Rule', description='This is a new customer rule', notes='Detailed description of the rule. Typically written in structured English or pseudo code. Consider using a flowchart or UML activity diagram to depict procedural logic.') t.rules.append(r) db.session.add(r) print("Rule", r.identifier, "created") db.session.commit()