Improve new screenshot behaviour

This commit is contained in:
rubenwardy 2020-12-06 04:07:51 +00:00
parent f93a2d8717
commit 4226e945e6
3 changed files with 19 additions and 6 deletions

@ -45,6 +45,9 @@ def screenshots(package):
if not package.checkPerm(current_user, Permission.ADD_SCREENSHOTS):
return redirect(package.getDetailsURL())
if package.screenshots.count() == 0:
return redirect(package.getNewScreenshotURL())
if request.method == "POST":
order = request.form.get("order")
if order:
@ -76,11 +79,17 @@ def create_screenshot(package):
uploadedUrl, uploadedPath = doFileUpload(form.fileUpload.data, "image",
"a PNG or JPG image file")
if uploadedUrl is not None:
counter = 1
for screenshot in package.screenshots:
screenshot.order = counter
counter += 1
ss = PackageScreenshot()
ss.package = package
ss.title = form["title"].data or "Untitled"
ss.url = uploadedUrl
ss.approved = package.checkPerm(current_user, Permission.APPROVE_SCREENSHOT)
ss.order = counter
db.session.add(ss)
msg = "Screenshot added {}" \

@ -37,13 +37,17 @@
</div>
</li>
{% endif %}
{% else %}
<li class="list-group-item">
<i>No screenshots.</i>
</li>
{% endfor %}
</ul>
<form action="" method="POST" class="form mt-4" role="form">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="order" value="" />
<input type="submit" value="{{ _("Update Order") }}" class="btn btn-primary">
<input type="submit" value="{{ _("Save Order") }}" class="btn btn-primary">
</form>
<noscript>

@ -28,10 +28,10 @@
<main>
<header class="jumbotron pb-3"
style="background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.7)), url('{{ package.getMainScreenshotURL() }}');
background-size: cover;
background-repeat: no-repeat;
background-position: center;">
style="background: linear-gradient(rgba(0, 0, 0, 0.4), rgba(0, 0, 0, 0.7)), url('{{ package.getMainScreenshotURL() }}');
background-size: cover;
background-repeat: no-repeat;
background-position: center;">
<div class="container">
<h1 class="display-3">
{{ package.title }}
@ -382,7 +382,7 @@
{% if package.checkPerm(current_user, "ADD_SCREENSHOTS") %}
<a href="{{ package.getEditScreenshotsURL() }}" class="btn btn-primary float-right">
<i class="fas fa-edit"></i>
<i class="fas fa-images mr-1"></i>
Edit
</a>
{% endif %}