DataHub Utils
- app.enquiries.common.datahub_utils.dh_adviser_search(request, access_token, adviser_name)
Performs an adviser DataHub API search.
- Parameters:
request (django.http.HttpRequest) –
adviser_name (str) – Adviser name to search for
- Returns:
A subset of fields for each Adviser found
- Return type:
- app.enquiries.common.datahub_utils.dh_company_search(request, access_token, company_name)
Performs a Company name search using DataHub API.
- Parameters:
request (django.http.HttpRequest) –
company_name (str) – Company name to search for
- Returns:
A subset of fields for each company found
- Return type:
- app.enquiries.common.datahub_utils.dh_contact_create(request, access_token, enquirer, company_id, primary=False)
Create a DataHub contact and associate it with the given company.
- Parameters:
request (django.http.HttpRequest) –
enquirer (app.enquiries.models.Enquirer) – Contact to add
company_id (str) – Company ID
primary (bool) –
- Returns:
A
(response_json_dict, None)
or(None, error_json_dict)
tuple- Return type:
- app.enquiries.common.datahub_utils.dh_enquiry_readiness(request, access_token, enquiry)
Check whether the given enquiry is ready to be submitted to DataHub
Criteria is that the company should exist in DataHub, client relationship manager is a valid user, given user is available etc.
- Parameters:
request (django.http.HttpRequest) –
enquiry (app.enquiries.models.Enquiry) –
- Returns:
JSON-parsed DataHub API response
- Return type:
- app.enquiries.common.datahub_utils.dh_get_company_contact_list(request, access_token, company_id)
Performs a contact search for a specific company using DataHub API.
- Parameters:
request (django.http.HttpRequest) –
company_id (str) – Company ID
- Returns:
A subset of fields for each company found
- Return type:
- app.enquiries.common.datahub_utils.dh_get_matching_company_contact(first_name, last_name, email, company_contacts)
Performs check identifying whether an enquirer exists in their company’s contact list in DataHub API.
- app.enquiries.common.datahub_utils.dh_get_matching_company_contact_by_email(email, company_contacts)
Performs check identifying whether an enquirer’s email exists in their company’s contact list in DataHub API.
- app.enquiries.common.datahub_utils.dh_get_user_details(request, access_token)
Gets the currently logged in user details
- Parameters:
request (django.http.HttpRequest) –
- app.enquiries.common.datahub_utils.dh_investment_create(request, enquiry)
Creates a DataHub investment using the data from the given
app.enquiries.models.Enquiry
.Investment is only created if the company corresponding to the enquiry exists in DataHub otherwise error is returned. Enquirer details are added to the list of contacts for this company. If this is the only contact then it will be made primary.
- Parameters:
request (django.http.HttpRequest) –
enquiry (app.enquiries.models.Enquiry) –
- Returns:
The parsed response JSON
- Return type:
- app.enquiries.common.datahub_utils.dh_prepare_contact(request, access_token, enquirer, company_id)
Prepares contact for the Data Hub request based on enquirer details. Prompts adding a new company contact to Data Hub if needed.
- Parameters:
request (django.http.HttpRequest) –
enquirer (app.enquiries.models.Enquirer) –
company_id (str) –
- Returns:
A
(uuid, None)
or(None, error_json_dict)
tuple- Return type:
- app.enquiries.common.datahub_utils.dh_prepare_payload(enquiry, company_id, contact_id, adviser_id, client_relationship_manager_id)
Prepares the payload for investment create request
- Parameters:
enquiry (app.enquiries.models.Enquiry) –
company_id (str) –
contact_id (str) –
adviser_id (str) –
client_relationship_manager_id (str) –
- Returns:
A
(payload, 'primary_sector')
or(payload, None)
, wherepayload
is adict
.
- app.enquiries.common.datahub_utils.dh_request(request, access_token, method, url, payload=None, request_headers=None, params=None, timeout=15)
Makes a DataHub API request.
- Parameters:
request (django.http.HttpRequest) – A Django request
access_token (str) – A valid OAuth 2.0 access_token
method (str) – HTTP method
url (str) – A full DataHub API URL
payload (A JSON serializable value, optional) – The request payload
request_headers (dict, optional) – Request headers
params (dict, optional) – GET request querystring params
timeout (int, optional) – A timeout after which the function throws an error
- Returns:
A
requests.Response
instance
- app.enquiries.common.datahub_utils.fetch_metadata(name)
Fetches DataHub API metadata by
name
. The function is memoized for one hour in Django’s cache.- Parameters:
name (str) – The trailing part of the DataHub API metadata endpoint e.g.
https://api.dev.datahub.uktrade.digital/v4/metadata/<name>
.- Returns:
The parsed metadata as a
list
of dictionaries.
- app.enquiries.common.datahub_utils.resolve_metadata_id(title, metadata)
Resolves an ID of the specified metadata by its
title
.