pass list of values from html button to python scripts - python

i have a html template like:
<button id="demo-btn-" >Pack</button>
<table class="table table-striped">
<thead>
<tr>
<th><input type="checkbox" onClick="toggle(this, 'no')"></th>
<th>Invoice</th>
<th>User</th>
<th>Order date</th>
<th>Amount</th>
<th>Status</th>
<th>Tracking Number</th>
</tr>
</thead>
<tbody>
{% for oid,dbd,stts,tp in new_orders %}
<tr>
<td><input type="checkbox" name="no" value="{{oid}}"></td>
<td><a class="btn-link" href="#">{{oid}}</a></td>
<td>Steve N. Horton</td>
<td><span class="text-muted"><i class="fa fa-clock-o"></i>{{dbd}} </span></td>
<td>{{tp}}</td>
<td>{{stts}}</td>
<td>-</td>
</tr>
{% endfor %}
</tbody>
</table>
when i select the checkbox in <thead> all the checkboxes in <tbody> are selected. Now i want, when i select the checkbox and press the pack button, the oid value for each row should be passed to a django view. How to do that?
EDIT:
I want to pass multiple oids as a list to python script. I can do that if i can pass these as a list to django app's views file. I dont know how to pass a list or a value to a django application.

Related

Check if a button is triggered by clicking enter key using selenium in python

How to check if a button element is triggered by clicking enter using selenium? For example I'm testing the following table which has buttons in it
<table>
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">row1</th>
<td>
<button class="btn btn-primary">action 1</button>
</td>
<td>
<button class="btn btn-secondary">action 2</button>
</td>
</tr>
<tr>
<th scope="row">row2</th>
<td><button class="btn hover btn-primary">action 1</button></td>
<td><button class="btn hover btn-secondary">action 2</button></td>
</tr>
</tbody>
</table>
I want to know if these buttons are triggered on clicking enter.

HTML Table - Iterate over multiple Lists and Create a Table

I have 3 lists of data that i would like to print out as a Table in HTML.
Lists
ipaddress [10.1.1.0,10.1.1.1,10.1.1.2,10.1.1.3]
State [Full,Full,Full,Full]
Interface [ge0,ge1,ge2,ge3]
ID [ 0,1,2,3]
I would like to Print above rows as a table under Table Column as rows.
Table Header
Address Interface State ID
I cant seem to figure out the proper for loops logic to print this as a table, here is what i have currently.
{%extends "home/layout.html"%}
{% block body%}
<h1 style="text-align:center;">Here is the Inventory </h1>
<li> {{ospfneighboraddress}}</li>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Address</th>
<th scope="col">Interface</th>
<th scope="col">State</th>
<th scope="col">ID</th>
</tr>
</thead>
<tbody>
{% for ospfaddress in ospfneighboraddress %}
<tr>
<td>{{ ospfaddress }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{%endblock%}
ospfneighboraddress is the first IP address list, rest are also lists
Here are other list names:
ospfneighborinterface
ospfneighborstate
ospfneighborID
How do print next three lists for each IP address ?
Here you go!
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table border="1">
<tr>
<th>Address</th>
<th>Interface</th>
<th>State</th>
<th>ID</th>
</tr>
<tr>
<td>10.1.1.0</td>
<td>ge0</td>
<td>Full</td>
<td>0</td>
</tr>
<tr>
<td>10.1.1.1</td>
<td>ge1</td>
<td>Full</td>
<td>1</td>
</tr>
<tr>
<td>10.1.1.2</td>
<td>ge2</td>
<td>Full</td>
<td>2</td>
</tr>
<tr>
<td>10.1.1.3</td>
<td>ge3</td>
<td>Full</td>
<td>3</td>
</tr>
</table>
</body>
</html>

Django: How to add html tag from string to the html template

Details:
Client framwork: Django
Web server: Python + Flask
I have an HTML page which rendered with a data array.
Each item in the array contains some fields. And one of the fields is a json object.
In order to improve the visibility of the json i've converted the json obj to html table.
Currently it's does't work.
The results (on the browser) looks like that:
PasswordPolicy <table border="1"><tr><th>MinimumPasswordLength</th><td>16</td></tr><tr><th>RequireSymbols</th><td>True</td></tr><tr><th>Re
Flask code:
#app.route("/PasswordPolicy", methods=["GET"])
#login_required
def get_password_policy():
get_table_content = list(db_object.get_password_policy())
search_event = request.args.get('searchquery')
at_type = request.args.get('audittype')
print("**************")
for e in get_table_content:
print("Before:")
print(e['PasswordPolicy'])
e['PasswordPolicy'] = json2html.convert(json = e['PasswordPolicy'])
print("After:")
print(e['PasswordPolicy'])
print("get_table_content:")
print(get_table_content[0])
print("**************")
return render_template(
'soc2/password_policy.html',
get_list=get_table_content
)
Html content:
<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr class="headings">
<th class="column-title">BusinessUnit </th>
<th class="column-title">ControllerNumber </th>
<th class="column-title">PasswordPolicy </th>
</tr>
</thead>
<tbody>
{% for elements in get_list %}
<tr class="even pointer">
<td>
{{ elements["BusinessUnit"] }}
</td>
<td>
{{ elements["ControllerNumber"] }}
</td>
<td>
{{ elements["PasswordPolicy"] }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
The question is how to tell to the browser to parse the table as html instead of simple string
You can use safe like so: {{ your_html_string | safe }}

Python Flask collapsible/expandable dynamic table

I am building a table in flask with rows that are collapsible. A row may have several elements underneath it that will all collapse on clicking. It works fine if I just hardcode values but when I am populating the table using a loop with data from a python dictionary, it does not work. The first row's first child collapses instead of all the correct row's children collapsing. Below should be sufficient code to reproduce the issue.
elements is a dictionary where key is a string and value is a list of tuples.
<table>
<thead>
<tr>
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
</tr>
</thead>
{%for k, v in elements.items()%}
<tbody>
<tbody class="labels">
<tr>
<td colspan="5">
<label for="i">{{k}}</label>
<input type="checkbox" name="i" id="i" data-toggle="toggle">
</td>
</tr>
</tbody>
{%for desc in v%}
<tbody class="hide">
<tr>
<td>{{desc[0]}}</td>
<td>{{desc[1]}}</td>
<td>{{desc[2]}}</td>
<td>
<button>trigger</button>
</td>
<td>{{desc[3]}}</td>
</tr>
</tbody>
{% endfor %}
</tbody>
{% endfor %}
<script>
$(document).ready(function() {
$('[data-toggle="toggle"]').change(function(){
$(this).parents().next('.hide').toggle();
});
});
</script>
<label for="i">{{k}}</label>
<input type="checkbox" name="i" id="i" data-toggle="toggle">
Accidentally wasn't changing the for, name, id fields.
Needed to update those as variables as well so looks like
<label for={{k}}>{{k}}</label>
<input type="checkbox" name={{k}} id={{k}} data-toggle="toggle">

How to transfer data from tables to web forms?

I have a table that displays information through a list of dictionaries.
This is the program :
<div class = "col-md-8" >
<table class="table table-bordered table-striped table-hover">
<thead> <!-- En-tĂȘte du tableau -->
<tr>
<th> Host Name </th>
<th> Hardware </th>
<th> Fixed-Address </th>
<th> Comment </th>
<tr>
</thead>
<tbody> <!-- Corps du tableau -->
{% for item in items %}
<tr id="confirm">
{% for key in [ 'host','hardware','fixed_address','comment' ] %}
<td> {{ item[key].decode('utf-8') }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
What I would like to do is to be able to modify it or add a new entry, that's not what I am going to ask here because before that I need to do the following:
Basically, I need to make every row act as a link, when I click on it (the row) I should be redirected to a web page with web forms and those web forms will be filled with the data from the table cells.
How can I do it? Thanks beforehand.
Do something like this.
<thead> <!-- En-tĂȘte du tableau -->
<tr>
<th> Host Name </th>
<th> Hardware </th>
<th> Fixed-Address </th>
<th> Comment </th>
<th> View </th>
<tr>
</thead>
<tbody> <!-- Corps du tableau -->
{% for item in items %}
<tr id="confirm">
{% for key in [ 'host','hardware','fixed_address','comment' ] %}
<td> {{ item[key].decode('utf-8') }}</td>
{% endfor %}
View
</tr>
{% endfor %}
</tbody>
</table>
</div>
That function inside url_for should be the function which displays data and should renders page for displaying data.

Categories