From 910c606f41274123e49f94998313f53577058b70 Mon Sep 17 00:00:00 2001 From: Mike Joyce Date: Mon, 24 May 2021 11:01:42 -0400 Subject: [PATCH 1/3] Return active and active_handshake_perdet status to bureau position --- .../bidding/services/bidhandshake.py | 27 +++++++++++++++++++ talentmap_api/fsbid/services/bureau.py | 5 ++++ 2 files changed, 32 insertions(+) create mode 100644 talentmap_api/bidding/services/bidhandshake.py diff --git a/talentmap_api/bidding/services/bidhandshake.py b/talentmap_api/bidding/services/bidhandshake.py new file mode 100644 index 000000000..39c7b4f6a --- /dev/null +++ b/talentmap_api/bidding/services/bidhandshake.py @@ -0,0 +1,27 @@ +import logging +import pydash + +from talentmap_api.bidding.models import BidHandshake + +logger = logging.getLogger(__name__) + + +def get_position_handshake_data(cp_id): + ''' + Return whether the cycle position is active and to which perdet, if any, possesses the active handshake + ''' + props = { + 'active': False, + 'active_handshake_perdet': None, + } + + hs = BidHandshake.objects.filter(cp_id=cp_id).values() + active = pydash.filter_(hs, lambda x: x['status'] is not 'R') + if len(active) is 0: + props['active'] = True + + active = pydash.find(hs, lambda x: x['status'] is 'O' or x['status'] is 'A') + if active: + props['active_handshake_perdet'] = active['bidder_perdet'] + + return props diff --git a/talentmap_api/fsbid/services/bureau.py b/talentmap_api/fsbid/services/bureau.py index 57f77367b..5a9a4c556 100644 --- a/talentmap_api/fsbid/services/bureau.py +++ b/talentmap_api/fsbid/services/bureau.py @@ -11,6 +11,7 @@ import talentmap_api.fsbid.services.bid as bid_services import talentmap_api.fsbid.services.cdo as cdoservices +import talentmap_api.bidding.services.bidhandshake as bh_services import talentmap_api.fsbid.services.common as services from talentmap_api.available_positions.models import AvailablePositionRanking @@ -141,6 +142,9 @@ def fsbid_bureau_positions_to_talentmap(bp): ''' Converts the response bureau position from FSBid to a format more in line with the Talentmap position ''' + + bh_props = bh_services.get_position_handshake_data(bp.get("cp_id", None)) + hasHandShakeOffered = False if bp.get("cp_status", None) == "HS": hasHandShakeOffered = True @@ -262,6 +266,7 @@ def fsbid_bureau_positions_to_talentmap(bp): "has_handshake_offered": hasHandShakeOffered, "has_handshake_accepted": None }], + "bid_handshake": bh_props, "unaccompaniedStatus": bp.get("us_desc_text", None), "isConsumable": bp.get("bt_consumable_allowance_flg", None) == "Y", "isServiceNeedDifferential": bp.get("bt_service_needs_diff_flg", None) == "Y", From 12dd0b7bcd1f8ca49153f7f496345d2898dff06b Mon Sep 17 00:00:00 2001 From: Mike Joyce Date: Tue, 25 May 2021 14:59:32 -0400 Subject: [PATCH 2/3] only return the active perdet --- talentmap_api/bidding/services/bidhandshake.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/talentmap_api/bidding/services/bidhandshake.py b/talentmap_api/bidding/services/bidhandshake.py index 39c7b4f6a..161720844 100644 --- a/talentmap_api/bidding/services/bidhandshake.py +++ b/talentmap_api/bidding/services/bidhandshake.py @@ -8,19 +8,15 @@ def get_position_handshake_data(cp_id): ''' - Return whether the cycle position is active and to which perdet, if any, possesses the active handshake + Return whether the cycle position is active, and if so, to which perdet possesses the active handshake ''' props = { - 'active': False, 'active_handshake_perdet': None, } hs = BidHandshake.objects.filter(cp_id=cp_id).values() - active = pydash.filter_(hs, lambda x: x['status'] is not 'R') - if len(active) is 0: - props['active'] = True - active = pydash.find(hs, lambda x: x['status'] is 'O' or x['status'] is 'A') + active = pydash.find(hs, lambda x: x['status'] is not 'R') if active: props['active_handshake_perdet'] = active['bidder_perdet'] From 3748593b66f88b4357988139cdf1107d01d9376e Mon Sep 17 00:00:00 2001 From: Mike Joyce Date: Wed, 26 May 2021 08:59:08 -0400 Subject: [PATCH 3/3] Refactor to use query filtering --- talentmap_api/bidding/services/bidhandshake.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/talentmap_api/bidding/services/bidhandshake.py b/talentmap_api/bidding/services/bidhandshake.py index 161720844..e519209eb 100644 --- a/talentmap_api/bidding/services/bidhandshake.py +++ b/talentmap_api/bidding/services/bidhandshake.py @@ -14,10 +14,9 @@ def get_position_handshake_data(cp_id): 'active_handshake_perdet': None, } - hs = BidHandshake.objects.filter(cp_id=cp_id).values() + perdet = BidHandshake.objects.filter(cp_id=cp_id).exclude(status='R').values_list("bidder_perdet", flat=True) - active = pydash.find(hs, lambda x: x['status'] is not 'R') - if active: - props['active_handshake_perdet'] = active['bidder_perdet'] + if perdet: + props['active_handshake_perdet'] = perdet.first() return props