Skip to content

Commit 393a46b

Browse files
authored
improve: search images table result (#164)
2 parents 65c1c34 + 1b11944 commit 393a46b

File tree

5 files changed

+66
-13
lines changed

5 files changed

+66
-13
lines changed

geotribu_cli/cli_results_rich_formatters.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def format_output_result_search_content(
109109
search_term=search_term,
110110
search_results_total=len(result),
111111
search_results_displayed=count,
112+
hint="Astuce : ctrl+clic sur le titre pour ouvrir le contenu",
112113
)
113114

114115
table = Table(
@@ -149,6 +150,7 @@ def format_output_result_search_image(
149150
search_term: Optional[str] = None,
150151
format_type: Optional[str] = None,
151152
count: int = 5,
153+
search_filter_type: Optional[str] = None,
152154
) -> Union[list[dict], Table]:
153155
"""Format result according to output option.
154156
@@ -162,9 +164,17 @@ def format_output_result_search_image(
162164
str: formatted result ready to print
163165
"""
164166
if format_type == "table":
167+
titre = add_search_criteria_as_str(
168+
in_txt="Recherche dans les images",
169+
search_term=search_term,
170+
search_filter_type=search_filter_type,
171+
search_results_total=len(result),
172+
search_results_displayed=count,
173+
hint="Astuce : ctrl+clic sur le nom pour ouvrir l'image",
174+
)
175+
165176
table = Table(
166-
title=f"Recherche d'images - {len(result)} résultats "
167-
f"avec le terme : {search_term}\n(ctrl+clic sur le nom pour ouvrir l'image)",
177+
title=titre,
168178
show_lines=True,
169179
highlight=True,
170180
caption=f"{__title__} {__version__}",
@@ -204,21 +214,23 @@ def format_output_result_search_image(
204214
@lru_cache
205215
def add_search_criteria_as_str(
206216
in_txt: str,
207-
search_filter_dates: tuple,
217+
search_filter_dates: Optional[tuple] = None,
208218
search_results_total: Optional[int] = None,
209219
search_results_displayed: Optional[int] = None,
210220
search_term: Optional[str] = None,
211221
search_filter_type: Optional[str] = None,
222+
hint: Optional[str] = None,
212223
) -> str:
213224
"""Prettify a title with search criterias.
214225
215226
Args:
216227
in_txt: initial title text
217228
search_filter_dates: tuple of dates used to filter search
218229
search_results_total: total of results of search. Defaults to None.
219-
search_results_displayed: totla of results to display. Defaults to None.
230+
search_results_displayed: total of results to display. Defaults to None.
220231
search_term: search terms. Defaults to None.
221232
search_filter_type: search filter type. Defaults to None.
233+
hint: optional short hint text to display before the table. Defaults to None.
222234
223235
Returns:
224236
formatted title
@@ -229,15 +241,24 @@ def add_search_criteria_as_str(
229241
if search_term:
230242
in_txt += f" avec le terme : {search_term}"
231243

232-
if any([search_filter_dates[0], search_filter_dates[1], search_filter_type]):
244+
if any(
245+
[
246+
isinstance(search_filter_dates, tuple) and search_filter_dates[0],
247+
isinstance(search_filter_dates, tuple) and search_filter_dates[1],
248+
search_filter_type,
249+
],
250+
):
233251
in_txt += "\nFiltres : "
234252
if search_filter_type:
235253
in_txt += f"de type {search_filter_type}, "
236-
if search_filter_dates[0]:
254+
if isinstance(search_filter_dates, tuple) and search_filter_dates[0]:
237255
in_txt += f"plus récents que {search_filter_dates[0]:%d %B %Y}, "
238-
if search_filter_dates[1]:
256+
if isinstance(search_filter_dates, tuple) and search_filter_dates[1]:
239257
in_txt += f"plus anciens que {search_filter_dates[1]:%d %B %Y}"
240258
else:
241-
in_txt += "Aucun filtre de recherche appliqué."
259+
in_txt += "\nAucun filtre de recherche appliqué."
260+
261+
if hint:
262+
in_txt += f"\n{hint}"
242263

243264
return in_txt

geotribu_cli/comments/comments_open.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ def run(args: argparse.Namespace):
151151
else:
152152
open_uri(in_filepath=comment_obj.url_to_comment)
153153

154-
sys.exit(0)
155-
156154

157155
# -- Stand alone execution
158156
if __name__ == "__main__":

geotribu_cli/search/search_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def parser_search_image(subparser: argparse.ArgumentParser) -> argparse.Argument
4747
Returns:
4848
argparse.ArgumentParser: parser ready to use
4949
"""
50-
5150
subparser.add_argument(
5251
"search_term",
5352
help="Terme de recherche.",
@@ -237,6 +236,7 @@ def run(args: argparse.Namespace):
237236
format_type=args.format_output,
238237
count=args.results_number,
239238
search_term=args.search_term,
239+
search_filter_type=args.filter_type,
240240
)
241241
)
242242
else:

requirements/testing.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
# --------------------
33

44
Pillow>=10.0.1,<11
5-
pytest-cov>=4,<5
6-
validators>=0.19,<0.23
5+
pytest-cov>=4
6+
pytest-retry>=1.6
7+
validators>=0.20,<0.23

tests/test_cli.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ def test_cli_run_comments_latest(capsys):
6868
assert Path(Path().home() / ".geotribu/comments/latest.json").exists()
6969

7070

71+
def test_cli_run_comments_open(capsys):
72+
"""Test nested subcommand comments latest."""
73+
cli.main(["comments", "open"])
74+
75+
out, err = capsys.readouterr()
76+
77+
assert err == ""
78+
assert Path(Path().home() / ".geotribu/comments/latest.json").exists()
79+
80+
81+
@pytest.mark.flaky(retries=3, delay=1, only_on=[SystemExit])
82+
def test_cli_run_comments_open_specific(capsys):
83+
"""Test nested subcommand comments latest."""
84+
cli.main(["comments", "open", "--page-size", "25", "--comment-id", "15"])
85+
86+
out, err = capsys.readouterr()
87+
88+
assert err == ""
89+
assert Path(Path().home() / ".geotribu/comments/latest.json").exists()
90+
91+
7192
def test_cli_run_contenus_articles_ubuntu(capsys):
7293
"""Test CLI images."""
7394
cli.main(
@@ -102,6 +123,18 @@ def test_cli_run_images_logo_news(capsys):
102123
assert Path(Path().home() / ".geotribu/search/cdn_search_index.json").exists()
103124

104125

126+
def test_cli_run_si_post_table(capsys):
127+
"""Test CLI images."""
128+
cli.main(["si", "--no-prompt", "post*"])
129+
130+
out, err = capsys.readouterr()
131+
132+
assert out.strip().startswith("Recherche dans les images")
133+
assert err == ""
134+
135+
assert Path(Path().home() / ".geotribu/search/cdn_search_index.json").exists()
136+
137+
105138
def test_cli_run_new_article(capsys):
106139
"""Test subcommand creating new article."""
107140

0 commit comments

Comments
 (0)