From c3d8d6e45db1ef4e5c44839cf19cc822c0c9f2bc Mon Sep 17 00:00:00 2001 From: Kaustubh Maske Patil <37668193+nikochiko@users.noreply.github.com> Date: Thu, 14 Dec 2023 20:57:03 +0530 Subject: [PATCH] Add private/public pills for visibility --- bots/models.py | 28 ++++++++++++++++++++++++++++ daras_ai_v2/base.py | 12 ++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/bots/models.py b/bots/models.py index c956470ae..896446c97 100644 --- a/bots/models.py +++ b/bots/models.py @@ -3,6 +3,7 @@ import datetime import typing from multiprocessing.pool import ThreadPool +from textwrap import dedent import pytz from django.conf import settings @@ -44,6 +45,33 @@ def help_text(self): case _: return self.label + def get_badge_html(self): + badge_container_class = ( + "text-sm bg-light border border-dark rounded-pill px-2 py-1" + ) + + match self: + case PublishedRunVisibility.UNLISTED: + return dedent( + f"""\ + + + Private + + """ + ) + case PublishedRunVisibility.PUBLIC: + return dedent( + f"""\ + + + Public + + """ + ) + case _: + raise NotImplementedError(self) + class Platform(models.IntegerChoices): FACEBOOK = 1 diff --git a/daras_ai_v2/base.py b/daras_ai_v2/base.py index ea7ac459d..cf9e6ac1f 100644 --- a/daras_ai_v2/base.py +++ b/daras_ai_v2/base.py @@ -1633,12 +1633,12 @@ def _render_run_preview(self, saved_run: SavedRun): ) with st.link(to=saved_run.get_app_url(), className="text-decoration-none"): - with st.tag("span", className="badge bg-secondary px-4 py-2 mb-2 lead"): + with st.div(className="mb-1", style={"font-size": "0.9rem"}): if is_latest_version: st.html( - PublishedRunVisibility(published_run.visibility) - .help_text() - .upper() + PublishedRunVisibility( + published_run.visibility + ).get_badge_html() ) st.write(f"#### {title}") @@ -1661,9 +1661,9 @@ def _render_published_run_preview(self, published_run: PublishedRun): ) with st.link(to=published_run.get_app_url(), className="text-decoration-none"): - with st.tag("span", className="badge bg-secondary px-4 py-2 mb-2"): + with st.div(className="mb-1", style={"font-size": "0.9rem"}): st.html( - PublishedRunVisibility(published_run.visibility).help_text().upper() + PublishedRunVisibility(published_run.visibility).get_badge_html() ) st.write(f"#### {title}")