def put(user_id: int) -> Any: """Set user info.""" if get_current_user().id != user_id: raise AccessForbiddenException( "Cannot update user's information for someone else.") set_user_info(user_id, request.json['firstName'], request.json['lastName']) return {'success': True}, 200
def post(user_id: int) -> Any: """Set current user's settings. If settings' param is not specified in request, it is not updated.""" user = get_current_user() if user.id != user_id: raise AccessForbiddenException( "Cannot update settings for someone else.") if request.json.get('skipTutorial', None) is not None: set_user_settings('skip_tutorial', request.json['skipTutorial']) return {'success': True}, 200
def create_empty_scan(dataset_key: str, declared_number_of_slices: int) -> Scan: """Create new empty scan. :param dataset_key: string with dataset key :param declared_number_of_slices: number of Slices that will be uploaded :return: Newly created Scan object """ user = get_current_user() dataset = DatasetsRepository.get_dataset_by_key(dataset_key) return ScansRepository.add_new_scan(dataset, declared_number_of_slices, user)
def create_empty_scan(category_key: str, declared_number_of_slices: int) -> Scan: """Create new empty scan. :param category_key: string with category key :param declared_number_of_slices: number of Slices that will be uploaded :return: Newly created Scan object """ user = get_current_user() category = ScanCategoriesRepository.get_category_by_key(category_key) return ScansRepository.add_new_scan(category, declared_number_of_slices, user)
def get_random_scan(category_key: str) -> Scan: """Fetch random scan for labeling. :param category_key: unique key identifying category :return: Scan Metadata object """ user = get_current_user() category = ScanCategoriesRepository.get_category_by_key(category_key) try: scan = ScansRepository.get_random_scan(category, user) if not scan: raise NotFoundException( 'Could not find any Scan for this category!') return scan except NoResultFound: raise NotFoundException('Could not find any Scan for this category!')
def add_label(scan_id: ScanID, elements: List[Dict], files: Dict[str, bytes], labeling_time: LabelingTime) -> Label: """Add label to given scan. :param scan_id: ID of a given scan :param elements: List of JSONs describing elements for a single label :param files: mapping of uploaded files (name and content) :param labeling_time: time in seconds that user spent on labeling :return: Label object """ user = get_current_user() try: label = LabelsRepository.add_new_label(scan_id, user, labeling_time) except IntegrityError: raise NotFoundException('Could not find Scan for that id!') for element in elements: add_label_element(element, label.id, files) return label
def get_random_scan(task_key: str) -> Scan: """Fetch random scan from specified Task for labeling. :param task_key: unique key identifying task :return: Scan Metadata object """ task = TasksRepository.get_task_by_key(task_key) if not task: raise InvalidArgumentsException('Task key {} is invalid!'.format(task_key)) user = get_current_user() scan = ScansRepository.get_random_scan(task, user) if not scan: raise NotFoundException('Could not find any Scan for this task!') predefined_label = LabelsRepository.get_predefined_label_for_scan_in_task(scan, task) if predefined_label: scan.predefined_label_id = predefined_label.id return scan
def add_label(scan_id: ScanID, task_key: str, elements: List[Dict], # pylint: disable-msg=too-many-arguments files: Dict[str, bytes], labeling_time: LabelingTime, comment: str = None, is_predefined: bool = False) -> Label: """Add label to given scan. :param scan_id: ID of a given scan :param task_key: Key of Task :param elements: List of JSONs describing elements for a single label :param files: mapping of uploaded files (name and content) :param labeling_time: time in seconds that user spent on labeling :param comment: (optional) comment describing a label :param is_predefined: (optional) mark such Label as predefined to show on Labeling Page :return: Label object """ user = get_current_user() try: label = LabelsRepository.add_new_label(scan_id, task_key, user, labeling_time, comment, is_predefined) except IntegrityError: raise NotFoundException('Could not find Scan for that id!') for element in elements: add_label_element(element, label.id, files) return label
def get() -> Any: """Get user info.""" user = get_current_user() return user, 200
def set_user_settings(name: str, value: object) -> None: """Set current user's settings parameter of specified name to provided value.""" UsersRepository.set_user_settings(get_current_user(), name, value)