-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (50 loc) · 1.45 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from flask import Flask, render_template, abort, jsonify, redirect
from jinja2 import Markup
from db import App
import web
import markdown
from tasks import TASKS, Site
app = Flask(__name__)
def markdown_to_html(md):
return Markup(markdown.markdown(md))
@app.context_processor
def app_context():
return {
"datestr": web.datestr,
"markdown_to_html": markdown_to_html,
}
@app.route("/")
def home():
apps = App.find_all()
internal_users = ["nikochiko", "anandology", "pipalacademy"]
apps = [app for app in apps if app.name not in internal_users]
return render_template("index.html", apps=apps)
@app.route("/<name>")
def app_page(name):
app = App.find(name)
if not app:
abort(404)
if app.name != name:
return redirect(f"/{app.name}")
site = Site(app.name)
status = site.get_status()
app.update_status(status)
return render_template("app.html", app=app, tasks=TASKS)
@app.route("/<name>/deploy", methods=["POST"])
def app_deploy(name):
app = App.find(name)
if not app:
Site(name).create()
app = App.create(name)
site = Site(app.name)
sync_status = site.sync()
if not sync_status.ok:
return jsonify({
"error": "deployment failed to sync",
"message": sync_status.message
}), 500
status = site.get_status()
app.update_status(status)
return jsonify(status)
if __name__ == "__main__":
app.run(port=5050)