-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GH-143] Show correct page and error when user searches a 0-3 length …
…string. (#146) * Set result_detail value (must be summmary or full) when query length is too short * remember the search preferences when showing error messages * move context check into a new function * Add unit tests for short name query and empty form * [Bot] Update version to 2.2.5 Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
dc0383f
commit 17d0b2d
Showing
4 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,38 @@ def handle_search_exception(e: Exception, context: RenderingContext): | |
"email [email protected] describing your problem." | ||
) | ||
|
||
@staticmethod | ||
def set_preferences_for_cookie(context: RenderingContext): | ||
""" | ||
When the search query is too short, the request_input data is dropped, but we still need a value for | ||
'result_detail' | ||
""" | ||
result_detail = "summary" | ||
if context.request_input and context.request_input.length: | ||
result_detail = context.request_input.length | ||
|
||
preferences = PreferencesCookie(result_detail=result_detail).json( | ||
exclude_unset=True, exclude_none=True | ||
) | ||
return preferences | ||
|
||
def check_context(self, context: RenderingContext, request: Request): | ||
if context.request_input: | ||
return context | ||
else: | ||
context.request_input = SearchDirectoryFormInput( | ||
method=request.form["method"], | ||
population=request.form["population"], | ||
length=request.form["length"], | ||
person_href=None, | ||
render_method=request.form["method"], | ||
render_query="", | ||
render_population=request.form["population"], | ||
render_length=request.form["length"], | ||
include_test_identities=False, | ||
) | ||
return context | ||
|
||
def search_listing( | ||
self, | ||
request: Request, | ||
|
@@ -160,15 +192,15 @@ def search_listing( | |
self.logger.exception(str(e)) | ||
SearchBlueprint.handle_search_exception(e, context) | ||
finally: | ||
context = self.check_context(context, request) | ||
response: Response = make_response( | ||
render_template( | ||
"views/search_results.html", **context.dict(exclude_none=True) | ||
), | ||
context.status_code, | ||
) | ||
preferences = PreferencesCookie( | ||
result_detail=context.request_input.length | ||
).json(exclude_unset=True, exclude_none=True) | ||
|
||
preferences = self.set_preferences_for_cookie(context) | ||
response.set_cookie( | ||
settings.session_settings.preferences_cookie_name, value=preferences | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "uw-husky-directory" | ||
version = "2.2.4" | ||
version = "2.2.5" | ||
description = "An updated version of the UW Directory" | ||
authors = ["Thomas Thorogood <[email protected]>"] | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters