Activity Stream Utils

app.enquiries.common.as_utils.fetch_and_process_enquiries()

Fetches new enquiries from Activity Stream and creates saved app.enquiries.models.Enquiry instances.

app.enquiries.common.as_utils.get_new_investment_enquiries(last_cursor=None, max_size=100)

Fetches new investment enquiries from Activity Stream. The ACTIVITY_STREAM_INITIAL_LOAD_DATE environmental variable determines the initial date from which the data is queried.

Two emails are sent for every enquiry, one to the user who filled out the form and one to enquiries@invest-trade.uk for triage. Both of these are present in activity stream. To avoid duplicate enquiries, the emails sent to the user are ignored by filtering out emails which were sent by noreply@invest.great.gov.uk.

Parameters:
  • last_cursor (str) – Indicates the last enquiry fetched (index and id). This is used to fetch next set of results when this is invoked again.

  • max_size (int) – The maximum number of results to fetch

Returns:

JSON-parsed response or None in case of an error

app.enquiries.common.as_utils.get_new_second_qualification_forms(last_datetime=None, max_size=100)

Fetches new submissions of the second qualification form from Activity Stream. The submissions are fetched from last_datetime onward, or without a date filter if not provided.

Parameters:
  • last_datetime (datetime) – The last time a second qualification form was submitted. Subsequent forms will filter after this date. If omited all forms will be fetched

  • max_size (int) – The maximum number of results to fetch

Returns:

JSON-parsed response or None in case of an error

app.enquiries.common.as_utils.great_ui_sector_rtt_mapping(value)

Resolves the primary sector for value.

Sector data in the website is different from that in dit-sectors reference, so we first check if it is in standard reference data otherwise map it to our reference data. If not found anywhere use default value.

Parameters:

value (str) –

Returns:

GREAT sector

Return type:

str

app.enquiries.common.as_utils.hawk_request(method, url, id_, secret_key, body)

Makes a hawk request

Parameters:
  • method (str) – A valid HTTP method

  • url (str) – A valid URL

  • id (str) – The id for the credentials argument to mohawk.Sender

  • secret_key (str) – The secret_key for the credentials argument to mohawk.Sender

  • body – A JSON serializable data structure to be sent as the request body

Returns:

requests.Response

app.enquiries.common.as_utils.parse_enquiry_email(submission)

Parses email body in the submission and returns Enquiry related fields. This can be used to create an Enquiry.

Parameters:

submission (dict) – The email to be parsed

Returns:

The result of via_enquiry_to_enquiry_kwargs() or {} or None

app.enquiries.common.as_utils.via_enquiry_to_enquiry_kwargs(data)

Converts enquiry submitted via email into a dict of kwargs for app.enquiries.models.Enquiry.

Parameters:

data (dict) –

Returns:

A dict of app.enquiries.models.Enquiry constructor kwargs.