Skip to content

Commit

Permalink
Replace underscores in auto generated field names
Browse files Browse the repository at this point in the history
  • Loading branch information
Cito committed Aug 6, 2024
1 parent 1fa8c97 commit a3cd54c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/mass/adapters/outbound/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
}


def name_from_key(key: str) -> str:
"""Auto generate a suitable name from a key"""
return key.title().replace("_", " ")


def pipeline_match_text_search(*, query: str) -> JsonObject:
"""Build text search segment of aggregation pipeline"""
text_search = {"$text": {"$search": query}}
Expand Down Expand Up @@ -95,7 +100,7 @@ def pipeline_facet_sort_and_paginate(
)
name = facet.name
if not name:
name = facet.key.capitalize()
name = name_from_key(facet.key)
segment[name] = [
{
"$unwind": {
Expand Down Expand Up @@ -144,7 +149,9 @@ def pipeline_project(*, facet_fields: list[models.FieldLabel]) -> JsonObject:
# add a segment for each facet to summarize the options
for facet in facet_fields:
key = facet.key
name = facet.name or key.capitalize()
name = facet.name
if not name:
name = name_from_key(key)
segment["facets"].append(
{
"key": key,
Expand Down

0 comments on commit a3cd54c

Please sign in to comment.