def test_example_restricting_label_edits(self):
    dataset = foz.load_zoo_dataset('quickstart').clone()
    view = dataset.match((F('ground_truth.detections').filter((F('label') == 'person')).length() > 1)).limit(1)
    previous_labels = view.values('ground_truth.detections', unwind=True)
    previous_person_labels = view.filter_labels('ground_truth', (F('label') == 'person')).values('ground_truth.detections', unwind=True)
    anno_key = 'cvat_edit_restrictions'
    attributes = {'sex': {'type': 'select', 'values': ['male', 'female']}, 'age': {'type': 'text'}}
    results = view.annotate(anno_key, label_field='ground_truth', classes=['person', 'test'], attributes=attributes, allow_additions=False, allow_deletions=False, allow_label_edits=False, allow_spatial_edits=False)
    self.assertIsNotNone(dataset.get_annotation_info(anno_key))
    task_id = results.task_ids[0]
    api = results.connect_to_api()
    deleted_id = previous_person_labels[0].id
    _delete_shape(api, task_id, deleted_id)
    _create_annotation(api, task_id, shape='person')
    edited_id = previous_person_labels[1].id
    _update_shape(api, task_id, edited_id, label='test', points=[10, 20, 30, 40], attributes=[('sex', 'male')])
    dataset.load_annotations(anno_key, cleanup=True)
    api.close()
    labels = view.values('ground_truth.detections', unwind=True)
    person_labels = view.filter_labels('ground_truth', (F('label') == 'person')).values('ground_truth.detections', unwind=True)
    self.assertListEqual([d.label for d in labels], [d.label for d in previous_labels])
    self.assertListEqual([d.bounding_box for d in labels], [d.bounding_box for d in previous_labels])
    self.assertListEqual([d.id for d in labels], [d.id for d in previous_labels])
    self.assertEqual(len(dataset.filter_labels('ground_truth', (F('sex') == 'male'))), 1)
def test_example_restricting_label_edits(self):
    dataset = foz.load_zoo_dataset('quickstart').clone()
    view = dataset.match((F('ground_truth.detections').filter((F('label') == 'person')).length() > 1)).limit(1)
    previous_labels = view.values('ground_truth.detections', unwind=True)
    previous_person_labels = view.filter_labels('ground_truth', (F('label') == 'person')).values('ground_truth.detections', unwind=True)
    anno_key = 'cvat_edit_restrictions'
    attributes = {'sex': {'type': 'select', 'values': ['male', 'female']}, 'age': {'type': 'text'}}
    results = view.annotate(anno_key, label_field='ground_truth', classes=['person', 'test'], attributes=attributes, allow_additions=False, allow_deletions=False, allow_label_edits=False, allow_spatial_edits=False)
    self.assertIsNotNone(dataset.get_annotation_info(anno_key))
    task_id = results.task_ids[0]
    api = results.connect_to_api()
    deleted_id = previous_person_labels[0].id
    _delete_shape(api, task_id, deleted_id)
    _create_annotation(api, task_id, shape='person')
    edited_id = previous_person_labels[1].id
    _update_shape(api, task_id, edited_id, label='test', points=[10, 20, 30, 40], attributes=[('sex', 'male')])
    dataset.load_annotations(anno_key, cleanup=True)
    api.close()
    labels = view.values('ground_truth.detections', unwind=True)
    person_labels = view.filter_labels('ground_truth', (F('label') == 'person')).values('ground_truth.detections', unwind=True)
    self.assertListEqual([d.label for d in labels], [d.label for d in previous_labels])
    self.assertListEqual([d.bounding_box for d in labels], [d.bounding_box for d in previous_labels])
    self.assertListEqual([d.id for d in labels], [d.id for d in previous_labels])
    self.assertEqual(len(dataset.filter_labels('ground_truth', (F('sex') == 'male'))), 1)