Exemplo n.º 1
0
    def process_change(self, pillow_instance, change):

        synclog = change.get_document()
        if not synclog:
            return

        version = None
        app_id = None
        try:
            sync_date = string_to_utc_datetime(synclog.get('date'))
        except (ValueError, AttributeError):
            return
        build_id = synclog.get('build_id')
        if build_id:
            version, app_id = get_version_and_app_from_build_id(
                synclog.get('domain'), build_id)
        user_id = synclog.get('user_id')

        if user_id:
            user = CouchUser.get_by_user_id(user_id)
            save = update_last_sync(user, app_id, sync_date, version)
            if version:
                save |= update_latest_builds(user, app_id, sync_date, version)
            if save:
                user.save()
Exemplo n.º 2
0
def mark_last_synclog(domain,
                      user,
                      app_id,
                      build_id,
                      sync_date,
                      device_id,
                      save=True):
    version = None
    if build_id:
        version = get_version_from_build_id(domain, build_id)

    local_save = update_last_sync(user, app_id, sync_date, version)
    if version:
        local_save |= update_latest_builds(user, app_id, sync_date, version)

    app_meta = None
    if device_id:
        if app_id:
            app_meta = DeviceAppMeta(app_id=app_id,
                                     build_id=build_id,
                                     last_sync=sync_date)
        local_save |= update_device_meta(user,
                                         device_id,
                                         device_app_meta=app_meta,
                                         save=False)

    if local_save and save:
        user.save(fire_signals=False)
    return local_save
Exemplo n.º 3
0
    def process_change(self, change):
        synclog = change.get_document()
        if not synclog:
            return

        version = None
        app_id = None
        try:
            sync_date = string_to_utc_datetime(synclog.get('date'))
        except (ValueError, AttributeError):
            return
        build_id = synclog.get('build_id')
        if build_id:
            version, app_id = get_version_and_app_from_build_id(synclog.get('domain'), build_id)
        user_id = synclog.get('user_id')

        if user_id:
            user = CouchUser.get_by_user_id(user_id)
            save = update_last_sync(user, app_id, sync_date, version)
            if version:
                save |= update_latest_builds(user, app_id, sync_date, version)

            app_meta = None
            device_id = synclog.get('device_id')
            if device_id:
                if app_id:
                    app_meta = DeviceAppMeta(app_id=app_id, build_id=build_id, last_sync=sync_date)
                save |= update_device_meta(user, device_id, device_app_meta=app_meta, save=False)

            if save:
                user.save(fire_signals=False)
Exemplo n.º 4
0
def update_user_reporting_data(app_build_id, app_id, couch_user, request):
    def _safe_int(val):
        try:
            return int(val)
        except:
            pass

    app_version = _safe_int(request.GET.get('app_version', ''))
    device_id = request.GET.get('device_id', '')
    last_sync_time = request.GET.get('last_sync_time', '')
    num_unsent_forms = _safe_int(request.GET.get('num_unsent_forms', ''))
    num_quarantined_forms = _safe_int(request.GET.get('num_quarantined_forms', ''))
    commcare_version = request.GET.get('cc_version', '')
    save_user = False
    # if mobile cannot determine app version it sends -1
    if app_version and app_version > 0:
        save_user = update_latest_builds(couch_user, app_id, datetime.utcnow(), app_version)
    try:
        last_sync = adjust_text_to_datetime(last_sync_time)
    except iso8601.ParseError:
        try:
            last_sync = string_to_utc_datetime(last_sync_time)
        except (ValueError, OverflowError):
            last_sync = None
    else:
        save_user |= update_last_sync(couch_user, app_id, last_sync, app_version)
    app_meta = DeviceAppMeta(
        app_id=app_id,
        build_id=app_build_id,
        build_version=app_version,
        last_heartbeat=datetime.utcnow(),
        last_sync=last_sync,
        num_unsent_forms=num_unsent_forms,
        num_quarantined_forms=num_quarantined_forms
    )
    save_user |= update_device_meta(
        couch_user,
        device_id,
        commcare_version=commcare_version,
        device_app_meta=app_meta,
        save=False
    )
    if save_user:
        couch_user.save(fire_signals=False)
Exemplo n.º 5
0
def update_user_reporting_data(app_build_id, app_id, couch_user, request):
    def _safe_int(val):
        try:
            return int(val)
        except:
            pass

    app_version = _safe_int(request.GET.get('app_version', ''))
    device_id = request.GET.get('device_id', '')
    last_sync_time = request.GET.get('last_sync_time', '')
    num_unsent_forms = _safe_int(request.GET.get('num_unsent_forms', ''))
    num_quarantined_forms = _safe_int(
        request.GET.get('num_quarantined_forms', ''))
    commcare_version = request.GET.get('cc_version', '')
    save_user = False
    # if mobile cannot determine app version it sends -1
    if app_version and app_version > 0:
        save_user = update_latest_builds(couch_user, app_id, datetime.utcnow(),
                                         app_version)
    try:
        last_sync = adjust_text_to_datetime(last_sync_time)
    except iso8601.ParseError:
        try:
            last_sync = string_to_utc_datetime(last_sync_time)
        except (ValueError, OverflowError):
            last_sync = None
    else:
        save_user |= update_last_sync(couch_user, app_id, last_sync,
                                      app_version)
    app_meta = DeviceAppMeta(app_id=app_id,
                             build_id=app_build_id,
                             build_version=app_version,
                             last_heartbeat=datetime.utcnow(),
                             last_sync=last_sync,
                             num_unsent_forms=num_unsent_forms,
                             num_quarantined_forms=num_quarantined_forms)
    save_user |= update_device_meta(couch_user,
                                    device_id,
                                    commcare_version=commcare_version,
                                    device_app_meta=app_meta,
                                    save=False)
    if save_user:
        couch_user.save(fire_signals=False)
Exemplo n.º 6
0
def mark_last_synclog(domain, user, app_id, build_id, sync_date, latest_build_date, device_id,
        device_app_meta, commcare_version=None, build_profile_id=None, save_user=True):
    version = None
    if build_id:
        version = get_version_from_build_id(domain, build_id)

    local_save = False
    if sync_date:
        # sync_date could be null if this is called from a heartbeat request
        local_save |= update_last_sync(user, app_id, sync_date, version)
    if version:
        local_save |= update_latest_builds(user, app_id, latest_build_date, version, build_profile_id=build_profile_id)

    if device_id:
        local_save |= update_device_meta(user, device_id, commcare_version=commcare_version,
            device_app_meta=device_app_meta, save=False)

    if local_save and save_user:
        user.save(fire_signals=False)
    return local_save