diff options
author | Frederick Muriuki Muriithi | 2025-03-14 10:54:15 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-03-14 10:54:15 -0500 |
commit | c70188b307138dde2f618fb846ac57cd1cc418fb (patch) | |
tree | f2b102d5f80e4d4dec83c47844f55af691c0f529 /gn_auth/auth | |
parent | bb6a77dfcb553fcabfff8a3337a569f9e30b6f16 (diff) | |
download | gn-auth-c70188b307138dde2f618fb846ac57cd1cc418fb.tar.gz |
Make display of number of minutes more human-friendly.
Diffstat (limited to 'gn_auth/auth')
-rw-r--r-- | gn_auth/auth/authorisation/users/views.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py index f2e89cc..469bfa1 100644 --- a/gn_auth/auth/authorisation/users/views.py +++ b/gn_auth/auth/authorisation/users/views.py @@ -114,6 +114,29 @@ def user_address(user: User) -> Address: """Compute the `email.headerregistry.Address` from a `User`""" return Address(display_name=user.name, addr_spec=user.email) + +def display_minutes_for_humans(minutes): + """Convert minutes into human-readable display.""" + _week_ = 10080 # minutes + _day_ = 1440 # minutes + _remainder_ = minutes + + _human_readable_ = "" + if _remainder_ >= _week_: + _weeks_ = _remainder_ // _week_ + _remainder_ = _remainder_ % _week_ + _human_readable_ += f"{_weeks_} week" + ("s" if _weeks_ > 1 else "") + + if _remainder_ >= _day_: + _days_ = _remainder_ // _day_ + _remainder_ = _remainder_ % _day_ + _human_readable_ += (" " if bool(_human_readable_) else "") + f"{_days_} day" + ("s" if _days_ > 1 else "") + + if _remainder_ > 0: + _human_readable_ += (" " if bool(_human_readable_) else "") + f"{_remainder_} minutes" + + return _human_readable_ + def send_verification_email( conn, user: User, @@ -137,7 +160,8 @@ def send_verification_email( client_id=client_id, redirect_uri=redirect_uri, verificationcode=verification_code)), - expiration_minutes=expiration_minutes) + expiration_minutes=display_minutes_for_humans( + expiration_minutes)) with db.cursor(conn) as cursor: cursor.execute( ("INSERT INTO " |