Skip to content

Commit

Permalink
🔆 Tweaks to display fields, seeds (#24)
Browse files Browse the repository at this point in the history
* Tweaks to display fields and seeds

* Customizes values displayed for related records.
* Use a small set of realistic ClamsApp names and only have seeds() function generate one
  record for each distinct app name.
* Changes ClamsEvent default display to Clams App name with Clams event status, e.g 'OCR: complete'

* Sets labels for Batches and Collections in select2 widgets.

* Swaps duplicate app NER for Bars

---------

Co-authored-by: Harpo Harbert <[email protected]>
  • Loading branch information
afred and mrharpo authored Apr 18, 2023
1 parent 17681da commit d03894a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
17 changes: 16 additions & 1 deletion chowda/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class MediaFile(SQLModel, table=True):
async def __admin_repr__(self, request: Request):
return self.guid

async def __admin_select2_repr__(self, request: Request) -> str:
return f'<span><strong>{self.guid}</strong></span>'


class Collection(SQLModel, table=True):
__tablename__ = 'collections'
Expand All @@ -92,6 +95,9 @@ class Collection(SQLModel, table=True):
async def __admin_repr__(self, request: Request):
return f'{self.name or self.id}'

async def __admin_select2_repr__(self, request: Request):
return f'<span><strong>{self.name or self.id}</span>'


class Batch(SQLModel, table=True):
__tablename__ = 'batches'
Expand All @@ -108,6 +114,9 @@ class Batch(SQLModel, table=True):
async def __admin_repr__(self, request: Request):
return f'{self.name or self.id}'

async def __admin_select2_repr__(self, request: Request):
return f'<span><strong>{self.name or self.id}</span>'


class ClamsAppPipelineLink(SQLModel, table=True):
clams_app_id: Optional[int] = Field(
Expand Down Expand Up @@ -146,6 +155,9 @@ class Pipeline(SQLModel, table=True):
async def __admin_repr__(self, request: Request):
return f'{self.name or self.id}'

async def __admin_select2_repr__(self, request: Request) -> str:
return f'<span><strong>{self.name or self.id}</span>'


class ClamsEvent(SQLModel, table=True):
__tablename__ = 'clams_events'
Expand All @@ -160,4 +172,7 @@ class ClamsEvent(SQLModel, table=True):
media_file: Optional[MediaFile] = Relationship(back_populates='clams_events')

async def __admin_repr__(self, request: Request):
return f'{self.batch.name}: {self.clams_app.name}: {self.status}'
return f'{self.clams_app.name}: {self.status}'

async def __admin_select2_repr__(self, request: Request) -> str:
return f'<span><strong>{self.clams_app.name}:</strong> {self.status}</span>'
18 changes: 16 additions & 2 deletions tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@
class CLAMSProvider(BaseProvider):
'''A custom Faker provider for generating CLAMS data'''

app_names = (
'Whisper',
'OCR',
'Slates',
'NER',
'Chyrons',
'Credits',
'Bars',
)

def app_name(self):
return f'app-{self.generator.word(part_of_speech="noun")}'
return self.generator.random.choice(self.app_names)

def guid(self):
return f'cpb-aacip-{str(self.generator.random_int())}-{self.generator.hexify(8*"^")}'
Expand Down Expand Up @@ -113,7 +123,11 @@ class ClamsAppFactory(ChowdaFactory):
class Meta:
model = ClamsApp

name = factory.Faker('app_name')
@factory.sequence
def name(n):
index = n % len(CLAMSProvider.app_names)
return CLAMSProvider.app_names[index]

description = factory.Faker('text')
endpoint = factory.Faker('url')

Expand Down
3 changes: 2 additions & 1 deletion tests/seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ClamsEventFactory,
CollectionFactory,
UserFactory,
CLAMSProvider,
)
from chowda.models import AppStatus
from random import sample, randint, choice
Expand All @@ -18,7 +19,7 @@ def seed(
num_media_files: int = 1000,
num_collections: int = 100,
num_batches: int = 100,
num_clams_apps: int = 10,
num_clams_apps: int = len(CLAMSProvider.app_names),
num_pipelines: int = 10,
num_clams_events: int = 1000,
num_users: int = 10,
Expand Down

0 comments on commit d03894a

Please sign in to comment.