def get_api_client(): return api_client.get_authenticated_connection( settings.SHARED_API_USERNAME, settings.SHARED_API_PASSWORD )
def format_errors(error_list): output_list = [] for i, error in enumerate(error_list): if error: field_errors = [] for key in error: field_errors += error[key] output_list.append("Row %s: %s" % (i + 1, ", ".join(field_errors))) return output_list def update_locations(user, locations, async=False): client = api_client.get_authenticated_connection( settings.LOCATION_UPLOADER_USERNAME, settings.LOCATION_UPLOADER_PASSWORD ) username = user.user_data.get("username", "Unknown") user_description = user.get_full_name() if user_description: user_description += " (%s)" % username else: user_description = username errors = [] location_count = len(locations) try: client.prisoner_locations.actions.delete_inactive.post() for i in range(math.ceil(location_count / settings.UPLOAD_REQUEST_PAGE_SIZE)): client.prisoner_locations.post( locations[i * settings.UPLOAD_REQUEST_PAGE_SIZE : (i + 1) * settings.UPLOAD_REQUEST_PAGE_SIZE]