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

🙈 Hides GUIDs from list views #122

Merged
merged 3 commits into from
Aug 23, 2023
Merged
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
15 changes: 10 additions & 5 deletions chowda/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
from metaflow.exception import MetaflowNotFound
from metaflow.integrations import ArgoEvent
from sqlmodel import Session, select
from starlette.datastructures import FormData
from starlette.requests import Request
from starlette.responses import Response
from starlette.templating import Jinja2Templates
from starlette.datastructures import FormData
from starlette_admin import CustomView, action
from starlette_admin.fields import IntegerField, TextAreaField
from starlette_admin._types import RequestAction
from starlette_admin.contrib.sqlmodel import ModelView
from starlette_admin.exceptions import ActionFailed
from starlette_admin.fields import IntegerField, TextAreaField

from chowda.auth.utils import get_user
from chowda.db import engine
from chowda.models import Batch
from chowda.models import Batch, Collection
from chowda.utils import validate_media_file_guids


Expand Down Expand Up @@ -90,6 +90,9 @@ def can_edit(self, request: Request) -> bool:


class CollectionView(BaseModelView):
exclude_fields_from_list: ClassVar[list[Any]] = [Collection.media_files]
exclude_fields_from_detail: ClassVar[list[Any]] = [Collection.id]

fields: ClassVar[list[Any]] = [
'name',
'description',
Expand All @@ -116,6 +119,8 @@ async def validate(self, request: Request, data: Dict[str, Any]):
class BatchView(BaseModelView):
exclude_fields_from_create: ClassVar[list[Any]] = [Batch.id]
exclude_fields_from_edit: ClassVar[list[Any]] = [Batch.id]
exclude_fields_from_list: ClassVar[list[Any]] = [Batch.media_files]
exclude_fields_from_detail: ClassVar[list[Any]] = [Batch.id]

actions: ClassVar[list[Any]] = [
'start_batches',
Expand Down Expand Up @@ -184,7 +189,7 @@ async def start_batches(self, request: Request, pks: List[Any]) -> str:
submit_btn_class='btn-success',
)
async def duplicate_batches(self, request: Request, pks: List[Any]) -> str:
"""Starts a Batch by sending a message to the Argo Event Bus"""
"""Create a new batch from the selected batch"""
try:
with Session(engine) as db:
for batch_id in pks:
Expand All @@ -211,7 +216,7 @@ async def duplicate_batches(self, request: Request, pks: List[Any]) -> str:
submit_btn_class='btn-success',
)
async def combine_batches(self, request: Request, pks: List[Any]) -> str:
"""Starts a Batch by sending a message to the Argo Event Bus"""
"""Merge multiple batches into a new batch"""
try:
with Session(engine) as db:
batches = db.exec(select(Batch).where(Batch.id.in_(pks))).all()
Expand Down