~comcloudway/builds.sr.ht

2c42f17cd903acda0ced1c5400d968e86aa21a7f — Noelle Leigh 3 years ago fa6c46f
Preserve job note upon resubmission

When the user clicks on "Edit & resubmit", the note associated with the
previous build will prepopulate the "Add Note" field with
"(resubmitted)" as a suffix.
2 files changed, 24 insertions(+), 6 deletions(-)

M buildsrht/blueprints/jobs.py
M buildsrht/templates/submit.html
M buildsrht/blueprints/jobs.py => buildsrht/blueprints/jobs.py +22 -5
@@ 20,6 20,7 @@ import hashlib
import requests
import yaml
import json
import textwrap

jobs = Blueprint("jobs", __name__)



@@ 164,22 165,37 @@ def index():
            Job.query.filter(Job.owner_id == current_user.id),
            "index.html", rss_feed=rss_feed)


@jobs.route("/submit")
@loginrequired
def submit_GET():
    manifest = session.get("manifest")
    if manifest:
        del session["manifest"]
    else:
        manifest = request.args.get("manifest")
    manifest = session.pop("manifest")
    note = session.pop("note")
    status = 200
    payment_required = requires_payment(current_user)
    if payment_required:
        status = 402
    return render_template("submit.html",
            manifest=manifest,
            note=note,
            payment_required=payment_required), status

def addsuffix(note: str, suffix: str) -> str:
    """
    Given a note and a suffix, return the note with the suffix concatenated/

    The returned string is guaranteed to fit in the Job.note DB field.
    """
    maxlen = Job.note.prop.columns[0].type.length
    assert len(suffix) + 1 <= maxlen, f"Suffix was too long ({len(suffix)})"
    if note.endswith(suffix):
        return note
    result = f"{note} {suffix}"
    if len(result) <= maxlen:
        return result
    note = textwrap.shorten(note, maxlen - len(suffix) - 1, placeholder="…")
    return f"{note} {suffix}"

@jobs.route("/resubmit/<int:job_id>")
@loginrequired
def resubmit_GET(job_id):


@@ 187,6 203,7 @@ def resubmit_GET(job_id):
    if not job:
        abort(404)
    session["manifest"] = job.manifest
    session["note"] = addsuffix(job.note, "(resubmitted)")
    return redirect("/submit")

@jobs.route("/submit", methods=["POST"])

M buildsrht/templates/submit.html => buildsrht/templates/submit.html +2 -1
@@ 67,7 67,8 @@
        class="form-control"
        id="note"
        name="note"
        placeholder="Submitted on the web" />
        placeholder="Submitted on the web"
        value="{{note if note else ""}}" />
    </div>
    <div class="form-group">
      <a