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

📙 page_size_options #156

Merged
merged 7 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions chowda/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class SonyCiAssetThumbnail(BaseField):
label: str = 'Thumbnail'
display_template: str = 'displays/sony_ci_asset_thumbnail.html'
read_only: bool = True
exclude_from_create: bool = True
exclude_from_edit: bool = True
afred marked this conversation as resolved.
Show resolved Hide resolved

render_function_key: str = 'sony_ci_asset_thumbnail'

async def parse_obj(self, request: Request, obj: Any) -> Any:
return obj.thumbnails_by_type.get('standard')
return obj.thumbnails_by_type.get('small')


@dataclass
Expand Down
22 changes: 16 additions & 6 deletions chowda/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@
from chowda.utils import validate_media_file_guids


class BaseModelView(ModelView):
class ChowdaModelView(ModelView):
"""Base permissions for all views"""

page_size_options: ClassVar[list[int]] = [10, 25, 100, 1000, -1]


class ClammerModelView(ChowdaModelView):
"""Base Clammer permissions for all protected views"""

def can_create(self, request: Request) -> bool:
return get_user(request).is_clammer

Expand All @@ -43,7 +49,7 @@ def can_edit(self, request: Request) -> bool:
return get_user(request).is_clammer


class AdminModelView(ModelView):
class AdminModelView(ClammerModelView):
"""Base Admin permissions for all protected views"""

def is_accessible(self, request: Request) -> bool:
Expand All @@ -60,7 +66,7 @@ def can_edit(self, request: Request) -> bool:
return get_user(request).is_admin


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

Expand Down Expand Up @@ -152,7 +158,7 @@ async def create_multiple_batches(self, request: Request, pks: List[Any]) -> str
return f'Created Batches from {", ".join(names)}'


class BatchView(BaseModelView):
class BatchView(ClammerModelView):
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]
Expand Down Expand Up @@ -283,8 +289,9 @@ async def combine_batches(self, request: Request, pks: List[Any]) -> str:
return f'Combined {len(pks)} Batch(es)'


class MediaFileView(BaseModelView):
class MediaFileView(ClammerModelView):
pk_attr: str = 'guid'

actions: ClassVar[List[str]] = ['create_new_batch']

fields: ClassVar[list[str]] = [
Expand All @@ -295,6 +302,7 @@ class MediaFileView(BaseModelView):
'mmif_json',
]
exclude_fields_from_list: ClassVar[list[str]] = ['mmif_json']
page_size_options: ClassVar[list[int]] = [10, 25, 100, 500, 2000, 10000]

def can_create(self, request: Request) -> bool:
return get_user(request).is_admin
Expand Down Expand Up @@ -337,7 +345,7 @@ class UserView(AdminModelView):
fields: ClassVar[list[Any]] = ['first_name', 'last_name', 'email']


class ClamsAppView(BaseModelView):
class ClamsAppView(ClammerModelView):
fields: ClassVar[list[Any]] = ['name', 'endpoint', 'description', 'pipelines']


Expand Down Expand Up @@ -387,6 +395,8 @@ class SonyCiAssetView(AdminModelView):
'media_files',
]

page_size_options: ClassVar[list[int]] = [10, 25, 100, 500, 2000, 10000]

def can_create(self, request: Request) -> bool:
"""Sony Ci Assets are ingested from Sony Ci API, not created from the UI."""
return False
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ omit = ['tests/*']
[tool.pytest.ini_options]
testpaths = ['tests', 'docs']

[tool.ruff.flake8-quotes]
inline-quotes = 'single'

mrharpo marked this conversation as resolved.
Show resolved Hide resolved
[tool.ruff]
extend-exclude = ['migrations']
ignore = ['Q000']
Expand Down
4 changes: 2 additions & 2 deletions static/js/custom_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Object.assign(render, {
media_file_guid_links: function render(data, type, full, meta, fieldOptions) {
// Render a list of media files to a string of links to media files
return data.map(
(guid) => `<a href="../media-file/detail/${guid}"> ${guid} </a>`
guid => `<a href="../media-file/detail/${guid}"> ${guid} </a>`
)
},
media_file_count: function render(data, type, full, meta, fieldOptions) {
Expand All @@ -18,7 +18,7 @@ Object.assign(render, {
fieldOptions
) {
return data
? `<img src="${data.location}" style="max-height:150px;">`
? `<img src="${data.location}" style="max-height:150px;" loading="lazy">`
: null
},
})