diff --git a/database.py b/database.py index 669d385..67a055a 100644 --- a/database.py +++ b/database.py @@ -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) diff --git a/main.py b/main.py index f3dc085..1f0b471 100644 --- a/main.py +++ b/main.py @@ -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}, ) @@ -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}, + }, ) diff --git a/templates/gallery.html b/templates/gallery.html index 3122cea..94435f5 100644 --- a/templates/gallery.html +++ b/templates/gallery.html @@ -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'); Snapshot + + + {% if og.display %} + + + {% else %} + + {% endif %}