~sircmpwn/dispatch.sr.ht

ref: e4b9f89a68a4cda43fb2c239a8b0ebc5b8eee0c3 dispatch.sr.ht/dispatchsrht/blueprints/html.py -rw-r--r-- 2.2 KiB View raw
e4b9f89a — √Čloi Rivard Define 'make' program via an environment variable 1 year, 13 days ago
                                                                                
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
60
61
62
63
64
65
66
67
68
69
70
71
72
from flask import Blueprint, render_template, request, redirect, url_for, abort
from flask_login import current_user
from srht.config import cfg
from srht.database import db
from srht.flask import loginrequired, paginate_query
from dispatchsrht.types import Task
import requests

html = Blueprint('html', __name__)

@html.route("/")
def index():
    if not current_user:
        return render_template("index.html")
    tasks = Task.query.filter(Task.user_id == current_user.id)
    search = request.args.get("search")
    if search:
        tasks = tasks.filter(Task.name.ilike("%" + search + "%"))
    tasks = tasks.order_by(Task.updated.desc())
    tasks, pagination = paginate_query(tasks)
    return render_template("dashboard.html",
            tasks=tasks, search=search, **pagination)

@html.route("/configure")
@loginrequired
def configure():
    return render_template("configure.html")

@html.route("/edit/<task_id>")
@loginrequired
def edit_task(task_id):
    task = Task.query.filter(Task.id == task_id).one_or_none()
    if not task:
        abort(404)
    if task.user_id != current_user.id:
        abort(401)
    taskdef = task.taskdef
    return render_template("task-settings.html", view="summary",
            task=task, taskdef=taskdef)

@html.route("/edit/<task_id>", methods=["POST"])
@loginrequired
def edit_task_POST(task_id):
    task = Task.query.filter(Task.id == task_id).one_or_none()
    if not task:
        abort(404)
    if task.user_id != current_user.id:
        abort(401)
    taskdef = task.taskdef
    return taskdef.edit_POST(task)

@html.route("/delete/<task_id>")
@loginrequired
def delete_task(task_id):
    task = Task.query.filter(Task.id == task_id).one_or_none()
    if not task:
        abort(404)
    if task.user_id != current_user.id:
        abort(401)
    return render_template("task-delete.html", view="delete", task=task)

@html.route("/delete/<task_id>", methods=["POST"])
@loginrequired
def delete_task_POST(task_id):
    task = Task.query.filter(Task.id == task_id).one_or_none()
    if not task:
        abort(404)
    if task.user_id != current_user.id:
        abort(401)
    db.session.delete(task)
    db.session.commit()
    return redirect(url_for("html.index"))