Skip to content

Commit

Permalink
🙈 Hides GUIDs from list views (#122)
Browse files Browse the repository at this point in the history
* Removes GUIDs from list views

* Removes GUIDs from list views for Collections and Batches.
* Removes redundant ID from Batch detail view.

* Fixes actions docstrings

---------

Co-authored-by: Harpo <ryan_harbert@wgbh.org>
  • Loading branch information
afred and mrharpo authored Aug 23, 2023
1 parent 3cba93b commit 14a8602
Showing 1 changed file with 10 additions and 5 deletions.
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

0 comments on commit 14a8602

Please sign in to comment.