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

replace inline styles with gui.styled() #565

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
94 changes: 30 additions & 64 deletions daras_ai_v2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,20 +484,10 @@ def _render_options_button_with_dialog(self):
self._unsaved_options_modal()

def render_social_buttons(self):
with gui.div(
className="d-flex align-items-start right-action-icons gap-lg-2 gap-1"
with (
gui.styled("& .btn { padding: 6px }"),
gui.div(className="d-flex align-items-start gap-lg-2 gap-1"),
):
gui.html(
# styling for buttons in this div
"""
<style>
.right-action-icons .btn {
padding: 6px;
}
</style>
""".strip()
)

if self.tab == RecipeTabs.run:
if self.request.user and not self.request.user.is_anonymous:
self._render_options_button_with_dialog()
Expand Down Expand Up @@ -625,17 +615,6 @@ def _render_workspace_with_invite_button(self, workspace: Workspace):

def _render_save_button(self):
with gui.div(className="d-flex justify-content-end"):
gui.html(
"""
<style>
.save-button-menu .gui-input label p { color: black; }
.published-options-menu {
z-index: 1;
}
</style>
"""
)

if self.can_user_edit_published_run(self.current_pr):
icon, label = icons.save, "Update"
elif self._has_request_changed():
Expand Down Expand Up @@ -1173,15 +1152,6 @@ def _render_version_row(
version: PublishedRunVersion,
older_version: PublishedRunVersion | None,
):
gui.html(
"""
<style>
.disable-p-margin p {
margin-bottom: 0;
}
</style>
"""
)
url = self.app_url(
example_id=version.published_run.published_run_id,
run_id=version.saved_run.run_id,
Expand All @@ -1197,7 +1167,7 @@ def _render_version_row(
version.changed_by, responsive=False, show_as_link=False
)
else:
gui.write("###### Deleted User", className="disable-p-margin")
gui.write("###### Deleted User", className="container-margin-reset")
with gui.tag("h6", className="mb-0"):
gui.html(
"Loading...",
Expand All @@ -1206,7 +1176,7 @@ def _render_version_row(
date_options={"month": "short", "day": "numeric"},
),
)
with gui.div(className="disable-p-margin"):
with gui.div(className="container-margin-reset"):
is_first_version = not older_version
if is_first_version:
with gui.tag("span", className="badge bg-secondary px-3"):
Expand Down Expand Up @@ -1569,40 +1539,36 @@ def _render_author(
if not photo and not name:
return

responsive_image_size = (
f"calc({image_size} * 0.67)" if responsive else image_size
)

# new class name so that different ones don't conflict
class_name = f"author-image-{image_size}"
if responsive:
class_name += "-responsive"
responsive_image_size = f"calc({image_size} * 0.67)"
else:
responsive_image_size = image_size

linkto = link and gui.link(to=link) or gui.dummy()
with linkto, gui.div(className="d-flex align-items-center"):
if photo:
gui.html(
f"""
<style>
.{class_name} {{
width: {responsive_image_size};
height: {responsive_image_size};
margin-right: 6px;
border-radius: 50%;
object-fit: cover;
pointer-events: none;
}}

@media (min-width: 1024px) {{
.{class_name} {{
width: {image_size};
height: {image_size};
}}
}}
</style>
"""
)
gui.image(photo, className=class_name)
with gui.styled(
"""
@media (min-width: 1024px) {
& {
width: %(image_size)s;
height: %(image_size)s;
}
}
"""
% dict(image_size=image_size)
):
gui.image(
photo,
style=dict(
width=responsive_image_size,
height=responsive_image_size,
marginRight="6px",
borderRadius="50%",
objectFit="cover",
pointerEvents="none",
),
)

if name:
name_style = {"fontSize": text_size} if text_size else {}
Expand Down
27 changes: 13 additions & 14 deletions daras_ai_v2/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,27 @@ def has_breadcrumbs(self):


def render_breadcrumbs(breadcrumbs: TitleBreadCrumbs, *, is_api_call: bool = False):
gui.html(
"""
<style>
@media (min-width: 1024px) {
.fs-lg-5 {
font-size: 1.25rem !important;
}
}
</style>
"""
)

if not (breadcrumbs.root_title or breadcrumbs.published_title):
# avoid empty space when breadcrumbs are not rendered
return

with gui.breadcrumbs():
with (
gui.styled(
"""
@media (min-width: 1024px) {
& a {
font-size: 1.25rem !important;
}
}
"""
),
gui.breadcrumbs(),
):
if breadcrumbs.root_title:
gui.breadcrumb_item(
breadcrumbs.root_title.title,
link_to=breadcrumbs.root_title.url,
className="text-muted fs-lg-5",
className="text-muted",
)
if breadcrumbs.published_title:
gui.breadcrumb_item(
Expand Down
15 changes: 11 additions & 4 deletions daras_ai_v2/variables_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,17 @@ def render_list_item(
gui.write(f"**{value_type}**", className="text-muted small")

if schema.get("role") == "system":
gui.caption(
gui.write(
"System provided",
help="This variable is automatically provided by the system. ",
className="text-muted small",
)
if is_template_var:
gui.caption(
gui.write(
"Template variable",
help="Your instruction or other prompts reference this variable. "
"Add a value and tap Run to test a sample value.",
className="text-muted small",
)

gui.div(className="flex-grow-1")
Expand All @@ -188,9 +190,14 @@ def render_list_item(
key=dialog_ref.open_btn_key,
)

item["value"] = json_value_editor(entry_key, value, value_type)
with (
gui.styled(".gui-input:has(&) { margin-bottom: 0 }")
if description
else gui.dummy()
):
item["value"] = json_value_editor(entry_key, value, value_type)

gui.caption(description, style=dict(marginTop="-5px", display="relative"))
gui.markdown(description, className="text-muted small")


def json_value_editor(entry_key: str, value, value_type: "JsonTypes"):
Expand Down
17 changes: 15 additions & 2 deletions workspaces/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.contrib import admin
from django.db.models import Sum
from django.db.models import Sum, Q
from safedelete.admin import SafeDeleteAdmin, SafeDeleteAdminFilter

from bots.admin_links import change_obj_url, open_in_new_tab
from payments.models import Subscription
from usage_costs.models import UsageCost
from . import models

Expand Down Expand Up @@ -85,7 +86,19 @@ class WorkspaceAdmin(SafeDeleteAdmin):
]
inlines = [WorkspaceMembershipInline, WorkspaceInviteInline]
ordering = ["-created_at"]
autocomplete_fields = ["created_by", "subscription"]
autocomplete_fields = ["created_by"]

def get_form(self, request, obj=None, change=False, **kwargs):
self.obj = obj
return super().get_form(request, obj, change, **kwargs)

def formfield_for_foreignkey(self, db_field, request, **kwargs):
field = super().formfield_for_foreignkey(db_field, request, **kwargs)
if db_field.name == "subscription" and self.obj:
kwargs["queryset"] = Subscription.objects.filter(
Q(workspace=self.obj) | Q(workspace__isnull=True)
)[:10]
return field

@admin.display(description="Name")
def display_name(self, workspace: models.Workspace):
Expand Down
Loading