Beispiel #1
0
def connect_signals():
    case_post_save.connect(messaging_case_changed_receiver,
                           CommCareCase,
                           dispatch_uid='messaging_couch_case_receiver')
    sql_case_post_save.connect(messaging_case_changed_receiver,
                               CommCareCaseSQL,
                               dispatch_uid='messaging_sql_case_receiver')
Beispiel #2
0
def connect_signals():
    if settings.SYNC_CASE_FOR_MESSAGING_ON_SAVE:
        case_post_save.connect(messaging_case_changed_receiver,
                               CommCareCase,
                               dispatch_uid='messaging_couch_case_receiver')
        sql_case_post_save.connect(messaging_case_changed_receiver,
                                   CommCareCaseSQL,
                                   dispatch_uid='messaging_sql_case_receiver')
Beispiel #3
0
    def ready(self):
        from casexml.apps.case.models import CommCareCase
        from casexml.apps.case.signals import case_post_save
        from corehq.form_processor.models import CommCareCaseSQL
        from corehq.form_processor.signals import sql_case_post_save

        case_post_save.connect(case_changed_receiver, CommCareCase,
                               dispatch_uid="data_interfaces_case_receiver")
        sql_case_post_save.connect(case_changed_receiver, CommCareCaseSQL,
                                   dispatch_uid="data_interfaces_sql_case_receiver")
Beispiel #4
0
    def ready(self):
        from casexml.apps.case.models import CommCareCase
        from casexml.apps.case.signals import case_post_save
        from corehq.form_processor.models import CommCareCaseSQL
        from corehq.form_processor.signals import sql_case_post_save

        case_post_save.connect(case_changed_receiver, CommCareCase,
                               dispatch_uid="data_interfaces_case_receiver")
        sql_case_post_save.connect(case_changed_receiver, CommCareCaseSQL,
                                   dispatch_uid="data_interfaces_sql_case_receiver")
Beispiel #5
0
def connect_signals():
    case_post_save.connect(
        messaging_case_changed_receiver,
        CommCareCase,
        dispatch_uid='messaging_couch_case_receiver'
    )
    sql_case_post_save.connect(
        messaging_case_changed_receiver,
        CommCareCaseSQL,
        dispatch_uid='messaging_sql_case_receiver'
    )
Beispiel #6
0
    repeater_name = repeater_cls.__module__ + '.' + repeater_cls.__name__
    if settings.REPEATERS_WHITELIST is not None and repeater_name not in settings.REPEATERS_WHITELIST:
        return
    domain = payload.domain
    if domain:
        repeaters = repeater_cls.by_domain(domain)
        for repeater in repeaters:
            repeater.register(payload)


@receiver(commcare_user_post_save, dispatch_uid="create_user_repeat_records")
def create_user_repeat_records(sender, couch_user, **kwargs):
    from corehq.motech.repeaters.models import UserRepeater
    create_repeat_records(UserRepeater, couch_user)


@receiver(post_save,
          sender=SQLLocation,
          dispatch_uid="create_location_repeat_records")
def create_location_repeat_records(sender, raw=False, **kwargs):
    from corehq.motech.repeaters.models import LocationRepeater
    if raw:
        return
    create_repeat_records(LocationRepeater, kwargs['instance'])


successful_form_received.connect(create_form_repeat_records)
successful_form_received.connect(create_short_form_repeat_records)
case_post_save.connect(create_case_repeat_records, CommCareCase)
case_post_save.connect(create_case_repeat_records, CommCareCaseSQL)
Beispiel #7
0
            pass
    
    def get_time_zone(self):
        return self.get_case_property("time_zone")

    def get_language_code(self):
        return self.get_case_property("language_code")
    
    @property
    def raw_username(self):
        return self.get_case_property("name")

    @classmethod
    def wrap_as_commconnect_case(cls, case):
        """
        Takes a CommCareCase and wraps it as a CommConnectCase.
        """
        return CommConnectCase.wrap(case.to_json())

    class Meta:
        app_label = "sms" # This is necessary otherwise syncdb will confuse the sms app with casexml


def case_changed_receiver(sender, case, **kwargs):
    contact = CommConnectCase.wrap_as_commconnect_case(case)
    contact.case_changed()


case_post_save.connect(case_changed_receiver, CommCareCase)

Beispiel #8
0
def create_repeat_records(repeater_cls, payload):
    domain = payload.domain
    if domain:
        repeaters = repeater_cls.by_domain(domain)
        for repeater in repeaters:
            repeater.register(payload)


def form_processing(sender, xform, **kwargs):
    should_update = scrub_meta(sender, xform)
    should_update = add_domain(sender, xform) or should_update
    should_update = add_export_tag(sender, xform) or should_update
    should_update = add_app_id(sender, xform) or should_update
    # form received saves the doc right after calling this signal,
    # so we don't have to save, though would need to here if that changes
    return should_update


def error_processing(sender, xform, **kwargs):
    should_update = add_domain(sender, xform)
    should_update = add_app_id(sender, xform) or should_update
    return should_update


form_received.connect(form_processing)
submission_error_received.connect(error_processing)

successful_form_received.connect(create_form_repeat_records)
successful_form_received.connect(create_short_form_repeat_records)
case_post_save.connect(create_case_repeat_records)
Beispiel #9
0

def create_form_repeat_records(sender, xform, **kwargs):
    from corehq.apps.receiverwrapper.models import FormRepeater
    create_repeat_records(FormRepeater, xform)


def create_case_repeat_records(sender, case, **kwargs):
    from corehq.apps.receiverwrapper.models import CaseRepeater
    create_repeat_records(CaseRepeater, case)


def create_short_form_repeat_records(sender, xform, **kwargs):
    from corehq.apps.receiverwrapper.models import ShortFormRepeater
    create_repeat_records(ShortFormRepeater, xform)


def create_repeat_records(repeater_cls, payload):
    domain = payload.domain
    if domain:
        repeaters = repeater_cls.by_domain(domain)
        for repeater in repeaters:
            if not (getattr(repeater, 'exclude_device_reports', False)
                    and is_device_report(payload)):
                repeater.register(payload)


successful_form_received.connect(create_form_repeat_records)
successful_form_received.connect(create_short_form_repeat_records)
case_post_save.connect(create_case_repeat_records)
Beispiel #10
0
from casexml.apps.case.models import CommCareCase
from casexml.apps.case.signals import case_post_save
from corehq.apps.reminders.models import (CaseReminderHandler,
    REMINDER_TYPE_DEFAULT)
from corehq.apps.reminders.tasks import case_changed
from dimagi.utils.logging import notify_exception

def case_changed_receiver(sender, case, **kwargs):
    """
    Fires reminders associated with the case, if any exist.
    """
    try:
        handler_ids = CaseReminderHandler.get_handler_ids(case.domain,
            reminder_type_filter=REMINDER_TYPE_DEFAULT)
        if len(handler_ids) > 0:
            case_changed.delay(case._id, handler_ids)
    except Exception:
        notify_exception(None,
            message="Error in reminders case changed receiver for case %s" %
            case._id)

case_post_save.connect(case_changed_receiver, CommCareCase)

Beispiel #11
0

def create_form_repeat_records(sender, xform, **kwargs):
    from corehq.apps.receiverwrapper.models import FormRepeater
    create_repeat_records(FormRepeater, xform)


def create_case_repeat_records(sender, case, **kwargs):
    from corehq.apps.receiverwrapper.models import CaseRepeater
    create_repeat_records(CaseRepeater, case)


def create_short_form_repeat_records(sender, xform, **kwargs):
    from corehq.apps.receiverwrapper.models import ShortFormRepeater
    create_repeat_records(ShortFormRepeater, xform)


def create_repeat_records(repeater_cls, payload):
    domain = payload.domain
    if domain:
        repeaters = repeater_cls.by_domain(domain)
        for repeater in repeaters:
            if not (getattr(repeater, 'exclude_device_reports', False)
                    and is_device_report(payload)):
                repeater.register(payload)


successful_form_received.connect(create_form_repeat_records)
successful_form_received.connect(create_short_form_repeat_records)
case_post_save.connect(create_case_repeat_records, CommCareCase)