added gallery

This commit is contained in:
iou1name 2019-10-06 18:11:48 -04:00
parent 6d005d3ad4
commit 16a4e2dc9f
4 changed files with 79 additions and 5 deletions

View File

@ -68,6 +68,22 @@ async def index(request):
return render_template("result.html", request, locals())
@routes.get('/gallery/{user_id}', name='gallery')
async def gallery(request):
"""A user's gallery page."""
try:
user_id = int(request.match_info['user_id'])
except ValueError:
raise web.HTTPNotFound
async with request.app['pool'] as conn:
uploads = await conn.fetch(
"SELECT * FROM upload WHERE user_id = $1",
user_id)
upload_url = config.upload_url
return render_template("gallery.html", request, locals())
def handle_filefield(filefield, rand_name=True):
"""Handles a posted file."""
filename = safe_filename(filefield.filename)

View File

@ -1,6 +1,6 @@
body {
margin-left: 10%;
margin-right: 10%;
margin-left: 0;
margin-right: 0;
background-color: lightcoral;
font-family: Helvetica,sans-serif;
font-size: 14px;
@ -8,6 +8,11 @@ body {
header {
margin-bottom: 3em;
}
#logo_line {
margin-left: 10%;
margin-bottom: 0.5em;
display: flex;
}
@ -16,8 +21,33 @@ header {
margin-right: 1em;
}
nav {
padding-left: 10%;
display: flex;
background-color: whitesmoke;
border-top: 1px solid darkgray;
border-bottom: 1px solid darkgray;
}
nav span {
padding: 0.5em;
}
nav span:hover {
background-color: lightgray;
transition: 0.1s;
}
nav a {
padding: 0.5em;
text-decoration: none;
color: black;
}
main {
display: grid;
margin-left: 10%;
margin-right: 10%;
}
section {

25
templates/gallery.html Normal file
View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Saddle - Gallery</title>
<link rel="stylesheet" type="text/css" href="/static/saddle.css">
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<meta name="description" content="A file upload service.">
</head>
<body>
<header>
<h1>Saddle</h1>
</header>
<main>
<section>
<table>
{% for upload in uploads %}
<tr>
<td><a href="{{ upload_url + upload['filename'] }}">{{ upload['filename'] }}</a></td>
</tr>
{% endfor %}
</table>
</section>
</main>
</body>
</html>

View File

@ -8,8 +8,11 @@
</head>
<body>
<header>
<object id="logo" title="Saddle Logo" data="/static/saddle.svg"></object>
<h1>Saddle</h1>
<div id="logo_line">
<object id="logo" title="Saddle Logo" data="/static/saddle.svg"></object>
<h1>Saddle</h1>
</div>
<nav><span><a href="./gallery/{{ request.cookies.get('userid') }}">Gallery</a></span></nav>
</header>
<main>
<section>