예제 #1
0
파일: models.py 프로젝트: babiboy/ureport
    def pull_results(cls, poll_id):
        from ureport.backend import get_backend
        backend = get_backend()
        poll = Poll.objects.get(pk=poll_id)

        created, updated, ignored = backend.pull_results(poll, None, None)

        poll.rebuild_poll_results_counts()

        return created, updated, ignored
예제 #2
0
    def pull_results(cls, poll_id):
        from ureport.backend import get_backend
        backend = get_backend()
        poll = Poll.objects.get(pk=poll_id)

        created, updated, ignored = backend.pull_results(poll, None, None)

        poll.rebuild_poll_results_counts()

        return created, updated, ignored
예제 #3
0
파일: models.py 프로젝트: Ilhasoft/ureport
    def pull_results(cls, poll_id):
        from ureport.backend import get_backend
        backend = get_backend()
        poll = Poll.objects.get(pk=poll_id)

        created, updated, ignored = backend.pull_results(poll, None, None)

        poll.rebuild_poll_results_counts()

        Poll.objects.filter(org=poll.org_id, flow_uuid=poll.flow_uuid).update(has_synced=True)

        return created, updated, ignored
예제 #4
0
    def pull_results(cls, poll_id):
        from ureport.backend import get_backend
        backend = get_backend()
        poll = Poll.objects.get(pk=poll_id)

        (num_val_created, num_val_updated, num_val_ignored, num_path_created,
         num_path_updated,
         num_path_ignored) = backend.pull_results(poll, None, None)

        poll.rebuild_poll_results_counts()

        Poll.objects.filter(org=poll.org_id,
                            flow_uuid=poll.flow_uuid).update(has_synced=True)

        return num_val_created, num_val_updated, num_val_ignored, num_path_created, num_path_updated, num_path_ignored
예제 #5
0
def pull_contacts(org, since, until):
    """
    Fetches updated contacts from RapidPro and updates local contacts accordingly
    """
    from ureport.backend import get_backend
    from ureport.contacts.models import ReportersCounter
    backend = get_backend()

    if not since:
        logger.warn("First time run for org #%d. Will sync all contacts" % org.pk)

    start = time.time()

    fields_created, fields_updated, fields_deleted, ignored = backend.pull_fields(org)

    logger.warn("Fetched contact fields for org #%d. "
                "Created %s, Updated %s, Deleted %d, Ignored %d" % (org.pk, fields_created, fields_updated,
                                                                    fields_deleted, ignored))
    logger.warn("Fetch fields for org #%d took %ss" % (org.pk, time.time() - start))

    start_boundaries = time.time()

    boundaries_created, boundaries_updated, boundaries_deleted, ignored = backend.pull_boundaries(org)

    logger.warn("Fetched boundaries for org #%d. "
                "Created %s, Updated %s, Deleted %d, Ignored %d" % (org.pk, boundaries_created, boundaries_updated,
                                                                    boundaries_deleted, ignored))

    logger.warn("Fetch boundaries for org #%d took %ss" % (org.pk, time.time() - start_boundaries))
    start_contacts = time.time()

    contacts_created, contacts_updated, contacts_deleted, ignored = backend.pull_contacts(org, since, until)

    logger.warn("Fetched contacts for org #%d. "
                "Created %s, Updated %s, Deleted %d, Ignored %d" % (org.pk, contacts_created, contacts_updated,
                                                                    contacts_deleted, ignored))

    logger.warn("Fetch contacts for org #%d took %ss" % (org.pk, time.time() - start_contacts))

    # Squash reporters counts
    ReportersCounter.squash_counts()

    return {
        'fields': {'created': fields_created, 'updated': fields_updated, 'deleted': fields_deleted},
        'boundaries': {'created': boundaries_created, 'updated': boundaries_updated, 'deleted': boundaries_deleted},
        'contacts': {'created': contacts_created, 'updated': contacts_updated, 'deleted': contacts_deleted}
    }
예제 #6
0
def pull_contacts(org, since, until):
    """
    Fetches updated contacts from RapidPro and updates local contacts accordingly
    """
    from ureport.backend import get_backend
    from ureport.contacts.models import ReportersCounter
    backend = get_backend()

    if not since:
        logger.warn("First time run for org #%d. Will sync all contacts" %
                    org.pk)

    start = time.time()

    fields_created, fields_updated, fields_deleted, ignored = backend.pull_fields(
        org)

    logger.warn(
        "Fetched contact fields for org #%d. "
        "Created %s, Updated %s, Deleted %d, Ignored %d" %
        (org.pk, fields_created, fields_updated, fields_deleted, ignored))
    logger.warn("Fetch fields for org #%d took %ss" %
                (org.pk, time.time() - start))

    start_boundaries = time.time()

    boundaries_created, boundaries_updated, boundaries_deleted, ignored = backend.pull_boundaries(
        org)

    logger.warn("Fetched boundaries for org #%d. "
                "Created %s, Updated %s, Deleted %d, Ignored %d" %
                (org.pk, boundaries_created, boundaries_updated,
                 boundaries_deleted, ignored))

    logger.warn("Fetch boundaries for org #%d took %ss" %
                (org.pk, time.time() - start_boundaries))
    start_contacts = time.time()

    contacts_created, contacts_updated, contacts_deleted, ignored = backend.pull_contacts(
        org, since, until)

    logger.warn("Fetched contacts for org #%d. "
                "Created %s, Updated %s, Deleted %d, Ignored %d" %
                (org.pk, contacts_created, contacts_updated, contacts_deleted,
                 ignored))

    logger.warn("Fetch contacts for org #%d took %ss" %
                (org.pk, time.time() - start_contacts))

    # Squash reporters counts
    ReportersCounter.squash_counts()

    return {
        'fields': {
            'created': fields_created,
            'updated': fields_updated,
            'deleted': fields_deleted
        },
        'boundaries': {
            'created': boundaries_created,
            'updated': boundaries_updated,
            'deleted': boundaries_deleted
        },
        'contacts': {
            'created': contacts_created,
            'updated': contacts_updated,
            'deleted': contacts_deleted
        }
    }