I have a table which contains for loop and if tag using jinja this table shows some data but in last column I want round toggle button but I only get a checkbox, I am unable to find the error please help me.
<tbody>
{%for student in students%}
{%if user.staff.class_coordinator_of == student.division and user.staff.teacher_of_year == student.year%}
<tr>
<td style="color:white;">{{student.user.first_name}}</td>
<td style="color:white;">{{student.user.last_name}}</td>
<td style="color:white;">{{student.year}}</td>
<td style="color:white;">{{student.division}}</td>
<td style="color:white;">{{student.batch}}</td>
<td>
<label class="switch ">
<input type="checkbox" id="" value="" checked>
<span class="slider round"></span>
</label>
</td>
</tr>
{% endif %}
{%endfor%}
</tbody>
OUTPUT
Output Image
You should use radio button instead of checkbox so, it should be type="radio".
<input type="radio" id="" value="" checked>
Related
actually i have a table in the html and i want to know how i can get like tabe.rows.count on python in web2py
here is my code:
<table id="TablaMateriales" name="TablaMateriales" class=" table table-responsive order-list">
<thead>
<tr class="table-light">
<td>Item</td>
<td>Descripcion</td>
<td>Unidad</td>
<td>Cantidad</td>
<td>Proveedor</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="number" name="Item0" class="form-control" style="width:45px" value="1" disabled />
</td>
<td>
<input type="text" name="Unidad0" style="width:100px" class="form-control"/>
</td>
<td>
<input type="number" min="0" id="Cantidad0" name="Cantidad0" style="width:75px" value="0" class="form-control" onFocus="this.select()" onsubmit="if(this == ''){$this.val('0');}"/>
</td>
<td>
<input type="text" name="Proveedor0" style="width:250px" class="form-control"/>
</td>
</tr>
</tbody>
</table>
and code behind:
def crearCotizacion():
materialesT = request.vars.get('TablaMateriales')
rowsCount = materialesT.rows.count
return dict(rowsCount = rowsCount)
Thank you!
It seems like you are trying to access a client side element ('TablaMateriales') on the server side. You can only do that if you explicitly pass the element back to the server.
And then you would need to manipulate it using something like http://web2py.com/books/default/chapter/29/05/the-views#Server-side-DOM-and-parsing
You could just count the number of rows using JavaScript from inside the view: JavaScript to get rows count of a HTML table
Option 1 is selected automatically from HTML which is equal to 10.
This is the HTML:
<form>
<table>
<tr>
<th>Name:</th>
<td><input id="search_term" /></td>
</tr>
<tr>
<th>Page size:</th>
<td>
<select id="page_size">
<option>4</option>
<option selected>10</option>
<option>20</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" id="search" value="Search" />
</td>
</tr>
</table>
</form>
I tried running:
js = "document.getElementById('page_size').options[1].text ='1000';"
# js = "document.getElementById('page_size').options[1].text ='1000'"
driver.execute(js)
I get KeyError when i execute js. So I tried doing it the Python way, however, nothing happens:
x = driver.find_element_by_xpath('//*[#id="page_size"]/option[2]')
x.clear()
x.send_keys(1000)
this is link i am testing on link
1:'http://example.webscraping.com/places/default/search'
As you want to change the option elements text, I just tested this piece of javascript using jsfiddle and it works, try using "innerText" instead of "text":
document.getElementById('page_size').options[1].innerText = "1000";
Link to jsfiddle: https://jsfiddle.net/z1omaue3/
My form HTML source is below, I am trying to "check one of the checkboxes" and hit the "update" or submit button using mechanize. How would I go about this? Does the variable for linear_entitlements make it not possible?
<form accept-charset="UTF-8" action="/admin/users/3548003/user_linear_entitlements" class="form with-border" id="edit_user_3548003" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="put"><input name="authenticity_token" type="hidden" value="samplevalue"></div>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>GUID</th>
<th>CMS Subpack ID</th>
<th>Last Updated</th>
</tr>
</thead>
<tbody>
<tr id="linear_entitlement_1">
<td>
<div class="control-group">
<label class="checkbox">
<span>SUN Pack</span>
<input class="checkbox" id="user_linear_entitlement_ids_" name="user[linear_entitlement_ids][]" type="checkbox" value="1">
</label>
</div>
</td>
<td> 2a59739c-13ed-11e2-a36b-12313d298802 </td>
<td> 1 </td>
<td> 2014-02-12 21:32:56 UTC <div style="float:right">→</div></td>
</tr>
<tr id="linear_entitlement_7">
<td>
<div class="control-group">
<label class="checkbox">
<span>Tamil Pack - Legacy</span>
<input class="checkbox" id="user_linear_entitlement_ids_" name="user[linear_entitlement_ids][]" type="checkbox" value="7">
</label>
</div>
</td>
<td> 2ab298dc-13ed-11e2-a36b-12313d298802 </td>
<td> 3 </td>
<td> 2015-04-01 23:11:33 UTC <div style="float:right">→</div></td>
</tr>
</tbody>
</table>
<div class="form-actions">
<input class="btn primary input_submit" name="commit" type="submit" value="Update"> <button type="reset" class="btn">Cancel</button>
</div>
</form>
So far I have this, which selects the form:
htmlResponse2 = browser.open(URL + 'admin/users/' + old_user_url + '/edit')
browser.select_form(nr=0)
I don't know if you need to select the form, but if you did so, following should just do the trick:
br.find_control(type="checkbox").items[0].selected=True
if you want to select all checkboxes:
for i in range(0, len(br.find_control(type="checkbox").items)):
br.find_control(type="checkbox").items[i].selected =True
then submit
br.submit()
I've written a Python 3.2 script to select 10 random questions out of a list of 18, having extracted them from a SQLite 3 database. The script works fine, but I now want to render this using HTML - I know how to make question boxes in HTML, but not how to get the asked question to print, in the place of a "question 1" placeholder.
HTML code below:
def PrintGame():
print( """
<html>
<div id = "textbody">
<h2>Quiz</h2>
<form method="post" action="quiz.cgi">
<table border="0">
<tr>
<td>Question 1:</td>
<td><input type="text" name="A1"/></td>
</tr>
<tr>
<td>Question 2:</td>
<td><input type="text" name="A2"/></td>
</tr>
<tr>
<td>Question 3:</td>
<td><input type="text" name="A3"/></td>
</tr>
<tr>
<td>Question 4:</td>
<td><input type="text" name="A4"/></td>
</tr>
<tr>
<td>Question 5:</td>
<td><input type="text" name="A5"/></td>
</tr>
<tr>
<td>Question 6:</td>
<td><input type="text" name="A6"/></td>
</tr>
<tr>
<td>Question 7:</td>
<td><input type="text" name="A7"/></td>
</tr>
<tr>
<td>Question 8:</td>
<td><input type="text" name="A8"/></td>
</tr>
<tr>
<td>Question 9:</td>
<td><input type="text" name="A9"/></td>
</tr>
<tr>
<td>Question 10:</td>
<td><input type="text" name="A10"/></td>
</tr>
<tr>
<td><input type="submit" value="Submit Answers"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
""")
Just to clarify, I want to replace the "Question n"-type things with the questions pulled from the SQLite 3 database. The questions are loaded into QASKEDN variables (where N is replaced by the question number).
Sounds like you just want string formatting, but with a flexible format string/variable.
I haven't checked, but something like this perhaps?
def PrintGame():
htmlquestions = []
for question in QASKEDN:
htmlquestions.append("""
<tr>
<td>{} :</td>
<td><input type="text" name="A1"/></td>
</tr>""".format(question))
html = ("""
<html>
<div id = "textbody">
<h2>Quiz</h2>
<form method="post" action="quiz.cgi">
<table border="0">"""
+ "".join(htmlquestions) +
""" </table>
</form>
</div>
</body>
</html>
""")
Update: now with opening triple double quote for the last lines.
You might want to check out Jinja - a templating language for python.
In your case your Jinja template should look something like
template_string = """
<html>
...
{% for question, name in questions %}
<tr>
<td>{{question}}</td>
<td><input type="text" name="{{name}}"/></td>
</tr>
{% endfor %}
...
</html>
"""
Then you load the template string from your code and call the rendering function passing it your data (in this case a list of tuples containing the question and name)
question_list = [("Q1", "name1"), ("Q2", "name2"), ...]
template = Template(template_string)
template.render(questions=questions_list)
I am trying to create a table within a Google App Engine Application where the background color in a table changes periodically based on input. Does anyone know how to accomplish this?
Here is my code:
self.response.out.write("""
<img src="/images/resistor.png" width = "150">
<table border = "1">
<tr height="150" >
<td bgcolor="%s" width="35"> </td> <td bgcolor="%s" width="35"> </td> <td bgcolor="%s" width="35"> </td> <td bgcolor="%s" width="35"> </td> %(Red,Blue,Black,Green)
</tr>
</table>
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form> """)
self.response.out.write('</pre></body></html>')
For example the Red,Green... Colors in %( ) will be variables that will change so at one point they all may be Red or Blue and Yellow.
That type of string-formatting is deprecated. Please use the .format() method in new code. Example:
self.response.out.write("""
<img src="/images/resistor.png" width = "150">
<table border = "1">
<tr height="150" >
<td bgcolor="{}" width="35"> </td>
<td bgcolor="{}" width="35"> </td>
<td bgcolor="{}" width="35"> </td>
<td bgcolor="{}" width="35"> </td>
</tr>
</table>
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form> """.format( ('Red','Blue','Black','Green') ))
self.response.out.write('</pre></body></html>')
And for anything beyond the basic have a look at using templates. Examples of templating systems are Jinja2 and Django Templates.