Why not take the data from the inserted in flask? - python

I am trying to insert several data in one table to another but it is not taking the data from the HTML, I have tried several ways, I also tried to take the number as a variable and insert it directly but it did not work.
This is what I am trying to do, that 2 tables bring me a value and insert them in a table called quantity, which has 2 ids and only 3 fields, where is the id, the count and the id of the product but when I try Insert the data, the page only reloads.
Python
if request.method == 'POST':
try:
dcont = request.form['dcont']
ids = request.form['ids']
cn = request.form['cn']
with sql.connect("DRIVER={SQL Server}; SERVER=AUS_COMPUTO02\SQLEXPRESS; DATABASE=WEBSERVICE; Trusted_Connection = yes;") as con:
cur = con.cursor()
cur = con.execute("INSERT INTO dbo.DETALLECONTEO VALUES (?,?,?)", (dcont,ids,cn))
cur.commit()
msg = "Successfully added"
print(cur)
print(dcont,ids,cn)
except:
con.rollback()
msg = "error inserte la operacion nuevamente"
finally:
# con.close()
return render_template ('result.html')
return render_template('new.html', prov=prov, cnt=cnt, ind=ind )
HTML
<div class="jumbotron">
<div class="form-group">
<form class="form-inline my-2 my-lg-0" action="{{ url_for('new') }}" class="form-control" class="w-auto p-3">
<select name='prove' class="form-control mr-sm-2" aria-label="Search" >
<option value="0"> Selecione su Proveedor </option>
<br action="{{ url_for('new') }}" method='POST'>
{% for p in prov %}
<option value="{{ p.ID }}" > {{ p.DESCRIPCION }} </option>
{% endfor %}
</select>
<button class="btn btn-outline-success my-2 my-sm-0" type="submit" >Seclet</button>
</form>
</div>
<div class="form-group">
<form class="form-inline my-lg-0" action="{{ url_for('adt') }}" method='POST'>
<table class="table" class="form-control">
<thead>
<tr>
<th scope="col">Codigo</th>
<th scope="col">Descipcion</th>
<th acope="col">Cantidad</th>
</tr>
</thead>
<tbody>
{% for c in cnt %}
<tr>
<td >{{ c.codigo }}</td>
<td>{{ c.descripcion }}</td>
<td > <input name='cn' id='cn' type="number" class="form-control"></td>
<td><select name='dcont' id='dcont'>
{% for i in ind %}
<option value=" {{i.Conteo}}"> {{i.Conteo}} </option>
{% endfor %}
</select>
</td>
<td> <select name='ids' id='ids'>
<option value="{{c.id}}"> {{c.id}} </option>
</select>
</td>
{% endfor %}
</tr>
</tbody>
</table>
</tbody>
</table>
<input class="btn btn-outline-success my-2 my-sm-0" type="submit" ><br>
</form>
</div>
</div>

Two main areas to focus on-- first your form hasn't been told to 'POST' the data-- go it's going to send it via the default 'GET' mode, changing your form code, by adding method="post" will resolve that issue.
<form class="form-inline my-2 my-lg-0" method="post" action="{{ url_for('new') }}" class="form-control" class="w-auto p-3">
So now your form data will get POST'ed-- and so will trigger the if request.method == 'POST': logic.
Your next issue is your data is coming in as the same named element-- e.g. if you submitted three entries, your ids element would post:
ids=3
ids=2
ids=6
So we need to use the request.form.getlist('ids') to get that data, so you end up with a list of entries for the form elements:
all_ids = request.form.getlist('ids')
all_cn = request.form.getlist('cn')
all_dcont = request.form.getlist('dcont')
Now if we looked at that data that might be submitted:
>>> print(all_ids)
['3','2','6']
>>> print(all_dcont)
['A','B','C']
>>> print(all_cn)
['X','Y','Z']
But we need to handle them as rows-- to insert into our database, so we can zip them together to make 'rows' of the data:
rows = zip(all_ids, all_dcont, all_cn)
So now we have:
>>> print(rows)
['3','A','X'], ['2','B','Y'], ['6','C','Z']
Which we can iterate through (theres a number of ways to do this, we'll keep it simple) to create out SQL statements to execute:
for entry in rows:
query_ids = entry[0]
query_dcont = entry[1]
query_cn = entry[2]
...
cur = con.execute("INSERT INTO dbo.DETALLECONTEO VALUES (?,?,?)", (query_dcont,query_ids,query_cn))
...

Related

How can I find the data which written with for loop in Flask

I'm trying to make a database project using with MYSQL and I'm new in Flask. In this project, the user should be able to increase and decrease the number of the products in the database. I print the items in my product table with for loop. The problem is I couldn't select the item which the user selected.
Html:
{% for mydata in data %}
<div class="items filterDiv {{ mydata[1] }}">
<img src="../static/foto/atayumurta.png" alt="">
<br><br>
<label for="item"> {{ mydata[3] }}</label>
<br><br>
<label class="Number">Number: <input class="numb" min="1" name="number" type="number"></label>
<br><br>
<input class="addbutton" type="submit" name="submit_button" value="Add">
<input class="removebutton" type="submit" name="removebutton" value="Remove">
</div>
{% endfor %}
Flask:
#app.route('/mainpage', methods=['POST','GET'])
def mainpage():
cursor.execute("SELECT * FROM product")
fetchdata = cursor.fetchall()
if request.method == 'POST':
if request.form['submit_button'] == 'Add':
number = request.form.get("number")
print(number)
return render_template('main.html', data=fetchdata)
else:
return render_template('main.html', data = fetchdata)
First, I wanted to see the number that the user has selected. So tried to print it but it prints null. As I said im new in flask, open for your suggestions.
Actually, the template contains a for loop for data.
In other words, the number field is not unique. So you need to modify the code. For example
{% for i in range(len(data)) %}
<div class="items filterDiv {{ data[i][1] }}">
<img src="../static/foto/atayumurta.png" alt="">
<br><br>
<label for="item"> {{ data[i][3] }}</label>
<br><br>
<label class="Number">Number: <input class="numb" min="1" name="number{{i}}" type="number"></label>
<br><br>
<input class="addbutton" type="submit" name="submit_button" value="Add">
<input class="removebutton" type="submit" name="removebutton" value="Remove">
</div>
{% endfor %}
Flask:
#app.route('/mainpage', methods=['POST','GET'])
def mainpage():
cursor.execute("SELECT * FROM product")
fetchdata = cursor.fetchall()
if request.method == 'POST':
if request.form['submit_button'] == 'Add':
number = request.form.get("number1")
print(number1)
return render_template('main.html', data=fetchdata)
else:
return render_template('main.html', data = fetchdata)

request.form returns only first value when converting to dictionary

I have the following HTML form:
<form method="POST" action="/dashboard/account/assignkpibulk">
<div class="modal-body form-group">
Select from the <b>dropdown</b> the KPI to be assign to each campaign,
then click <b>"Assign KPI´s"</b> to complete the assigment. If you want to assign a KPI to only one
campaign click on <b>Assign KPI</b>
</div>
<div class="container">
<div class="card-body">
<div class="table-responsive">
<table class="table" id="modalKpiTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Campaign Name</th>
<th>Campaign ID</th>
<th>KPI Name</th>
<th class="text-center">Assigment Actions</th>
</tr>
</thead>
<tbody>
{% for info in campaign_data %}
<tr>
<input type="hidden" name="campaign_name" value="{{info.campaign}}">
<td>{{info.campaign}}</td>
<input type="hidden" name="campaign_id" value="{{info.campaign_id}}">
<td>{{info.campaign_id}}</td>
<td class="text-center">
<div class="form-group">
<select class="form-control form-control-sm" id="kpiFormControlSelect" name="kpi_name">
<option value="none">None</option>
{% for kpi in kpi_info %}
<option value="{{kpi.kpi_name}}">{{ kpi.kpi_name }}</option>
{% endfor %}
</select>
</div>
</td>
<td class="text-center">
<a href="" class="d-none d-sm-inline-block btn btn-sm btn-info shadow-sm">
<i class="fas fa-square-root-alt fa-sm text-white-50"></i> Assign KPI
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<br>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
<input class="btn btn-primary" type="submit" value="Assign KPI´s" href="">
</div>
</form>
When I run the following function:
#blueprint.route('/account/assignkpibulk', methods=['GET','POST'])
#isLoggedIn
def assign_kpi_bluk():
if request.method == 'POST':
print(request.form.to_dict())
_data = {'user_name': session['user_name'],
'id': None,
'data': request.form.to_dict()}
return redirect(url_for('dashboard.assign_kpi', client_id=session['client_id'], client_name=session['client_name']))
when I print(request.form.to_dict()) it only request the first value of the dictionary:
{'modalKpiTable_length': '10', 'campaign_name': 'Sample Campaign', 'campaign_id': '900990999', 'kpi_name': 'none'}
However if I do just print(request.form) I got all the results:
ImmutableMultiDict([('modalKpiTable_length', '3'), ('campaign_name', 'Sample Campaign'),
('campaign_name', 'Sample Campaign 2'), ('campaign_name', 'Sample Campaign 3'),
('campaign_id', '900990999'), ('campaign_id', '9009909992'), ('campaign_id', '9009909993'),
('kpi_name', 'none'), ('kpi_name', 'kpi_1'), ('kpi_name', 'kpi_2')])
Most answers / documentation I read suggest to add to_dict(request.form) or dict(request.form) to convert the request to a dictionary however did´t work
Thanks
The request.form object is an immutable dictionary and has type of werkzeug.ImmutableMultiDict which has to_dict(flat=True) function.
refer to:
https://tedboy.github.io/flask/generated/generated/werkzeug.ImmutableMultiDict.to_dict.html
ImmutableMultiDict.to_dict(flat=True)
Return the contents as regular dict. If flat is True the returned dict will only have the first item present, if flat is False all values will be returned as lists.
so to get all values you need to set flat parameter to False in request.form.to_dict(flat=False)

How to make a checkbox checked in Jinja2

I am learning flask programming and cannot figure out how to make a radio input checked, here is the html template I am using:
<form method = "POST" action="/proxy_settings">
<input type="radio" name="proxy_mode" value = '0'>Auto
<br>
<input type="radio" name="proxy_mode" value = '1'>Manual
<br>
<br>
<section>
<table border="1">
<tr>
<td>Description</td>
<td>delay</td>
<td>select</td>
</tr>
{% for node_name, node_delay in node_list.items() %}
<tr>
<td>{{node_name}}</td>
<td>{{node_delay}}</td>
<td><input type="radio" name="proxy_node"></td>
</tr>
{% endfor %}
</table>
</section>
<br>
<section>
<button type="submit">CONFIRM</button>
</section>
</form>
I am rendering this template in flask like this:
return render_template("base.html", node_number = ret["node_number"], proxy_mode = ret1["proxy_mode"], proxy_node = ret2["proxy_node"], node_list=ret3)
My question is:
How to make proxy_mode radio input checked according to the value of variable proxy_mode?
How to make proxy_node radio input checked according to the value of variable proxy_node? For example, if proxy_node equals to 2, then the radio input in row 2 of the table will be checked.
How to assign a value attribute dynamically to the radio input proxy_node?
I have tried the following method for question 1 but it doesn't work.
<input type="radio" name="proxy_mode" value = '0' {% if proxy_mode == 0 %} checked=true {% endif %}>Auto
<br>
<input type="radio" name="proxy_mode" value = '1' {% if proxy_mode == 1 %} checked=true {% endif %}>Manual
Thanks in advance!
This should be the easiest way.
<input type="radio" name="proxy_mode" value="0" {{ "checked" if proxy_mode == 0 }}>Auto
<br>
<input type="radio" name="proxy_mode" value="1" {{ "checked" if proxy_mode == 1 }}>Manual
After reading through Jinja2 Template Designer Documentation and another stackoverflow question I was able to come up with a solution for my problems:
Use Jinja statements to control whole html tag instead of a property of this tag. So, the form looks like this after modification:
<form method = "POST" action="/proxy_settings">
{% if proxy_mode == '0' %}
<input type="radio" name="proxy_mode" value = '0' checked=true>Auto
{% else %}
<input type="radio" name="proxy_mode" value = '0'>Auto
{% endif %}
<br>
{% if proxy_mode == '1' %}
<input type="radio" name="proxy_mode" value = '1' checked=true>Manual
{% else %}
<input type="radio" name="proxy_mode" value = '1'>Manual
{% endif %}
<br>
<br>
<section>
<table border="1">
<tr>
<td>Description</td>
<td>delay</td>
<td>select</td>
</tr>
{% for node_name, node_delay in node_list.items() %}
<tr>
<td>{{node_name}}</td>
<td>{{node_delay}}</td>
{% if loop.index0 == proxy_node|int %}
<td><input type="radio" name="proxy_node" value={{loop.index0}} checked=true></td>
{% else %}
<td><input type="radio" name="proxy_node" value={{loop.index0}}></td>
{% endif %}
</tr>
{% endfor %}
</table>
</section>
<br>
<section>
<button type="submit">CONFIRM</button>
</section>
</form>
Hope this answer will help whoever viewed this question. Thanks!

Django issues with filtering objects by month and year

I'm building a website in Django and I want to make a page as an archive for the Spendings objects that I have in my models.py file, I'm trying to make a form where a users can select a year and a month and after they click submit I want to show them all the spendings that they had on that month of the year. This is my code from views.py file
def archive(request):
if request.method == 'POST':
budget = Budget.objects.filter(user=request.user)
year = datetime.strptime(request.POST['year'], '%Y')
month = datetime.strptime(request.POST['month'], '%m')
spendings = Spending.objects.filter(
user=request.user, date_created__year=year.year, date_created__month=month.month)
total_spendings = spendings_assembly(spendings)
return redirect('archive')
else:
budget = Budget.objects.filter(user=request.user)
spendings = Spending.objects.filter(user=request.user)
total_spendings = spendings_assembly(spendings)
context = {
'title': 'Archive',
'spendings': spendings,
'total_spendings': total_spendings,
'budget': budget,
}
return render(request, 'users/archive.html', context)
and this is what is on my archive.html file:
<div class="container">
<form method="POST" action="{% url 'archive' %}">
{% csrf_token %}
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01">Year</label>
</div>
<select name="year" class="custom-select" id="inputGroupSelect01">
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
</select>
</div>
<div class="input-group mb-3">
<select name="month" class="custom-select" id="inputGroupSelect02">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<div class="input-group-append">
<label class="input-group-text" for="inputGroupSelect02">Month</label>
</div>
</div>
<input type="submit" name="result" value="See the Archive" class="btn btn-warning btn-lg btn-block">
</form>
<div class="row">
<div class="col">
<h4>Spendings List</h4>
<hr>
<table class="table table-hover">
<thead class="thead-dark">
<tr>
{% for sum in budget %}
<th>Name</th>
<th>Category</th>
<th>Amount ({{ sum.currency }})</th>
<th>Date Created</th>
{% endfor %}
</tr>
</thead>
{% for spending in spendings %}
<tr>
<td>{{ spending.name }}</td>
<td>{{ spending.category }}</td>
<td>{{ spending.amount }}</td>
<td>{{ spending.date_created|date:"F-d-Y" }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
This is code for spendings object from models.py file:
class Spending(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
category = models.CharField(max_length=100)
amount = models.FloatField()
date_created = models.DateTimeField(default=timezone.now)
def __str__(self):
return self.name

How to select/unselect/delete multiple django items in a table with the same checkbox?

I have this table of items with their details, and I have implemented a method to 'select' a few items using a submit button, which submits all checked checkboxes on each item.
This is the code for the checkbox:
<input name='quiz-pids' id='checkbox-{{ quiz.id }}' type="checkbox" value="{{ quiz.id }}" required>
As you can see, I have passed the quiz.id in the checkbox value. This is my submit button I am using:
<input type="submit" class="btn btn-primary select-btn myitems-select-btn"
value='Finalize Items'
required>
Here, I have not mentioned what this button will do except than submit. This is the function which processes the data input by submit button.
class UploadedItems(ListView):
model = ItemBatch
ordering = ('uploaded',)
context_object_name = 'plan'
template_name = 'classroom/teachers/item_list.html'
def post (self, request, *args, **kwargs):
# get the selected quizs
quizs = request.POST.getlist('quiz-pids')
# retrieves thoses quizes from the database:
print("pids returned are ", quizs)
# items = ItemBatch.objects.filter(pid__in=quizs)
for i in quizs:
print("before", i)
i = get_object_or_404(ItemBatch, id=i)
i.rtd = 'True'
i.save()
print("after", i.truck_type) # print("items are",items)
return redirect('teachers:upload_batch')
As you can see, my function 'post' accepts only quiz-pids because of this line request.POST.getlist('quiz-pids'). Now my question is, I also want to delete and unselect my items. But, because my function can only accept quiz-pids, I cannot just create another button for that.
What I tried
I tried adding more functions:
def post (self, request, *args, **kwargs):
# get the selected quizs
quizs = request.POST.getlist('quiz-pids')
deleted_items = request.POST.getlist('delete-pids')
unselect_items = request.POST.getlist('unselect-pids')
# retrieves thoses quizes from the database:
print("pids returned are ", quizs)
# items = ItemBatch.objects.filter(pid__in=quizs)
for i in quizs:
print("before", i)
i = get_object_or_404(ItemBatch, id=i)
i.rtd = 'True'
i.save()
print("after", i.truck_type) # print("items are",items)
for j in unselect_items:
j = get_object_or_404(ItemBatch, id=i)
j.rtd = 'False'
j.save()
for k in deleted_items:
k = get_object_or_404(ItemBatch, id=i)
k.delete()
k.save()
But, because every checkbox I have in front of my items, has the name name='quiz-pids', I am not able to generate a deleted_items list or unselect_items list. I cannot possibly give three different checkboxes to every item. What should I do?
Here is my complete html and views function:
#method_decorator([login_required, teacher_required], name='dispatch')
class UploadedItems(ListView):
model = ItemBatch
ordering = ('uploaded',)
context_object_name = 'plan'
template_name = 'classroom/teachers/item_list.html'
def get_queryset (self):
return ItemBatch.objects.filter(uploaded_by=self.request.user)
def get_context_data (self, **kwargs):
context = super().get_context_data(**kwargs)
latest = ItemBatch.objects.filter(uploaded_by=self.request.user).order_by('-time').annotate(
truncated_time=Trunc('time', 'minute', output_field=DateTimeField()))
context['last'] = ItemBatch.objects.filter(uploaded_by=self.request.user).annotate(
truncated_time=Trunc('time', 'minute', output_field=DateTimeField())).filter(
truncated_time=Subquery(latest.values('truncated_time')[:1])).order_by('-rtd')
return context
def post (self, request, *args, **kwargs):
# get the selected quizs
quizs = request.POST.getlist('quiz-pids')
deleted_items = request.POST.getlist('delete-pids')
unselect_items = request.POST.getlist('unselect-pids')
# retrieves thoses quizes from the database:
print("pids returned are ", quizs)
# items = ItemBatch.objects.filter(pid__in=quizs)
for i in quizs:
print("before", i)
i = get_object_or_404(ItemBatch, id=i)
i.rtd = 'True'
i.save()
print("after", i.truck_type) # print("items are",items)
for j in unselect_items:
j = get_object_or_404(ItemBatch, id=i)
j.rtd = 'False'
j.save()
for k in deleted_items:
k = get_object_or_404(ItemBatch, id=i)
k.delete()
k.save()
print("pids converted are ", quizs)
return redirect('teachers:upload_batch')
HTML template:
{% extends 'base2.html' %}
{% load static %}
{% load tz humanize %}
{% timezone "Asia/Kolkata" %}
{% block content %}
<h2>Orders</h2>
{% include 'classroom/teachers/inventory_header.html' with active='myitems' %}
<h2 class="align-left"> Your Last Uploaded Items</h2>
{#Post New Bid#}
<div class="card last-items">
<form method="post" novalidate>
{% csrf_token %}
<table class="table table-striped mb-0" id="items">
<thead>
<tr>
<th>Select</th>
<th>Name</th>
<th>SKU ID</th>
<th>Quantity</th>
<th>Dimensions</th>
<th>Volume/Weight</th>
<th>Origin</th>
<th>Destination</th>
<th>Type</th>
<th>Uploaded</th>
<th>Dispatch Status</th>
</tr>
</thead>
<tbody>
<input type="checkbox" id="selectall" class="css-checkbox btn btn-primary" name="selectall"/>Select
All
{% for quiz in last %}
<input type="submit" class="btn btn-primary select-btn myitems-select-btn"
value='Finalize Items'
required>
<input type="submit" class="btn btn-primary select-btn myitems-select-btn"
value='Unselect Items'
required>
<input type="submit" class="btn btn-primary select-btn myitems-select-btn"
value='Delete Items'
required>
<a href="{% url 'teachers:pack_it' %}"
class="btn btn-primary mb-3 myitems-select-btn {% if quiz.rtd == 0 %} disabled {% endif %}"
role="button">Plan Vehicles</a>
<tr class="{% if quiz.rtd == True %} active{% endif %} {% if quiz.is_dispatched == True %} dispatched{% endif %}">
<td class="align-middle"><input name='quiz-pids' id='checkbox-{{ quiz.id }}'
type="checkbox" value="{{ quiz.id }}" required
{% if quiz.is_dispatched == 1 %} disabled{% endif %} ></td>
<td class="align-middle">{{ quiz.name }}</td>
<td class="align-middle">{{ quiz.pid }}</td>
<td class="align-middle">{{ quiz.quantity }}</td>
<td class="align-middle">{{ quiz.length }}x{{ quiz.width }}x{{ quiz.height }}</td>
<td class="align-middle">{{ quiz.volume|truncatechars:8 }}/{{ quiz.weight }}</td>
<td class="align-middle">{{ quiz.origin }}</td>
<td class="align-middle">{{ quiz.destination }}</td>
<td class="align-middle">{{ quiz.truck_type }}</td>
<td class="align-middle">{{ quiz.time|naturaltime }}</td>
<td class="align-middle">{{ quiz.is_dispatched|yesno:"Dispatched,Ready to Dispatch" }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
</div>
<br>
<br>
<h2 class="align-left">All your Uploaded Items</h2>
<br>
<div class="card">
<table class="table table-striped mb-0" id="items">
<thead>
<tr>
<th>Select</th>
<th>Name</th>
<th>SKU ID</th>
<th>Quantity</th>
<th>Dimensions</th>
<th>Volume/Weight</th>
<th>Origin</th>
<th>Destination</th>
<th>Type</th>
<th>Uploaded</th>
<th>Dispatch Status</th>
</tr>
</thead>
<tbody>
<form method="post" novalidate>
{% csrf_token %}
{% for quiz in plan %}
<input type="submit" class="btn btn-primary select-btn myitems-select-btn"
value='Finalize Items'
required>
<a href="{% url 'teachers:pack_it' %}"
class="btn btn-primary mb-3 myitems-select-btn {% if quiz.rtd == 0 %} disabled {% endif %}"
role="button">Plan Vehicles</a>
<tr class="{% if quiz.rtd == True %} active{% endif %} {% if quiz.is_dispatched == True %} dispatched{% endif %}">
<td class="align-middle"><input name='quiz-pids' id='checkbox-{{ quiz.id }}'
type="checkbox" value="{{ quiz.id }}" required
{% if quiz.is_dispatched == 1 %} disabled{% endif %} ></td>
<td class="align-middle">{{ quiz.name }}</td>
<td class="align-middle">{{ quiz.pid }}</td>
<td class="align-middle">{{ quiz.quantity }}</td>
<td class="align-middle">{{ quiz.length }}x{{ quiz.width }}x{{ quiz.height }}</td>
<td class="align-middle">{{ quiz.volume }}/{{ quiz.weight }}</td>
<td class="align-middle">{{ quiz.origin }}</td>
<td class="align-middle">{{ quiz.destination }}</td>
<td class="align-middle">{{ quiz.truck_type }}</td>
<td class="align-middle">{{ quiz.time|naturaltime }}</td>
<td class="align-middle">{{ quiz.is_dispatched|yesno:"Dispatched,Ready to Dispatch" }}</td>
</tr>
<tr>
{% empty %}
<td class="bg-light text-center font-italic" colspan="9">You haven't uploaded any items yet.
</td>
</tr>
{% endfor %}
</form>
</tbody>
</table>
</div>
<link rel="stylesheet" href="http://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">
{# <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>#}
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#items').DataTable({
"pagingType": "full_numbers",
"bDestroy": true
});
});
</script>
<script>
$('#selectall').click(function () {
var checkedStatus = this.checked;
$('input:checkbox').each(function () {
$(this).prop('checked', checkedStatus);
});
});
</script>
{% endblock %}
{% endtimezone %}
Anybody has any doubts? or need more information?

Categories

Resources