Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.39 KB | None | 0 0
  1. @http.route(['/offline_miners'], type='http', auth='public', methods=['GET'], website=True)
  2. def offline_report(self, **kw):
  3. devices_offline = request.env['cmc.device'].sudo().search([('current_ip_address_id', '=', False), ('state', '=', 'active')])
  4. now = datetime.datetime.now()
  5.  
  6. ret = '<h3>List of offline miners </br> <h4>Date: %s</h4></h3>' % (now.strftime("%Y-%m-%d %H:%M"))
  7.  
  8. devices = devices_offline.sorted(lambda d: (d.current_location_id.name or 'UNKOWN', d.name))
  9.  
  10. beaudry = []
  11. beaudry.append('<h4>Beaudry</h4><br>')
  12. thomas = []
  13. thomas.append('<h4>St-Thomas</h4><br>')
  14. root = []
  15. root.append('<h4>Root</h4><br>')
  16. champlain = []
  17. champlain.append('<h4>Champlain</h4><br>')
  18. lanaudiere = []
  19. lanaudiere.append('<h4>Lanaudière</h4><br>')
  20. paul = []
  21. paul.append('<h4>St-Paul</h4><br>')
  22. raoul = []
  23. raoul.append('<h4>Raoul-Charette</h4><br>')
  24. unknown = []
  25. unknown.append('<h4>Unknown</h4><br>')
  26.  
  27. for device in devices_offline:
  28. if device.current_location_id:
  29. if device.current_location_id.name[:4] == 'LOC1':
  30. beaudry.append('<tr><td>%s</td> <td>%s</td> <td>%s</td> </tr>' % (device.name, device.current_location_id.name or ' ', device.owner_id.name or ' '))
  31. elif device.current_location_id.name[:4] == 'LOC2':
  32. thomas.append('<tr><td>%s</td> <td>%s</td> <td>%s</td> </tr>' % (device.name, device.current_location_id.name or ' ', device.owner_id.name or ' '))
  33. elif device.current_location_id.name[:4] == 'LOC3':
  34. root.append('<tr><td>%s</td> <td>%s</td> <td>%s</td> </tr>' % (device.name, device.current_location_id.name or ' ', device.owner_id.name or ' '))
  35. elif device.current_location_id.name[:4] == 'LOC4':
  36. champlain.append('<tr><td>%s</td> <td>%s</td> <td>%s</td> </tr>' % (device.name, device.current_location_id.name or ' ', device.owner_id.name or ' '))
  37. elif device.current_location_id.name[:4] == 'LOC5':
  38. lanaudiere.append('<tr><td>%s</td> <td>%s</td> <td>%s</td> </tr>' % (device.name, device.current_location_id.name or ' ', device.owner_id.name or ' '))
  39. elif device.current_location_id.name[:4] == 'LOC6':
  40. paul.append('<tr><td>%s</td> <td>%s</td> <td>%s</td> </tr>' % (device.name, device.current_location_id.name or ' ', device.owner_id.name or ' '))
  41. elif device.current_location_id.name[:4] == 'LOC7':
  42. raoul.append('<tr><td>%s</td> <td>%s</td> <td>%s</td> </tr>' % (device.name, device.current_location_id.name or ' ', device.owner_id.name or ' '))
  43. else:
  44. unknown.append('<tr><td>%s</td> <td>%s</td> <td>%s</td> </tr>' % (device.name, device.current_location_id.name or ' ', device.owner_id.name or ' '))
  45.  
  46. if not kw.get('id') is None:
  47. if len(beaudry) > 1 and ('1' in kw.get('id')):
  48.  
  49. i = 0
  50. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  51. while i < len(beaudry):
  52. ret += beaudry[i]
  53. i += 1
  54.  
  55. ret += '</table><br>'
  56.  
  57. if len(thomas) > 1 and ('2' in kw.get('id')):
  58.  
  59. i = 0
  60. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  61. while i < len(thomas):
  62. ret += thomas[i]
  63. i += 1
  64.  
  65. ret += '</table>'
  66.  
  67. if len(root) > 1 and ('3' in kw.get('id')):
  68. i = 0
  69. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  70. while i < len(root):
  71. ret += root[i]
  72. i += 1
  73.  
  74. ret += '</table>'
  75.  
  76. if len(champlain) > 1 and ('4' in kw.get('id')):
  77. i = 0
  78. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  79. while i < len(champlain):
  80. ret += champlain[i]
  81. i += 1
  82.  
  83. ret += '</table>'
  84.  
  85. if len(lanaudiere) > 1 and ('5' in kw.get('id')):
  86. i = 0
  87. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  88. while i < len(lanaudiere):
  89. ret += lanaudiere[i]
  90. i += 1
  91.  
  92. ret += '</table>'
  93.  
  94. if len(paul) > 1 and ('6' in kw.get('id')):
  95. i = 0
  96. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  97. while i < len(paul):
  98. ret += paul[i]
  99. i += 1
  100.  
  101. ret += '</table>'
  102.  
  103. if len(raoul) > 1 and ('7' in kw.get('id')):
  104. i = 0
  105. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  106. while i < len(raoul):
  107. ret += raoul[i]
  108. i += 1
  109.  
  110. ret += '</table>'
  111. else:
  112. if len(beaudry) > 1:
  113.  
  114. i = 0
  115. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  116. while i < len(beaudry):
  117. ret += beaudry[i]
  118. i += 1
  119.  
  120. ret += '</table><br>'
  121.  
  122. if len(thomas) > 1:
  123.  
  124. i = 0
  125. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  126. while i < len(thomas) :
  127. ret += thomas[i]
  128. i += 1
  129.  
  130. ret += '</table>'
  131.  
  132. if len(root) > 1:
  133. i = 0
  134. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  135. while i < len(root):
  136. ret += root[i]
  137. i += 1
  138.  
  139. ret += '</table>'
  140.  
  141. if len(champlain) > 1:
  142. i = 0
  143. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  144. while i < len(champlain):
  145. ret += champlain[i]
  146. i += 1
  147.  
  148. ret += '</table>'
  149.  
  150. if len(lanaudiere) > 1:
  151. i = 0
  152. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  153. while i < len(lanaudiere):
  154. ret += lanaudiere[i]
  155. i += 1
  156.  
  157. ret += '</table>'
  158.  
  159. if len(paul) > 1:
  160. i = 0
  161. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  162. while i < len(paul):
  163. ret += paul[i]
  164. i += 1
  165.  
  166. ret += '</table>'
  167.  
  168. if len(raoul) > 1:
  169. i = 0
  170. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  171. while i < len(raoul):
  172. ret += raoul[i]
  173. i += 1
  174.  
  175. ret += '</table>'
  176.  
  177. if len(unknown) > 1:
  178. i = 0
  179. ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
  180. while i < len(unknown):
  181. ret += unknown[i]
  182. i += 1
  183.  
  184. ret += '</table>'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement