def synchronization(api_sync_object, checkpoint, date, limit, offset, params=None, **kwargs): has_next = True next_url = "" params = params or {} while has_next: meta, objects = api_sync_object.get_objects_function( next_url_params=next_url, limit=limit, offset=offset, filters=api_sync_object.filters, **kwargs) if checkpoint: save_checkpoint(checkpoint, api_sync_object.name, meta.get('limit') or limit, meta.get('offset') or offset, date) with transaction.atomic(): for obj in objects: api_sync_object.sync_function(obj, **params) has_next, next_url = get_next_meta_url(has_next, meta, next_url)
def synchronization(api_sync_object, checkpoint, date, limit, offset, params=None, atomic=False, **kwargs): has_next = True next_url = "" params = params or {} while has_next: meta, objects = api_sync_object.get_objects_function( next_url_params=next_url, limit=limit, offset=offset, filters=api_sync_object.filters, **kwargs ) if checkpoint: save_checkpoint(checkpoint, api_sync_object.name, meta.get('limit') or limit, meta.get('offset') or offset, date) if atomic: with transaction.atomic(): for obj in objects: api_sync_object.sync_function(obj, **params) else: for obj in objects: api_sync_object.sync_function(obj, **params) has_next, next_url = get_next_meta_url(has_next, meta, next_url)
def synchronization(name, get_objects_function, sync_function, checkpoint, date, limit, offset, **kwargs): has_next = True next_url = "" while has_next: meta, objects = get_objects_function(next_url_params=next_url, limit=limit, offset=offset, **kwargs) if checkpoint: save_checkpoint(checkpoint, name, meta.get('limit') or limit, meta.get('offset') or offset, date) for obj in objects: sync_function(obj) has_next, next_url = get_next_meta_url(has_next, meta, next_url)
def webusers_sync(project, endpoint, checkpoint, limit, offset, **kwargs): has_next = True next_url = None while has_next: meta, webusers = endpoint.get_webusers(next_url_params=next_url, **kwargs) save_checkpoint(checkpoint, "webuser", meta.get('limit') or limit, meta.get('offset') or offset, kwargs.get('date', None)) for user in webusers: if user.email or user.username: sync_ilsgateway_webuser(project, user) has_next, next_url = get_next_meta_url(has_next, meta, next_url)
def locations_sync(project, endpoint, checkpoint, fetch_groups=True, **kwargs): has_next = True next_url = None while has_next: meta, locations = endpoint.get_locations(next_url_params=next_url, **kwargs) save_checkpoint(checkpoint, 'location_%s' % kwargs['filters']['type'], meta.get('limit') or kwargs.get('limit'), meta.get('offset') or kwargs.get('offset'), kwargs.get('date', None)) for location in locations: sync_ilsgateway_location(project, endpoint, location, fetch_groups=fetch_groups) has_next, next_url = get_next_meta_url(has_next, meta, next_url)
def smsusers_sync(project, endpoint, checkpoint, extension=None, **kwargs): has_next = True next_url = "" while has_next: meta, users = endpoint.get_smsusers(next_url_params=next_url, **kwargs) save_checkpoint(checkpoint, "smsuser", meta.get('limit') or kwargs.get('limit'), meta.get('offset') or kwargs.get('offset'), kwargs.get('date', None)) for user in users: sms_user = sync_ilsgateway_smsuser(project, user) if extension: extension(sms_user, user) has_next, next_url = get_next_meta_url(has_next, meta, next_url)