Commits

Wang Dingwei  committed 222222d

fixed rule editing issue

  • Participants
  • Parent commits 8168729

Comments (0)

Files changed (2)

         name = request.form['rule_name']
         desc = request.form['rule_desc']
         action = request.form['rule_action']
-        db.session.merge(Rule(name, desc, action))
+        this_rule = Rule.query.filter(Rule.name==name).filter(Rule.desc==desc).first()
+        if not this_rule:
+            db.session.add(Rule(name, desc, action))
+        else:
+            this_rule.action = action
         db.session.commit()
     rules = Rule.query.all()
     return render_template('rules.html', rules=rules)

File templates/rule.html

 <h2>Edit rule</h2>
 
 <form action="/rules/" method="POST">
-    <p>Name: <input type="text" readonly="readonly" name=rule_name value="{{
-    rule.name }}" disabled="disabled" /></p>
+    <p>Name: <input type="text" readonly="readonly" name="rule_name" value="{{
+    rule.name }}" /></p>
     Description:<br>
-    <textarea name="rule_desc" cols=40 rows=4 readonly="readonly"
-        disabled="disabled">{{ rule.desc }}</textarea><p>
+    <textarea name="rule_desc" cols=40 rows=4 readonly="readonly">{{ rule.desc }}</textarea><p>
     Action:<br>
     <textarea name="rule_action" cols=40 rows=4>{{ rule.action }}</textarea>
     <input type="submit" value="Submit">