Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenGraph stuff, show last prompt's winner #4

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ def get_pics_by_prompt(self, prompt_id: int) -> List[Pic]:
.order_by(Pic.winner.desc())
)

def get_winner_by_prompt(self, prompt_id: int) -> List[Pic]:
return (
self.db.query(Pic)
.filter(Pic.prompt == prompt_id, Pic.winner == True)
.first()
)

def get_submission_status(self, user_hash: str, prompt_id: int) -> bool:
user = self.get_user_by_hash(user_hash)
print(user_hash)
Expand Down
15 changes: 13 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ def images_page(

date_str = prompt.date.strftime("%b %-d, %Y")

og = {"display": False}
winner = db.get_winner_by_prompt(n - 1)
if winner is not None:
og["display"] = True
og["url"] = winner.url

return templates.TemplateResponse(
request=request,
name="gallery.html",
context={"pics": pics, "prompt": prompt.prompt, "date": date_str},
context={"pics": pics, "prompt": prompt.prompt, "date": date_str, "og": og},
)


Expand Down Expand Up @@ -174,7 +180,12 @@ def winner_admin_page(
return templates.TemplateResponse(
request=request,
name="gallery.html",
context={"pics": pics, "prompt": prompt.prompt, "date": date_str},
context={
"pics": pics,
"prompt": prompt.prompt,
"date": date_str,
"og": {"display": False},
},
)


Expand Down
8 changes: 8 additions & 0 deletions templates/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
@import url('https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,300;0,400;0,700;0,900;1,300;1,400;1,700;1,900&display=swap');
</style>
<title>Snapshot</title>
<meta property="og:type" content="website">
<meta property="og:title" content="Snapshot 📸">
{% if og.display %}
<meta property="og:description" content="Click to see snapshots for '{{prompt}}'. Editor's choice for last prompt shown here!">
<meta property="og:image" content="{{og.url}}">
{% else %}
<meta property="og:description" content="Click to see snapshots for '{{prompt}}'">
{% endif %}
</head>

<body>
Expand Down
Loading