Add support for using number in member terms renwewal API (#77)
Closed #75 Co-authored-by: Rio6 <rio.liu@r26.me> Co-authored-by: Max Erenberg <merenber@csclub.uwaterloo.ca> Reviewed-on: #77 Co-authored-by: Rio Liu <r345liu@csclub.uwaterloo.ca> Co-committed-by: Rio Liu <r345liu@csclub.uwaterloo.ca>pull/79/head
parent
779e35a08e
commit
57ba72ef26
@ -1,38 +1,22 @@ |
||||
from typing import List |
||||
|
||||
from .utils import http_get |
||||
from ceo_common.model import Term |
||||
from ceo_common.model.Term import get_terms_for_renewal |
||||
import ceo.cli.utils as cli_utils |
||||
import ceo.tui.utils as tui_utils |
||||
|
||||
# Had to put these in a separate file to avoid a circular import. |
||||
|
||||
|
||||
def get_terms_for_new_user(num_terms: int) -> List[str]: |
||||
current_term = Term.current() |
||||
terms = [current_term + i for i in range(num_terms)] |
||||
return list(map(str, terms)) |
||||
|
||||
|
||||
def get_terms_for_renewal( |
||||
def get_terms_for_renewal_for_user( |
||||
username: str, num_terms: int, clubrep: bool, tui_controller=None, |
||||
) -> List[str]: |
||||
resp = http_get('/api/members/' + username) |
||||
# FIXME: this is ugly, we shouldn't need a hacky if statement like this |
||||
if tui_controller is None: |
||||
result = cli_utils.handle_sync_response(resp) |
||||
else: |
||||
result = tui_utils.handle_sync_response(resp, tui_controller) |
||||
max_term = None |
||||
current_term = Term.current() |
||||
if clubrep and 'non_member_terms' in result: |
||||
max_term = max(Term(s) for s in result['non_member_terms']) |
||||
elif not clubrep and 'terms' in result: |
||||
max_term = max(Term(s) for s in result['terms']) |
||||
|
||||
if max_term is not None and max_term >= current_term: |
||||
next_term = max_term + 1 |
||||
if clubrep: |
||||
return get_terms_for_renewal(result.get('non_member_terms'), num_terms) |
||||
else: |
||||
next_term = Term.current() |
||||
|
||||
terms = [next_term + i for i in range(num_terms)] |
||||
return list(map(str, terms)) |
||||
return get_terms_for_renewal(result.get('terms'), num_terms) |
||||
|
@ -1,6 +1,6 @@ |
||||
flake8==3.9.2 |
||||
setuptools==40.8.0 |
||||
wheel==0.36.2 |
||||
pytest==6.2.4 |
||||
flake8==5.0.4 |
||||
setuptools==65.4.1 |
||||
wheel==0.37.1 |
||||
pytest==7.1.3 |
||||
aiosmtpd==1.4.2 |
||||
aiohttp==3.7.4.post0 |
||||
aiohttp==3.8.3 |
||||
|
Loading…
Reference in new issue