Skip to content

Commit

Permalink
Merge pull request #4 from charliettaylor/charlie/previews
Browse files Browse the repository at this point in the history
Add OpenGraph stuff, show last prompt's winner
  • Loading branch information
AaronLieb authored Sep 27, 2024
2 parents b3c53ab + 68bb29b commit 2e91608
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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

0 comments on commit 2e91608

Please sign in to comment.