Skip to content

Commit

Permalink
Merge pull request #5 from charliettaylor/charlie/admin-stuff
Browse files Browse the repository at this point in the history
Update admin page, fix winner bug
  • Loading branch information
AaronLieb authored Oct 15, 2024
2 parents c4dd58c + f50c941 commit 2b0d056
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion database.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ def set_winner(self, pic_id: int):
if pic is None:
return None

pic.winner = ~pic.winner # pyright: ignore [reportAttributeAccessIssue]
pic.winner = not pic.winner # pyright: ignore [reportAttributeAccessIssue]
self.db.commit()
return pic
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Annotated

from fastapi import Cookie, FastAPI, Form, HTTPException, Request, Response
from fastapi.responses import HTMLResponse
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from twilio.request_validator import RequestValidator
Expand Down Expand Up @@ -212,7 +212,7 @@ def set_winner(pic_id: int, password: Annotated[str | None, Cookie()] = None):
raise HTTPException(status_code=401, detail="Unauthorized")

if db.set_winner(pic_id) is not None:
return "Winner set"
return RedirectResponse(url="/admin", status_code=303)

raise HTTPException(status_code=404, detail="Pic not found")

Expand Down
48 changes: 30 additions & 18 deletions templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,41 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/static/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
<title>Admin Portal</title>
</head>

<body>
<h1>Admin Shit</h1>
<header class="container">
<hgroup>
<h1>Admin Shit</h1>
</hgroup>
</header>
<main class="container">
<section>
<div class="grid">
<input type="text" id="prompt" placeholder="Send prompt" name="prompt" />
<button type="submit">Send</button>
</div>
</section>
<section>
<h2>Editor's Choice</h2>
<ul style="list-style-type: none;">
{% for prompt in prompts %}
<li>
<a href="{{prompt.url}}">
{{prompt.id}} - {{prompt.prompt}}
</a>
</li>
{% endfor %}
</ul>

<ul>
<li>
Send prompt: <input type="text" id="prompt" name="prompt" /> <button>Send</button>
</li>
<li>Other stuff...</li>
</ul>

Select winners:
<ul>
{% for prompt in prompts %}
<li>
<a href="{{prompt.url}}">
{{prompt.id}} - {{prompt.prompt}}
</a>
</li>
{% endfor %}
</ul>
</section>
</main>
<footer class="container">
<small>Made by Charlie and Aaron</small>
</footer>
</body>

</html>

0 comments on commit 2b0d056

Please sign in to comment.