Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############### views.py
- from .tables import VisitsTable
- from datetime import date
- def calculate_year_income(request):
- today = date.today()
- year_income = Visits.objects.filter(visitdate__year=today.year).order_by('-id')
- year_table = VisitsTable(year_income, exclude='addpresent')
- year_table.paginate(page=request.GET.get("page", 1), per_page=10)
- print_table = VisitsTable(year_income, exclude='addpresent, addlab, addrevis')
- print_table.paginate(page=request.GET.get("page", 1), per_page=10)
- context = {
- 'year_table': year_table,
- 'print_table': print_table,
- }
- return render(request, 'reports/year_table.html', context)
- ############### year_table.html
- {% extends 'index.html' %}
- {% load render_table from django_tables2 %}
- {% block content %}
- <div>
- <p class="float-left">
- <h1><strong>Yearly Report</strong></h1>
- </p>
- <a type="button" class="btn btn-outline-primary" href="{% url 'reports:print_html' %}">
- Print Preview
- </a>
- <button class="btn btn-outline-success" id="print" onclick="printData()">
- Print
- </button>
- </div>
- <br><br>
- <div class="container">
- {% render_table year_table %}
- </div>
- <div id="pdata" hidden>
- {% render_table print_table %}
- </div>
- {% endblock %}
- {% block scripts %}
- <script type="text/javascript">
- function printData() {
- var divToPrint = document.getElementById('pdata');
- var htmlToPrint = '' +
- '<style type="text/css">' +
- 'table th, table td {' +
- 'border:1px solid #000;' +
- 'padding:0.5em;' +
- 'width:100%;' +
- 'white-space:nowrap;' + // this line to make the cells flixable
- '}' +
- 'p {' +
- 'text-align: right' +
- 'margin-bottom:0;' +
- 'padding:0;' +
- 'line-height:12px;' +
- 'font-size:10px;' +
- '}' +
- '#pdata {display: block;}' +
- '@media print {' +
- 'nav { visibility: hidden; }' + // for remove pagination from
- // printing
- '}' +
- '</style>';
- htmlToPrint += divToPrint.outerHTML;
- newWin = window.open("");
- newWin.document.write(htmlToPrint);
- newWin.print();
- newWin.close();
- }
- </script>
- {% endblock %}
- ################# tables.py
- import django_tables2 as tables
- from .models import Visits
- def render_footer(bound_column, table):
- return sum(bound_column.accessor.resolve(row) for row in table.data)
- class VisitsTable(tables.Table):
- amount = tables.TemplateColumn(
- '<a href="{% url \'visits:visits_patient_id\' record.id record.patient_id %}">{{ record.amount }}</a>',
- verbose_name=u'Amount',
- footer=render_footer)
- id = tables.TemplateColumn(
- '<a href="{% url \'visits:visits_patient_id\' record.id record.patient_id %}">{{ record.id }}</a>',
- verbose_name=u'Visits ID',
- template_name='django_tables2/bootstrap4.html',
- )
- patient = tables.TemplateColumn(
- '<a href="{% url \'visits:visits_patient_id\' record.id record.patient_id %}">{{ record.patient }}</a>',
- verbose_name=u'Patient Name',
- template_name='django_tables2/bootstrap4.html',
- )
- visitdate = tables.TemplateColumn(
- '<a href="{% url \'visits:visits_patient_id\' record.id record.patient_id %}">{{ record.visitdate }}</a>',
- verbose_name=u'Visit Date',
- )
- diagnosis = tables.TemplateColumn(
- '<a href="{% url \'visits:visits_patient_id\' record.id record.patient_id %}">{{ record.diagnosis }}</a>',
- verbose_name=u'Daignosis', #footer=len(tables.rows)
- )
- addlab = tables.TemplateColumn(
- '<a class="btn btn-outline-dark" href="{% url \'labs:add_lab_visit\' record.patient_id record.id %}">Add Analysis</a>',
- verbose_name=u'Add Analysis',
- footer="")
- addpresent = tables.TemplateColumn(
- '<a class="btn btn-outline-primary" href="{% url \'presenthistory:save_present_hist\' record.patient_id record.id %}">Add Present History</a>',
- verbose_name=u'Add Present History')
- addrevis = tables.TemplateColumn(
- '<a class="btn btn-outline-dark" href="{% url \'revisits:save_revisit\' record.patient_id record.id %}">Add Revisit</a>',
- verbose_name=u'Add Revisit')
- class Meta:
- model = Visits
- attrs = {"id": "visits-table",
- 'class': 'table table-striped table-bordered table-hover'}
- template_name = 'django_tables2/bootstrap4.html'
- fields = ('id', 'patient', 'visitdate', 'diagnosis', 'amount',
- 'addrevis', 'addlab')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement