如何在Python中动态添加If-Else语句?
目前,我已经开发了一个脚本,可以阅读收到的/最新的电子邮件,并根据某些标准(如电子邮件主题和文本)过滤电子邮件。当用户选择如何在Python中动态添加If-Else语句?,python,django,Python,Django,目前,我已经开发了一个脚本,可以阅读收到的/最新的电子邮件,并根据某些标准(如电子邮件主题和文本)过滤电子邮件。当用户选择主题或文本时,他们可以选择要过滤电子邮件的条件(等于、不包含等) 我的问题 我有一个演示网站,可以让用户添加不同的条件来过滤电子邮件。但是现在我的脚本一次只能处理一个条件并执行。如何使我的脚本检测到存在多个条件并根据多个规则过滤电子邮件我正在使用Django创建我的网站 <!DOCTYPE html> <html lang="en">
主题
或文本
时,他们可以选择要过滤电子邮件的条件(等于、不包含等)
我的问题
我有一个演示网站,可以让用户添加不同的条件来过滤电子邮件。但是现在我的脚本一次只能处理一个条件并执行。如何使我的脚本检测到存在多个条件并根据多个规则过滤电子邮件我正在使用Django创建我的网站
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Quicksand:300,500" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
.buttonSubmit{
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
body {font-family: 'Quicksand', sans-serif;}
.button {
border-radius: 50px;
background-color: #ff9633;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 15px;
padding: 10px;
width: 80px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
margin-left:500px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 45%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* Add Animation */
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
@keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-header {
padding: 2px 16px;
background-color: #ff9633;
color: white;
}
.modal-body {padding: 2px 16px;}
.modal-footer {
padding: 2px 16px;
background-color: #ff9633;
color: white;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #ff9633;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color:
#fa7d34;
}
</style>
</head>
<body>
<ul>
<li>
<div id="myBtn1"><a href="#AddCon">Alert Policies</a></div>
</li>
<li><a href="#contact">Test3</a></li>
<li><a href="#about">Test4</a></li>
</ul>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Alert Policies</h2>
</div>
<div class="modal-body">
<p style="font-size:14px">Please select an event parameter as well as the condition type and value that
apply.</p>
<!-- parameter drop down -->
<form method="post">
<label for="Parameter"> <b style="font-size:13px"> Event parameter to evaluate </b></label>
<select name="Parameter" id="Parameter" style="width:340px; font-family: 'Quicksand', sans-serif;">
<option disabled selected value>select a parameter</option>
<option value="Subject">Subject</option>
<option value="Text">Text</option>
</select>
<br><br>
<label for="Condition"> <b style="font-size:13px"> Type of condition </b></label>
<select name="Condition" id="Condition"
style="width:340px; margin-left:69px; font-family: 'Quicksand', sans-serif;">
<option disabled selected value>select a condition</option>
<option value="Equals">Equals</option>
<option value="Contain">Contain</option>
<option value="NotContain">Does not contain</option>
</select>
<br><br>
<label for="valuetomatch"> <b style="font-size:13px"> Value to match</b></label>
<input type="text" id="valuetomatch" name="valuetomatch"
style="width:333px; margin-left:80px; font-family: 'Quicksand', sans-serif;">
<br>
<br>
</form>
<button class="button"><span>OK</span></button>
</div>
</div>
</div>
<table id="myTable">
<tr>
<th>Event Parameter</th>
<th>Condition</th>
<th>Value to match</th>
<th>Action</th>
</tr>
</table>
<br>
<a href="#" class="buttonSubmit">Submit</a>
<script>
//add tablebox
$(document).ready(function(){
$(".button").on('click', function () {
para = document.getElementById("Parameter").value;
condi = document.getElementById("Condition").value;
value2match = document.getElementById("valuetomatch").value;
if (para && condi && value2match !== null) {
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
cell1.innerHTML = document.getElementById("Parameter").value;
cell2.innerHTML = document.getElementById("Condition").value;
cell3.innerHTML = document.getElementById("valuetomatch").value;
cell4.innerHTML = '<button class = "del_img "onClick="delSpec(this)">Delete</button> </div>';
//close the modal
modal.style.display = "none";
}else
{
alert("All the input box cannot be empty!");
}
});
});
function delSpec(node)
{
r=node.parentNode.parentNode;
r.parentNode.removeChild(r);
}
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn1");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
我以前的脚本:
用户单击OK
后,将直接执行view.py
中的脚本,它将仅根据当前条件解析电子邮件
我试图实现的目标:
我已经修改了我的html模板,它将继续让用户添加几个条件,而不是只执行一个条件。示例:当用户选择参数etc并单击OK
时,将存储新行,脚本将根据用户希望解析的规则数解析电子邮件。(单击submit
后,仅当满足所有规则时才会触发脚本)
预期输出(基于上图)
能够使用这两个规则解析传入电子邮件的系统电子邮件主题必须等于test,并且文本必须包含text contain
可能的解决方案
当出现新规则时,它是否能够动态添加If-Else语句?然后计数直到规则的最后一行,然后执行
我的py脚本(此代码是以前的版本,当用户单击“确定”时只能执行一次)
我当前的Html模板
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Quicksand:300,500" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
.buttonSubmit{
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
body {font-family: 'Quicksand', sans-serif;}
.button {
border-radius: 50px;
background-color: #ff9633;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 15px;
padding: 10px;
width: 80px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
margin-left:500px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 45%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* Add Animation */
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
@keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-header {
padding: 2px 16px;
background-color: #ff9633;
color: white;
}
.modal-body {padding: 2px 16px;}
.modal-footer {
padding: 2px 16px;
background-color: #ff9633;
color: white;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #ff9633;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color:
#fa7d34;
}
</style>
</head>
<body>
<ul>
<li>
<div id="myBtn1"><a href="#AddCon">Alert Policies</a></div>
</li>
<li><a href="#contact">Test3</a></li>
<li><a href="#about">Test4</a></li>
</ul>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Alert Policies</h2>
</div>
<div class="modal-body">
<p style="font-size:14px">Please select an event parameter as well as the condition type and value that
apply.</p>
<!-- parameter drop down -->
<form method="post">
<label for="Parameter"> <b style="font-size:13px"> Event parameter to evaluate </b></label>
<select name="Parameter" id="Parameter" style="width:340px; font-family: 'Quicksand', sans-serif;">
<option disabled selected value>select a parameter</option>
<option value="Subject">Subject</option>
<option value="Text">Text</option>
</select>
<br><br>
<label for="Condition"> <b style="font-size:13px"> Type of condition </b></label>
<select name="Condition" id="Condition"
style="width:340px; margin-left:69px; font-family: 'Quicksand', sans-serif;">
<option disabled selected value>select a condition</option>
<option value="Equals">Equals</option>
<option value="Contain">Contain</option>
<option value="NotContain">Does not contain</option>
</select>
<br><br>
<label for="valuetomatch"> <b style="font-size:13px"> Value to match</b></label>
<input type="text" id="valuetomatch" name="valuetomatch"
style="width:333px; margin-left:80px; font-family: 'Quicksand', sans-serif;">
<br>
<br>
</form>
<button class="button"><span>OK</span></button>
</div>
</div>
</div>
<table id="myTable">
<tr>
<th>Event Parameter</th>
<th>Condition</th>
<th>Value to match</th>
<th>Action</th>
</tr>
</table>
<br>
<a href="#" class="buttonSubmit">Submit</a>
<script>
//add tablebox
$(document).ready(function(){
$(".button").on('click', function () {
para = document.getElementById("Parameter").value;
condi = document.getElementById("Condition").value;
value2match = document.getElementById("valuetomatch").value;
if (para && condi && value2match !== null) {
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
cell1.innerHTML = document.getElementById("Parameter").value;
cell2.innerHTML = document.getElementById("Condition").value;
cell3.innerHTML = document.getElementById("valuetomatch").value;
cell4.innerHTML = '<button class = "del_img "onClick="delSpec(this)">Delete</button> </div>';
//close the modal
modal.style.display = "none";
}else
{
alert("All the input box cannot be empty!");
}
});
});
function delSpec(node)
{
r=node.parentNode.parentNode;
r.parentNode.removeChild(r);
}
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn1");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
.按钮提交{
背景色:#4CAF50;
边界:无;
颜色:白色;
填充:15px 32px;
文本对齐:居中;
文字装饰:无;
显示:内联块;
字体大小:16px;
利润:4倍2倍;
光标:指针;
}
桌子{
字体系列:arial,无衬线;
边界塌陷:塌陷;
宽度:100%;
}
td,th{
边框:1px实心#dddddd;
文本对齐:左对齐;
填充:8px;
}
tr:n个孩子(偶数){
背景色:#dddddd;
}
正文{字体系列:“流沙”,无衬线;}
.按钮{
边界半径:50px;
背景色:#ff9633;
边界:无;
颜色:#FFFFFF;
文本对齐:居中;
字体大小:15px;
填充:10px;
宽度:80px;
过渡:均为0.5s;
光标:指针;
保证金:5px;
左边距:500px;
}
.按钮跨度{
光标:指针;
显示:内联块;
位置:相对位置;
过渡:0.5s;
}
.按钮跨度:之后{
内容:'\00bb';
位置:绝对位置;
不透明度:0;
排名:0;
右:-20px;
过渡:0.5s;
}
.按钮:悬停范围{
右边填充:25px;
}
.按钮:悬停范围:之后{
不透明度:1;
右:0;
}
/*模态(背景)*/
.莫代尔{
显示:无;/*默认情况下隐藏*/
位置:固定;/*保持原位*/
z指数:1;/*位于顶部*/
填充顶部:100px;/*框的位置*/
左:0;
排名:0;
宽度:100%;/*全宽*/
高度:100%;/*全高*/
溢出:自动;/*根据需要启用滚动*/
背景色:rgb(0,0,0);/*回退色*/
背景色:rgba(0,0,0,0.4);/*黑色w/不透明度*/
}
/*模态内容*/
.模态内容{
位置:相对位置;
背景色:#fefe;
保证金:自动;
填充:0;
边框:1px实心#888;
宽度:45%;
盒影:0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit动画名称:animatetop;
-webkit动画持续时间:0.4s;
动画名称:animatetop;
动画持续时间:0.4s
}
/*添加动画*/
@-webkit关键帧动画顶点{
从{top:-300px;不透明度:0}
到{顶部:0;不透明度:1}
}
@关键帧动画顶点{
从{top:-300px;不透明度:0}
到{顶部:0;不透明度:1}
}
/*关闭按钮*/
.结束{
颜色:白色;
浮动:对;
字号:28px;
字体大小:粗体;
}
.关闭:悬停,
.结束:聚焦{
颜色:#000;
文字装饰:无;
光标:指针;
}
.模态标题{
填充:2x16px;
背景色:#ff9633;
颜色:白色;
}
.模态体{填充:2px 16px;}
.模态页脚{
填充:2x16px;
背景色:#ff9633;
颜色:白色;
}
保险商实验室{
列表样式类型:无;
保证金:0;
填充:0;
溢出:隐藏;
背景色:#ff9633;
}
李{
浮动:左;
}
李阿{
显示:块;
颜色:白色;
文本对齐:居中;
填充:14px 16px;
文字装饰:无;
}
李娜:停下来{
背景色:
#fa7d34;
}
-
&时代;
警报策略
请选择一个事件参数以及需要的条件类型和值
申请
要评估的事件参数
选择一个参数
主题
正文
条件类型
选择一个条件
等于
包含
不包含
要匹配的值
好啊
事件参数
条件
要匹配的值
行动
//添加桌面框
$(文档).ready(函数(){
$(“.button”)。在('click',函数(){
para=document.getElementById(“参数”).value;
condi=document.getElementById(“条件”).value;
value2match=docume
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Quicksand:300,500" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
.buttonSubmit{
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
body {font-family: 'Quicksand', sans-serif;}
.button {
border-radius: 50px;
background-color: #ff9633;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 15px;
padding: 10px;
width: 80px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
margin-left:500px;
}
.button span {
cursor: pointer;
display: inline-block;
position: relative;
transition: 0.5s;
}
.button span:after {
content: '\00bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.button:hover span {
padding-right: 25px;
}
.button:hover span:after {
opacity: 1;
right: 0;
}
/* The Modal (background) */
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
/* Modal Content */
.modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
width: 45%;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s
}
/* Add Animation */
@-webkit-keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
@keyframes animatetop {
from {top:-300px; opacity:0}
to {top:0; opacity:1}
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
.modal-header {
padding: 2px 16px;
background-color: #ff9633;
color: white;
}
.modal-body {padding: 2px 16px;}
.modal-footer {
padding: 2px 16px;
background-color: #ff9633;
color: white;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #ff9633;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color:
#fa7d34;
}
</style>
</head>
<body>
<ul>
<li>
<div id="myBtn1"><a href="#AddCon">Alert Policies</a></div>
</li>
<li><a href="#contact">Test3</a></li>
<li><a href="#about">Test4</a></li>
</ul>
<!-- The Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Alert Policies</h2>
</div>
<div class="modal-body">
<p style="font-size:14px">Please select an event parameter as well as the condition type and value that
apply.</p>
<!-- parameter drop down -->
<form method="post">
<label for="Parameter"> <b style="font-size:13px"> Event parameter to evaluate </b></label>
<select name="Parameter" id="Parameter" style="width:340px; font-family: 'Quicksand', sans-serif;">
<option disabled selected value>select a parameter</option>
<option value="Subject">Subject</option>
<option value="Text">Text</option>
</select>
<br><br>
<label for="Condition"> <b style="font-size:13px"> Type of condition </b></label>
<select name="Condition" id="Condition"
style="width:340px; margin-left:69px; font-family: 'Quicksand', sans-serif;">
<option disabled selected value>select a condition</option>
<option value="Equals">Equals</option>
<option value="Contain">Contain</option>
<option value="NotContain">Does not contain</option>
</select>
<br><br>
<label for="valuetomatch"> <b style="font-size:13px"> Value to match</b></label>
<input type="text" id="valuetomatch" name="valuetomatch"
style="width:333px; margin-left:80px; font-family: 'Quicksand', sans-serif;">
<br>
<br>
</form>
<button class="button"><span>OK</span></button>
</div>
</div>
</div>
<table id="myTable">
<tr>
<th>Event Parameter</th>
<th>Condition</th>
<th>Value to match</th>
<th>Action</th>
</tr>
</table>
<br>
<a href="#" class="buttonSubmit">Submit</a>
<script>
//add tablebox
$(document).ready(function(){
$(".button").on('click', function () {
para = document.getElementById("Parameter").value;
condi = document.getElementById("Condition").value;
value2match = document.getElementById("valuetomatch").value;
if (para && condi && value2match !== null) {
var table = document.getElementById("myTable");
var row = table.insertRow(-1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
cell1.innerHTML = document.getElementById("Parameter").value;
cell2.innerHTML = document.getElementById("Condition").value;
cell3.innerHTML = document.getElementById("valuetomatch").value;
cell4.innerHTML = '<button class = "del_img "onClick="delSpec(this)">Delete</button> </div>';
//close the modal
modal.style.display = "none";
}else
{
alert("All the input box cannot be empty!");
}
});
});
function delSpec(node)
{
r=node.parentNode.parentNode;
r.parentNode.removeChild(r);
}
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn1");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>
con = {
"Equals": "==",
"Contain": "in",
"NotContain": "not in"
}
#Get all value from
ParameterGet = str(request.POST.get('Parameter', None))
ConditionGet = str(request.POST.get('Condition', None))
valuetomatch = str(request.POST["valuetomatch"])
con = {
"Equals": "==",
"Contain": "in",
"NotContain": "not in"
}
for each_row in rows:
***your other logic goes here***
ParameterGet = str(request.POST.get('Parameter', None))
ConditionGet = str(request.POST.get('Condition', None))
valuetomatch = str(request.POST["valuetomatch"])
text = "body.decode('utf-8').rstrip()"
current_condition = "(valuetomatch "+ con[ConditionGet] + " " + ParameterGet.lower() + ")"
if eval(current_condition):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(EMAIL_ACCOUNT, PASSWORD)
msg = "subject not contain!"
server.sendmail(EMAIL_ACCOUNT, "xxx@gmail.com", msg)
server.quit()
else:
print("no email");
>>> con = {
"Equals": "==",
"Contain": "in",
"NotContain": "not in"
}
>>> valuetomatch = "hi"
>>> ConditionGet = "Contain"
>>> ParameterGet = "Subject"
>>> subject = "hi"
>>> current_condition = "(valuetomatch "+ con[ConditionGet] + " " + ParameterGet.lower() + ")"
>>> current_condition
'(valuetomatch in subject)'
>>> eval(current_condition)
True