What is the best way to disable the "deny" button when "approve" button is clicked ? I have {{some}} that stores the value of approve or deny value.
<button>Approve</button>
<button>Deny</button>
html file
{% if some %}
<table id="example" class="display" cellspacing="0" width="100%" border="1.5px">
<tr align="center">
<th> Student ID </th>
<th> Student Name </th>
<th> Start Date </th>
<th> End Date </th>
<th> Action </th>
<th> Status </th>
</tr>
{% for item in query_results %}
<tr align="center">
<td> {{item.studentID}} </td>
<td> {{item.studentName}} </td>
<td> {{item.startDate|date:'d-m-Y'}} </td>
<td> {{item.endDate|date:'d-m-Y'}} </td>
<td><button>Approve</button> <button {% if some == 'approve' %} disabled{% endif %}>Deny</button></td>
<td>
{% if item.status %}
{{item.status}}
{% else %}
Pending
{% endif %}
</td>
</tr>
{% endfor %}
</table>
{% else %}
the {{some}} gets from here
views.py
def superltimesheet(request):
query_results = Timesheet.objects.all()
data={'query_results':query_results, 'some':'some'}
return render(request, 'hrfinance/supervisor_list_timesheet.html', data)
Use an if tag:
<button{% if some == 'deny' %} disabled{% endif %}>Approve</button>
I am not sure about what are you asking, but you can do an if statement like
{% if some == 'approve' %}
<button>Deny</button>
{% else %}
<button>Approve</button>
{% endif %}
or:
{% if some == 'approve' %}
<button>Deny</button>
{% else %}
tell me if that works or I misunderstood
Related
TypeError at /dashboard
'post' object is not iterable i am just try to get data from db table and show on dashboard in dabel form
my dashboard.html page
{% if posts %}
<table class="table table-dark table-hover">
<thead>
<tr>
<th scope="col" style="width:3%">ID</th>
<th scope="col" style="width:30%">Title</th>
<th scope="col" style="width:55%">Description</th>
<th scope="col" style="width:15%">Action</th>
</tr>
</thead>
<tbody>
{% for post in posts %}
<tr>
<td>{{posts.id}} </td>
<td>{{posts.title}}</td>
<td>{{posts.desc}}</td>
<td><a class="btn btn-primary" type="submit" value="Submit">Edit</a>
<form action ='' , method ='POST' class='d-inline'>
{% csrf_token %}
<input type='submit' class='btn btn-danger btn-sm' value ='Delete' >
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<h4 class =' text-center alert alert-warning'>No Records </h4>
{% endif %}
</div>
</div>
{% endblock content %}
my views.py
def dashboard(request):
if request.user.is_authenticated:
posts= post.objects.all()
return render(request,'dashboard.html',{'posts':post})
else:
return HttpResponseRedirect('login')
urls.py
path('dashboard',views.dashboard,name='dashboard'),
You have a typo in your views.py file. Try change this:
return render(request,'dashboard.html',{'posts':post})
to this:
return render(request,'dashboard.html',{'posts':posts})
I assume in template dashboard.html you have to change this :
{% for post in posts %}
<tr>
<td>{{posts.id}} </td>
<td>{{posts.title}}</td>
<td>{{posts.desc}}</td>
to this :
{% for post in posts %}
<tr>
<td>{{post.id}} </td>
<td>{{post.title}}</td>
<td>{{post.desc}}</td>
It should be like this:
{% for post in posts %}
<tr>
<td>{{post.id}} </td>
<td>{{post.title}}</td>
<td>{{post.desc}}</td>
I have the following code:
<table id="MyTable" class="highlight responsive-table" >
<thead>
<tr>
{% with columns as columns %}
{% for columns in columns %}
<th class="th-sm">{{ columns }}</th>
{% endfor %}
{% endwith %}
</tr>
</thead>
<tbody>
{% for trans in transactions %}
<tr>
<td> {{ trans.transactionsequencenumber }}</td>
<td> {{ trans.posid }}</td>
<td> {{ trans.transactionnumber }}</td>
</tr>
{% endfor %}
</table>
which works for displaying static table data, but the idea is that the columns being iterated are being set via a user preferences model, so the table columns can change depending on the user, theres a possible 90+ columns to choose from, and here is where my issue lays.
pseudo code below to help illustrate my goal:
<table id="MyTable" class="highlight responsive-table" >
<thead>
<tr>
{% with columns as columns %}
{% for columns in columns %}
<th class="th-sm">{{ columns }}</th>
{% endfor %}
{% endwith %}
</tr>
</thead>
<tbody>
{% for trans in transactions %}
<tr>
<td> {{ trans.{{columns}} }}</td>
</tr>
{% endfor %}
I've tried simple string concatenation so far, but that just prints the string to the table and not the object data,
any help and/or guidance would be greatly apprecieted.
be kind, this is my first question.
For every object that represent a line in the database attribute, you put it into a column. For example:
<tr>
<th> title </th>
<th> body </th>
</tr>
{% for post in posts %}
<tr>
<td> {{post.title}}</td>
<td> {{post.body}} </td>
</tr>
{% endfor %}
<h3>Out of severice vehicles</h3>
<table class="table table-hover">
<tbody>
<tr>
{% for col in caidian_oos.columns %}
<th>
{{col}}
</th>
{% endfor %}
</tr>
{% for row in caidian_oos.values %}
<tr>
{% for cell in row %}
<td>
{{cell}}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
<br />
--
The data object is a pandas dataframe
I want to add a column that user can click.
On user's click it should save the corresponding row to mysql database.
Can anybody help me? I have a list of 60 records from django database in my html file. I want to show that list in table of 6 columns and 10 rows. In html file I used command {% for %} but the list is in one column.
My html file is:
{% for kategoria in kategorie %}
<table>
<tr>
<th> {{ kategoria.glowna|linebreaksbr }} ({{ wpisy_kat }}) </th>
</tr>
</table>
{% endfor %}
you can try using divisibleby template tag in your template like this to change row after every six entries.
remember {{ forloop.counter }} {# starting index 1 #} and {{ forloop.counter0 }} {# starting index 0 #}
{% for kategoria in kategorie %}
<table>
{% if not forloop.counter0 |divisibleby:"6" %}
<tr>
{% endif %}
<th> {{ kategoria.glowna|linebreaksbr }} ({{ wpisy_kat }}) </th>
{% if forloop.counter|divisibleby:"6" %}
</tr>
{% endif %}
</table>
{% endfor %}
<table>
{% for object in queryset %}
<tr>
<td> object.attr1 </td>
<td> object.attr2 </td>
<td> object.attr3 </td>
<td> object.attr4 </td>
<td> object.attr5 </td>
<td> object.attr6 </td>
</tr>
{% endfor %}
</table>
If you want to have a more pages with 10 items each page, have a look at django's pagination
I am using pisa in my django project, to make my html generate on a PDF for report functionality. Some of my reports are getting rather large and I have noticed it doesn't have any page numbering on it. Does anyone know how I can get page numbers to show up on the printed PDF report?
edit
here is how I generate the PDF
if request.POST.has_key('print_report_submit'):
context['show_report'] = True
context['mb_logo'] = os.path.join(os.path.dirname(__file__), "../../../media/images/mb_logo.jpg")
html = render_to_string('reports/fam_maturity_print.html', RequestContext(request,context))
result = StringIO.StringIO()
pdf = pisa.pisaDocument(StringIO.StringIO(html.encode("ISO-8859-1")), result)
response = HttpResponse(result.getvalue(), mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=family_maturity-statement.pdf'
return response
HTML
{% if show_report %}
<table width="100%">
<tr>
<td colspan="2" align="center" width="400px">
<h1 class="title">Family Maturities by Year</h1>
<br/><br/>
</td>
</tr>
<tr>
<td width="500px">
<img src="{{ mb_logo }}"/>
<td> <p>
<img style="max-height: 60px; max-width:60px;" src="{{ check_image }}"/>
</p>
</tr>
</table>
<br/>
<br/>
<hr class="report_hr1"/>
<h2 class="state_head" style="font-size: 16px;">Statement Information As of {{ statement_date|date:"F d, Y" }}</h2>
<hr class="report_hr1"/>
<table>
{% for plan_dict in plan_list %}
<hr class="report_hr2"/>
<table>
<tr>
<td><strong>Plan Holder: </strong></td><td>{{ plan_dict.plan.get_primary_owner.member.client}}</td>
<td><strong>Joint Owner(s): </strong></td>
<td>
{% for member in plan_dict.plan.planmember_set.all %}
{% ifnotequal member.ownership_type.code "primary" %}
{{ member }}
{% endifnotequal %}
{% endfor %}
</td>
</tr>
<tr>
<td><strong>Plan ID: </strong></td><td>{{ plan_dict.plan.id }}</td>
</tr>
<tr>
<td><strong>Plan type: </strong></td><td>{{ plan_dict.plan.plan_type }}</td>
</tr>
</table>
<hr class="report_hr2"/>
{# This is the table for the current year's maturities #}
{% if plan_dict.investment %}
<table>
<td colspan="2"><h3>{{ cur_year }}</h3></td>
<tr>
<th>Financial Institution</th>
<th>Type</th>
<th>Principal</th>
<th>Maturity</th>
</tr>
{% for i in plan_dict.investment %}
<tr>
<td>{{ i.financial_institution.abbr }}</td>
<td>{{ i.product.code }}</td>
<td>${{ i.amount|intcomma }}</td>
<td>${{ i.maturity_amount|intcomma }}</td>
</tr>
{% endfor %}
<tr>
<td><strong>Total for {{ cur_year }}</strong></td>
<td></td>
<td><strong>${{ plan_dict.total|intcomma }}</strong></td>
<td><strong>${{ plan_dict.total_m|intcomma }}</strong></td>
</tr>
</table>
{% endif %}
<div id="holding_table" align="center">
<h3>Holding Totals with Each Company</h3>
<table>
<tr>
<td style="font-weight: bold;">Financial Institution</td>
<td style="font-weight: bold;">Total</td>
</tr>
{% for l in plan_dict.total_list %}
{% if l.maturity_amount__sum != None %}
<tr>
<td>{{ l.financial_institution__abbr }}</td>
<td>${{ l.maturity_amount__sum|intcomma }}</td>
</tr>
{% endif %}
{% endfor %}
<tr>
<td style="font-weight: bold;">Total Non-Fund Holdings for this plan</td>
<td style="font-weight: bold;">${{ plan_dict.grand|intcomma }}</td>
</tr>
</table>
<span class="disclaimer_span">This report has been prepared from data believed to be reliable but no
representation is made as to accuracy or completeness.</span>
</div>
<br/>
<br/>
{% endfor %}
</table>
{% endif %}
Any help would be much appreciated.
How says in this link:
http://www.arnebrodowski.de/blog/501-Pisa-and-Reportlab-pitfalls.html
One problem I ran into was adding a static footer to my pages, which contains a <pdf:pagenumber /> tag and should show the current pagenumber at the bottom of every page of the resulting PDF. The problem was, that every page just showed the number 0. The solution was very simple, but I was only able to figure it out after studiying the pisa source-code: You can only use the tag inside a paragraph, not (as I did) inside a table for example. Even parapgraphs inside tables don't work. It has to be a top-level paragraph.
Edit
Try this:
<div>
<pdf:pagenumber />
</div>
This is working for me you need to use this its for A3 size
#page{
size: A3;
margin: 1cm;
#frame footer_frame { /* Another static Frame */
-pdf-frame-content: footer_content;
left: 400pt; top: 1170pt; height: 20pt;
}
}
you have to put on above table
<div id="footer_content"> Page <pdf:pagenumber>
of <pdf:pagecount> </div>