Skip to content
Snippets Groups Projects
Commit 54f54982 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

Task #8887: added two methods to browse the tasks/claims in html tables.

parent 4079bf9b
No related branches found
No related tags found
No related merge requests found
...@@ -313,6 +313,137 @@ def getUpdateEvents(): ...@@ -313,6 +313,137 @@ def getUpdateEvents():
def getLofarTime(): def getLofarTime():
return jsonify({'lofarTime': asIsoFormat(datetime.utcnow())}) return jsonify({'lofarTime': asIsoFormat(datetime.utcnow())})
#ugly method to generate html tables for all tasks
@app.route('/tasks.html')
def getTasksHtml():
tasks = rarpc.getTasks()
if not tasks:
abort(404)
updateTaskMomDetails(tasks, momrpc)
html = '<!DOCTYPE html><html><head><title>Tasks</title><style>table, th, td {border: 1px solid black; border-collapse: collapse; padding: 4px;}</style></head><body><table style="width:100%">\n'
props = sorted(tasks[0].keys())
html += '<tr>%s</tr>\n' % ''.join('<th>%s</th>' % prop for prop in props)
for task in tasks:
html += '<tr>'
for prop in props:
if prop in task:
if prop == 'id':
html += '<td><a href="/rest/tasks/%s.html">%s</a></td> ' % (task[prop], task[prop])
else:
html += '<td>%s</td> ' % task[prop]
html += '</tr>\n'
html += '</table></body></html>\n'
return html
#ugly method to generate html tables for the task and it's claims
@app.route('/tasks/<int:task_id>.html', methods=['GET'])
def getTaskHtml(task_id):
task = rarpc.getTask(task_id)
if not task:
abort(404, 'No such task %s' % task_id)
task['name'] = 'Task %d' % task['id']
updateTaskMomDetails(task, momrpc)
html = '<!DOCTYPE html><html><head><title>Tasks</title><style>table, th, td {border: 1px solid black; border-collapse: collapse; padding: 4px;}</style></head><body><table style="">\n'
html += '<h1>Task %s</h1>' % task_id
props = sorted(task.keys())
html += '<tr><th>key</th><th>value</th></tr>\n'
for prop in props:
html += '<tr><td>%s</td>' % prop
if prop == 'id':
html += '<td><a href="/rest/tasks/%s.html">%s</a></td> ' % (task[prop], task[prop])
elif prop == 'predecessor_ids' or prop == 'successor_ids':
ids = task[prop]
if ids:
html += '<td>%s</td> ' % ', '.join('<a href="/rest/tasks/%s.html">%s</a>' % (id, id) for id in ids)
else:
html += '<td></td> '
else:
html += '<td>%s</td> ' % task[prop]
html += '</tr>'
html += '</table>\n<br>'
claims = rarpc.getResourceClaims(task_ids=[task_id], extended=True, include_properties=True)
if claims:
html += '<h1>Claims</h1>'
for claim in claims:
html += '<table>'
for claim_key,claim_value in claim.items():
if claim_key == 'properties':
html += '<tr><td>properties</td><td><table>'
if claim_value:
propnames = sorted(claim_value[0].keys())
html += '<tr>%s</tr>\n' % ''.join('<th>%s</th>' % propname for propname in propnames)
for prop in claim_value:
html += '<tr>%s</tr>\n' % ''.join('<td>%s</td>' % prop[propname] for propname in propnames)
html += '</table></td></tr>'
elif claim_key == 'saps':
html += '<tr><td>saps</td><td><table>'
saps = claim_value
if saps:
sap_keys = ['sap_nr', 'properties']
html += '<tr>%s</tr>\n' % ''.join('<th>%s</th>' % sap_key for sap_key in sap_keys)
for sap in saps:
html += '<tr>'
for sap_key in sap_keys:
if sap_key == 'properties':
html += '<td><table>'
sap_props = sap[sap_key]
if sap_props:
propnames = sorted(sap_props[0].keys())
html += '<tr>%s</tr>\n' % ''.join('<th>%s</th>' % propname for propname in propnames)
for prop in sap_props:
html += '<tr>%s</tr>\n' % ''.join('<td>%s</td>' % prop[propname] for propname in propnames)
html += '</table></td>'
else:
html += '<td>%s</td>' % (sap[sap_key])
html += '</tr>'
html += '</table></td></tr>'
else:
html += '<tr><td>%s</td><td>%s</td></tr>' % (claim_key,claim_value)
html += '</table>'
html += '<br>'
html += '</body></html>\n'
return html
@app.route('/rest/tasks/<int:task_id>/resourceclaims.html', methods=['GET'])
@gzipped
def resourceClaimsForTaskHtml(task_id):
claims = rarpc.getResourceClaims(task_ids=[task_id], extended=True, include_properties=True)
if not claims:
abort(404, 'No resource claims for task %s' % task_id)
html = '<!DOCTYPE html><html><head><title>Tasks</title><style>table, th, td {border: 1px solid black; border-collapse: collapse; padding: 4px;}</style></head><body><table style="">\n'
for claim in claims:
html += '<tr><td>%s</td>' % claim
html += '</table></body></html>\n'
return html
def main(): def main():
# make sure we run in UTC timezone # make sure we run in UTC timezone
import os import os
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment