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

🧮 Fixes MediaFileCount field #125

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
38 changes: 11 additions & 27 deletions chowda/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ async def serialize_value(
class MediaFileCount(IntegerField):
"""A field that displays the number of MediaFiles in a collection or batch"""

exclude_from_create: bool = True
name: str = 'media_file_count'
label: str = 'Size'
read_only: bool = True
exclude_from_edit: bool = True
exclude_from_create: bool = True

render_function_key: str = 'media_file_count'
display_template: str = 'displays/media_file_count.html'

async def serialize_value(
self, request: Request, value: Any, action: RequestAction
) -> Any:
return len(value)
async def parse_obj(self, request: Request, obj: Any) -> Any:
return len(obj.media_files)


class BaseModelView(ModelView):
Expand Down Expand Up @@ -89,21 +87,14 @@ def can_edit(self, request: Request) -> bool:


class CollectionView(BaseModelView):
# FIXME exclude_fields_from_list: ClassVar[list[Any]] = [Collection.media_files]
# Hiding the media_files field from the list view hides the media_file_count field
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',
MediaFileCount(
'media_files',
id='media_file_count',
label='Size',
read_only=True,
exclude_from_edit=True,
exclude_from_create=True,
),
MediaFileCount(),
# 'media_files', # default view
MediaFilesGuidsField(
'media_files',
id='media_file_guids',
Expand All @@ -127,7 +118,7 @@ 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]
# FIXME exclude_fields_from_list: ClassVar[list[Any]] = [Batch.media_files]
exclude_fields_from_list: ClassVar[list[Any]] = [Batch.media_files]
exclude_fields_from_detail: ClassVar[list[Any]] = [Batch.id]

actions: ClassVar[list[Any]] = [
Expand All @@ -141,14 +132,7 @@ class BatchView(BaseModelView):
'name',
'pipeline',
'description',
MediaFileCount(
'media_files',
id='media_file_count',
label='Size',
read_only=True,
exclude_from_edit=True,
exclude_from_create=True,
),
MediaFileCount(),
MediaFilesGuidsField(
'media_files',
id='media_file_guids',
Expand Down