mirror of
https://github.com/YunoHost/yunorunner.git
synced 2024-09-03 20:05:52 +02:00
[mod] uses jinja2
This commit is contained in:
parent
1e453c29fc
commit
10a1bb3ef3
3 changed files with 18 additions and 7 deletions
|
@ -6,3 +6,4 @@ peewee
|
||||||
# cli
|
# cli
|
||||||
argh
|
argh
|
||||||
requests
|
requests
|
||||||
|
sanic-jinja2
|
||||||
|
|
22
run.py
22
run.py
|
@ -20,6 +20,8 @@ from sanic import Sanic, response
|
||||||
from sanic.exceptions import NotFound
|
from sanic.exceptions import NotFound
|
||||||
from sanic.log import LOGGING_CONFIG_DEFAULTS
|
from sanic.log import LOGGING_CONFIG_DEFAULTS
|
||||||
|
|
||||||
|
from sanic_jinja2 import SanicJinja2
|
||||||
|
|
||||||
from playhouse.shortcuts import model_to_dict, dict_to_model
|
from playhouse.shortcuts import model_to_dict, dict_to_model
|
||||||
|
|
||||||
from models import Repo, Job, db, Worker
|
from models import Repo, Job, db, Worker
|
||||||
|
@ -45,6 +47,16 @@ task_logger = logging.getLogger("task")
|
||||||
|
|
||||||
app = Sanic()
|
app = Sanic()
|
||||||
|
|
||||||
|
jinja = SanicJinja2(app)
|
||||||
|
|
||||||
|
# to avoid conflict with vue.js
|
||||||
|
jinja.env.block_start_string='<%'
|
||||||
|
jinja.env.block_end_string='%>'
|
||||||
|
jinja.env.variable_start_string='<{'
|
||||||
|
jinja.env.variable_end_string='}>'
|
||||||
|
jinja.env.comment_start_string='<#'
|
||||||
|
jinja.env.comment_end_string='#>'
|
||||||
|
|
||||||
APPS_LISTS = {
|
APPS_LISTS = {
|
||||||
"Official": "https://app.yunohost.org/official.json",
|
"Official": "https://app.yunohost.org/official.json",
|
||||||
"Community": "https://app.yunohost.org/community.json",
|
"Community": "https://app.yunohost.org/community.json",
|
||||||
|
@ -365,22 +377,20 @@ async def api_stop_job(request, job_id):
|
||||||
|
|
||||||
|
|
||||||
@app.route('/job/<job_id>')
|
@app.route('/job/<job_id>')
|
||||||
|
@jinja.template('job.html')
|
||||||
async def job(request, job_id):
|
async def job(request, job_id):
|
||||||
job = Job.select().where(Job.id == job_id)
|
job = Job.select().where(Job.id == job_id)
|
||||||
|
|
||||||
if job.count == 0:
|
if job.count == 0:
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
|
|
||||||
job = job[0]
|
return {"job": job[0]}
|
||||||
|
|
||||||
async with aiofiles.open("./templates/job.html", mode="r") as index_template:
|
|
||||||
return response.html(await index_template.read() % job.id)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
@jinja.template('index.html')
|
||||||
async def index(request):
|
async def index(request):
|
||||||
async with aiofiles.open("./templates/index.html", mode="r") as index_template:
|
return {}
|
||||||
return response.html(await index_template.read())
|
|
||||||
|
|
||||||
|
|
||||||
def main(path_to_analyseCI):
|
def main(path_to_analyseCI):
|
||||||
|
|
|
@ -404,7 +404,7 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ws = new WebSocket('ws://' + document.domain + ':' + location.port + '/job-%s-ws');
|
ws = new WebSocket('ws://' + document.domain + ':' + location.port + '/job-<{ job.id }>-ws');
|
||||||
|
|
||||||
ws.onmessage = function (event) {
|
ws.onmessage = function (event) {
|
||||||
var message = JSON.parse(event.data);
|
var message = JSON.parse(event.data);
|
||||||
|
|
Loading…
Add table
Reference in a new issue