Make a nice table and clean up.
This commit is contained in:
		
							
								
								
									
										14
									
								
								app.py
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								app.py
									
									
									
									
									
								
							@@ -2,6 +2,7 @@
 | 
				
			|||||||
from flask import Flask, jsonify, abort, make_response, request, render_template
 | 
					from flask import Flask, jsonify, abort, make_response, request, render_template
 | 
				
			||||||
from flask_httpauth import HTTPBasicAuth
 | 
					from flask_httpauth import HTTPBasicAuth
 | 
				
			||||||
import datetime
 | 
					import datetime
 | 
				
			||||||
 | 
					import humanfriendly
 | 
				
			||||||
 | 
					
 | 
				
			||||||
auth = HTTPBasicAuth()
 | 
					auth = HTTPBasicAuth()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -49,13 +50,16 @@ def create_status():
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    return jsonify({'status': status}), 201
 | 
					    return jsonify({'status': status}), 201
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@app.route('/', methods=['GET'])
 | 
					@app.route('/raw', methods=['GET'])
 | 
				
			||||||
def get_statuses():
 | 
					def get_statuses_raw():
 | 
				
			||||||
    return jsonify({'statuses': statuses[::-1]})
 | 
					    return jsonify({'statuses': statuses[::-1]})
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@app.route('/list', methods=['GET'])
 | 
					@app.route('/', methods=['GET'])
 | 
				
			||||||
def list():
 | 
					def get_statuses():
 | 
				
			||||||
    return render_template("list.html", statuses = statuses[::-1])
 | 
					    long_agos = [humanfriendly.format_timespan(datetime.datetime.now().timestamp() - status['timestamp']) for status in statuses[::-1]]
 | 
				
			||||||
 | 
					    return render_template("list.html", 
 | 
				
			||||||
 | 
					                            statuses = statuses[::-1],
 | 
				
			||||||
 | 
					                            long_agos = long_agos)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@app.errorhandler(404)
 | 
					@app.errorhandler(404)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										3
									
								
								static/css/style.css
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								static/css/style.css
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					.statuses tr td {
 | 
				
			||||||
 | 
					  border: 1px solid black;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,6 +1,19 @@
 | 
				
			|||||||
<ul class="statuses">
 | 
					<html>
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					<link href="/static/css/style.css" rel="stylesheet">
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<table class = "statuses">
 | 
				
			||||||
 | 
					<tr><th>What Happened?</th><th>When Did It Happen?</th><th>How Long Has It Been?</th></tr>
 | 
				
			||||||
  {% for status in statuses %}
 | 
					  {% for status in statuses %}
 | 
				
			||||||
  <li> {{ status.title }}
 | 
					  <tr>
 | 
				
			||||||
  </li>
 | 
					  <td>{{ status.title }}</td><td>{{ status.timestamp_readable }}</td><td>{{ long_agos[loop.index0] }}</td>
 | 
				
			||||||
 | 
					  </tr>
 | 
				
			||||||
    {% endfor %}
 | 
					    {% endfor %}
 | 
				
			||||||
</ul>
 | 
					</table>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user