Esempio n. 1
0
    def sync_search_wrapper():
        if isinstance(instance, InvestmentProjectTeamMember):
            pk = instance.investment_project.pk
        else:
            pk = instance.pk

        sync_object_async(InvestmentSearchApp, pk)
Esempio n. 2
0
def test_sync_object_task_syncs_using_celery(opensearch):
    """Test that an object can be synced to OpenSearch using Celery."""
    obj = SimpleModel.objects.create()
    sync_object_async(SimpleModelSearchApp, obj.pk)
    opensearch.indices.refresh()

    assert doc_exists(opensearch, SimpleModelSearchApp, obj.pk)
Esempio n. 3
0
def test_sync_object_task_syncs_using_celery(setup_es):
    """Test that an object can be synced to Elasticsearch using Celery."""
    obj = SimpleModel.objects.create()
    sync_object_async(SimpleModelSearchApp, obj.pk)
    setup_es.indices.refresh()

    assert doc_exists(setup_es, SimpleModelSearchApp, obj.pk)
Esempio n. 4
0
def investment_project_sync_m2m_opensearch(instance, action, reverse, pk_set,
                                           **kwargs):
    """
    Sync opensearch when m2m fields change on the investment project.
    """
    if action not in ('post_add', 'post_remove', 'post_clear'):
        return

    pks = pk_set if reverse else (instance.pk, )

    for pk in pks:
        sync_object_async(InvestmentSearchApp, pk)
Esempio n. 5
0
    def sync_search_wrapper():
        queryset = DBInvestmentProject.objects.filter(
            Q(created_by_id=instance.pk)
            | Q(client_relationship_manager_id=instance.pk)
            | Q(project_manager_id=instance.pk)
            | Q(project_assurance_adviser_id=instance.pk)
            | Q(team_members__adviser_id=instance.pk), )

        for project in queryset:
            sync_object_async(
                InvestmentSearchApp,
                project.pk,
            )
Esempio n. 6
0
def investment_project_sync_search_interaction_change(instance):
    """
    Sync investment projects in OpenSearch when related interactions change.

    When an interaction changes, the OpenSearch index is also updated for
    the related investment project. The previous version also needs to be
    checked to make sure that if the investment project changes, the old
    investment project is also updated in the index.
    """
    pks = []

    if instance.investment_project is not None:
        pks.append(instance.investment_project.pk)

    previous_version = Version.objects.get_for_object(
        instance, ).order_by('-revision__date_created').first()

    if (previous_version is not None
            and 'investment_project_id' in previous_version.field_dict):
        pks.append(previous_version.field_dict['investment_project_id'])

    for pk in set([pk for pk in pks if pk is not None]):
        sync_object_async(InvestmentSearchApp, pk)
Esempio n. 7
0
def export_country_history_sync_search(instance):
    """Sync export country history to the OpenSearch."""
    transaction.on_commit(
        lambda: sync_object_async(ExportCountryHistoryApp, instance.pk), )
Esempio n. 8
0
def company_sync_es(instance):
    """Sync company to the Elasticsearch."""
    transaction.on_commit(
        lambda: sync_object_async(CompanySearchApp, instance.pk), )
Esempio n. 9
0
def sync_event_to_opensearch(instance):
    """Sync event to the OpenSearch."""
    transaction.on_commit(
        lambda: sync_object_async(EventSearchApp, instance.pk), )
Esempio n. 10
0
def sync_participant_to_es(dit_participant):
    """Sync a DIT participant's interaction to Elasticsearch."""
    transaction.on_commit(
        lambda: sync_object_async(InteractionSearchApp, dit_participant.
                                  interaction_id), )
Esempio n. 11
0
def sync_interaction_to_es(instance):
    """Sync interaction to the Elasticsearch."""
    transaction.on_commit(
        lambda: sync_object_async(InteractionSearchApp, instance.pk), )
Esempio n. 12
0
def investor_profile_sync_es(instance):
    """Sync investor profile to Elasticsearch."""
    if str(instance.profile_type_id) == ProfileType.large.value.id:
        transaction.on_commit(
            lambda: sync_object_async(LargeInvestorProfileSearchApp, instance.
                                      pk), )
Esempio n. 13
0
def sync_related_company_to_opensearch(instance):
    """Sync related company."""
    transaction.on_commit(
        lambda: sync_object_async(CompanySearchApp, instance.company.pk), )
Esempio n. 14
0
def large_capital_opportunity_sync_search(instance):
    """Sync large capital opportunity to OpenSearch."""
    transaction.on_commit(
        lambda: sync_object_async(LargeCapitalOpportunitySearchApp, instance.pk),
    )
Esempio n. 15
0
def sync_event_to_es(instance):
    """Sync event to the Elasticsearch."""
    transaction.on_commit(
        lambda: sync_object_async(EventSearchApp, instance.pk), )
Esempio n. 16
0
def contact_sync_search(instance):
    """Sync contact to the OpenSearch."""
    transaction.on_commit(
        lambda: sync_object_async(ContactSearchApp, instance.pk), )
Esempio n. 17
0
def order_sync_es(instance):
    """Sync an order to the Elasticsearch."""
    transaction.on_commit(
        lambda: sync_object_async(OrderSearchApp, instance.pk),
    )
Esempio n. 18
0
def investor_profile_sync_es(instance):
    """Sync investor profile to Elasticsearch."""
    transaction.on_commit(
        lambda: sync_object_async(LargeInvestorProfileSearchApp, instance.pk),
    )