amr_aly

print div

May 29th, 2021 (edited)
375
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ############## views.py
  2. # This method to print prescription
  3. def print_html(request, visit_id):
  4.     vis_id = Visits.objects.get(id=visit_id)
  5.     table = MedicineTable(Medicine.objects.filter(visit=visit_id).order_by('-id'), show_header=False)
  6.     qs = Medicine.objects.filter(visit=visit_id).order_by('-id')
  7.  
  8.     match = Medicine.objects.filter(visit=visit_id).exists()
  9.     if match:
  10.         patient = Patients.objects.get(id=patname['patient'])#patname['patient']
  11.     else:
  12.         patient = None
  13.         messages.success(request, 'Prescription is not ready create new one')
  14.    
  15.     vdate = Visits.objects.values('visitdate').filter(id=visit_id).first()
  16.     visitdate = vdate['visitdate']
  17.  
  18.     context = {
  19.         'match_patient': match,
  20.         'qs': qs,
  21.         'visit_no': vis_id,
  22.         'name': patient,
  23.         'date': visitdate,
  24.        
  25.     }
  26.     return render(request, 'visitdrug/print.html', context)
  27.  
  28. ############## print.html
  29.  
  30. <div class="container">
  31.  
  32.     <!-- <div class="center-align float-left" style="margin: 5px; padding: 10px;"> -->
  33.         <a type="button" class="btn btn-outline-primary" href="{% url 'visitdrug:save_medicine' name.id visit_no.id %}">
  34.             Back To Prescription
  35.         </a>
  36.         <button class="btn btn-outline-primary" id="print" onclick="printData()">
  37.         </button>
  38. </div>
  39. <hr>
  40.  
  41. {% for obj in qs %}
  42.     <div class="container">
  43.         <table class="table table-striped">
  44.         <tbody id="tbody-id">
  45.             <tr>
  46.                 <td colspan="1" style="background-color:lightgrey">
  47.                     <form class="well form-horizontal" style="background-color:white; margin: 10px;">
  48.                         <fieldset>
  49.                             <p style="margin: 10px;"><strong>ID :</strong> {{obj.id}}</p><br>
  50.                             <p style="margin: 10px;"><strong>Company Name :</strong> {{obj.patient}}</p><br>
  51.                             <p style="margin: 10px;"><strong>Phone No. :</strong> {{obj.visitdate}}</p><br>
  52.                             <p style="margin: 10px;"><strong>Address :</strong> {{obj.amount}}</p><br>
  53.                         </fieldset>    
  54.                     </form>
  55.                 </td>
  56.             </tr>
  57.         </tbody>
  58.         </table>
  59.     </div>
  60.     {% endfor %}
  61.  
  62.  
  63. {% endblock %}
  64.  
  65.  
  66. {% block scripts %}
  67.     <!-- <script type="text/javascript" src="{% static 'js/jquery-3.4.1.min.js' %}"></script>
  68.     <script type="text/javascript" src="{% static 'js/jquery-ui.min.js' %}"></script>
  69.     <script type="text/javascript" src="{% static 'js/bootstrap.min.js' %}"></script>
  70.     <script type="text/javascript" src="{% static 'js/main.js' %}"></script> -->
  71. <script type="text/javascript">
  72.     function printData() {
  73.         var spanToPrint = document.getElementById("p");
  74.         // var imgToPrint = document.getElementById("img");
  75.         var divToPrint = document.getElementById("pdata");
  76.         newWin = window.open("");
  77.         newWin.document.write(spanToPrint.innerHTML + divToPrint.outerHTML);
  78.         newWin.print();
  79.         newWin.close();
  80.     }
  81. </script>
  82. {% endblock  %}
RAW Paste Data