~edwargix/git.sr.ht

1d8109ca5712f7a3eccd9f1d089ee716cc64458e — Simon Ser 2 years ago d768598
Allow uploading multiple artifacts at once

Useful to upload both the tarball and the PGP signature at once,
for instance.

For some reason getlist returns a non-empty list even if the user
selects no file. If the user selects one or multiple files, it
behaves as expected. That's why len(file_list) isn't used for
validation.
2 files changed, 10 insertions(+), 8 deletions(-)

M gitsrht/blueprints/artifacts.py
M gitsrht/templates/ref.html
M gitsrht/blueprints/artifacts.py => gitsrht/blueprints/artifacts.py +9 -8
@@ 38,20 38,21 @@ def ref_upload(owner, repo, ref):
        else:
            target = tag.target.hex
        valid = Validation(request)
        f = request.files.get("file")
        valid.expect(f, "File is required", field="file")
        valid.expect(request.files.get("file"), "File is required", field="file")
        file_list = request.files.getlist("file")
        default_branch = git_repo.default_branch()
        if not valid.ok:
            return render_template("ref.html", view="refs",
                    owner=owner, repo=repo, git_repo=git_repo, tag=tag,
                    strip_pgp_signature=strip_pgp_signature,
                    default_branch=default_branch, **valid.kwargs)
        artifact = upload_artifact(valid, repo, target, f, f.filename)
        if not valid.ok:
            return render_template("ref.html", view="refs",
                    owner=owner, repo=repo, git_repo=git_repo, tag=tag,
                    strip_pgp_signature=strip_pgp_signature,
                    default_branch=default_branch, **valid.kwargs)
        for f in file_list:
            artifact = upload_artifact(valid, repo, target, f, f.filename)
            if not valid.ok:
                return render_template("ref.html", view="refs",
                        owner=owner, repo=repo, git_repo=git_repo, tag=tag,
                        strip_pgp_signature=strip_pgp_signature,
                        default_branch=default_branch, **valid.kwargs)
        db.session.commit()
        return redirect(url_for("repo.ref",
            owner=owner.canonical_name,

M gitsrht/templates/ref.html => gitsrht/templates/ref.html +1 -0
@@ 83,6 83,7 @@
            type="file"
            name="file"
            id="file"
            multiple
            class="form-control {{valid.cls("file")}}" />
          {{valid.summary("file")}}
        </div>