Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @http.route(['/offline_miners'], type='http', auth='public', methods=['GET'], website=True)
- def offline_report(self, **kw):
- devices_offline = request.env['cmc.device'].sudo().search([('current_ip_address_id', '=', False), ('state', '=', 'active')])
- now = datetime.datetime.now()
- ret = '<h3>List of offline miners </br> <h4>Date: %s</h4></h3>' % (now.strftime("%Y-%m-%d %H:%M"))
- devices = devices_offline.sorted(lambda d: (d.current_location_id.name or 'UNKOWN', d.name))
- beaudry = []
- beaudry.append('<h4>Beaudry</h4><br>')
- thomas = []
- thomas.append('<h4>St-Thomas</h4><br>')
- root = []
- root.append('<h4>Root</h4><br>')
- champlain = []
- champlain.append('<h4>Champlain</h4><br>')
- lanaudiere = []
- lanaudiere.append('<h4>Lanaudière</h4><br>')
- paul = []
- paul.append('<h4>St-Paul</h4><br>')
- raoul = []
- raoul.append('<h4>Raoul-Charette</h4><br>')
- unknown = []
- unknown.append('<h4>Unknown</h4><br>')
- for device in devices_offline:
- if device.current_location_id:
- if device.current_location_id.name[:4] == 'LOC1':
- 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 ' '))
- elif device.current_location_id.name[:4] == 'LOC2':
- 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 ' '))
- elif device.current_location_id.name[:4] == 'LOC3':
- 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 ' '))
- elif device.current_location_id.name[:4] == 'LOC4':
- 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 ' '))
- elif device.current_location_id.name[:4] == 'LOC5':
- 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 ' '))
- elif device.current_location_id.name[:4] == 'LOC6':
- 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 ' '))
- elif device.current_location_id.name[:4] == 'LOC7':
- 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 ' '))
- else:
- 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 ' '))
- if not kw.get('id') is None:
- if len(beaudry) > 1 and ('1' in kw.get('id')):
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(beaudry):
- ret += beaudry[i]
- i += 1
- ret += '</table><br>'
- if len(thomas) > 1 and ('2' in kw.get('id')):
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(thomas):
- ret += thomas[i]
- i += 1
- ret += '</table>'
- if len(root) > 1 and ('3' in kw.get('id')):
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(root):
- ret += root[i]
- i += 1
- ret += '</table>'
- if len(champlain) > 1 and ('4' in kw.get('id')):
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(champlain):
- ret += champlain[i]
- i += 1
- ret += '</table>'
- if len(lanaudiere) > 1 and ('5' in kw.get('id')):
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(lanaudiere):
- ret += lanaudiere[i]
- i += 1
- ret += '</table>'
- if len(paul) > 1 and ('6' in kw.get('id')):
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(paul):
- ret += paul[i]
- i += 1
- ret += '</table>'
- if len(raoul) > 1 and ('7' in kw.get('id')):
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(raoul):
- ret += raoul[i]
- i += 1
- ret += '</table>'
- else:
- if len(beaudry) > 1:
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(beaudry):
- ret += beaudry[i]
- i += 1
- ret += '</table><br>'
- if len(thomas) > 1:
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(thomas) :
- ret += thomas[i]
- i += 1
- ret += '</table>'
- if len(root) > 1:
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(root):
- ret += root[i]
- i += 1
- ret += '</table>'
- if len(champlain) > 1:
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(champlain):
- ret += champlain[i]
- i += 1
- ret += '</table>'
- if len(lanaudiere) > 1:
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(lanaudiere):
- ret += lanaudiere[i]
- i += 1
- ret += '</table>'
- if len(paul) > 1:
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(paul):
- ret += paul[i]
- i += 1
- ret += '</table>'
- if len(raoul) > 1:
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(raoul):
- ret += raoul[i]
- i += 1
- ret += '</table>'
- if len(unknown) > 1:
- i = 0
- ret += '<table><th> Device </th><th> Location </th><th> Owner </th>'
- while i < len(unknown):
- ret += unknown[i]
- i += 1
- ret += '</table>'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement