Guest User

Untitled

a guest
Sep 13th, 2018
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. #TABLE DOWNLOAD
  2. ____________________________________________
  3. | email | PUB (FK_DOCUMENT) |
  4. | __________________________________________ |
  5. |test12@gmail.com | 1 |
  6. | __________________________________________ |
  7. |test12@gmail.com | 2 |
  8. | __________________________________________ |
  9. |test45@gmail.com | 4 |
  10. | __________________________________________ |
  11. |test22@gmail.com | 3 |
  12. | __________________________________________ |
  13. |test01@gmail.com | 2 |
  14. | __________________________________________ |
  15. |test98@gmail.com | 4 |
  16. | __________________________________________ |
  17. |test74@gmail.com | 4 |
  18. | __________________________________________ |
  19.  
  20. #TABLE DOCUMENT
  21. __________________
  22. | ID | EDQM_ID |
  23. | ________________ |
  24. |1 | A |
  25. | ________________ |
  26. |2 | B |
  27. | ________________ |
  28. |3 | C |
  29. | ________________ |
  30. |4 | D |
  31. | ________________ |
  32.  
  33. #HTML STATISTICS TABLE
  34. ________________________
  35. | PUB_ID | Requests |
  36. | _____________________ |
  37. |A | 1 |
  38. | _____________________ |
  39. |B | 2 |
  40. | _____________________ |
  41. |C | 1 |
  42. | _____________________ |
  43. |D | 3 |
  44. | _____________________ |
  45.  
  46. pub_id = Download.objects.values_list('pub__edqm_id').distinct()
  47.  
  48. <QuerySet [('A',), ('B',), ('C',), ('D',)]>
  49.  
  50. requests = Download.objects.values_list('pub__edqm_id').annotate(count=Count('pub__edqm_id'))
  51.  
  52. <QuerySet [('TEST-02', 12), ('FORMSET-3', 1), ('EPUB TEST', 3), ('TEST-01', 9), ('FORMSET 03', 13), ('FORMSET 3 bi', 24), ('BIO 01', 87)]>
  53.  
  54. <table id="DocumentTable" class="table table-bordered table-striped table-condensed table_model">
  55. <thead>
  56. <caption style="border: inherit; background-color: lightgrey;">
  57. <span><strong>Download per Publication</strong></span>
  58. </caption>
  59. <tr>
  60. <th>{% trans 'Publications' %}</th>
  61. <th>{% trans 'Requests' %}</th>
  62. <th>{% trans 'Max download number' %}</th>
  63. <th>{% trans 'Average download number' %}</th>
  64. </tr>
  65. </thead>
  66. <tbody>
  67. <tr>
  68. <td>PUB_ID here </td>
  69. <td><span class="badge alert-danger"> Requests here </span></td>
  70. <td> </td>
  71. <td> </td>
  72. </tr>
  73. </tbody>
  74. </table>
  75.  
  76. class StatsView(View):
  77. template_name = 'freepub/stats.html'
  78.  
  79. def get(self, request):
  80. subtitle = _("Statistics")
  81.  
  82. #Some values display in my template
  83. customers_count = Customer.objects.all().count()
  84. publications_count = Publication.objects.all().count()
  85. downloads_count = Download.objects.all().count()
  86. last_download_temp = Download.objects.latest('id').download_date
  87. last_download = last_download_temp.strftime('%Y-%m-%d %H:%M:%S ')
  88. document = Document.objects.all()
  89.  
  90. #Populate HTML table
  91. pub_id = Download.objects.values_list('pub__edqm_id').distinct()
  92.  
  93. fieldname = Download.objects.values_list('pub__edqm_id').annotate(count=Count('pub__edqm_id'))
  94.  
  95. context = {'subtitle': subtitle,
  96. 'fieldname': fieldname,
  97. 'customers_count': customers_count,
  98. 'publications_count': publications_count,
  99. 'downloads_count': downloads_count,
  100. 'last_download': last_download,
  101. 'document': document}
  102.  
  103. return render(request, self.template_name, context)
Add Comment
Please, Sign In to add comment