@profile
@login_required
def post(self):
    '\n        Called when saving data from the annotator client\n        '
    data = request.get_json(force=True)
    image = data.get('image')
    dataset = data.get('dataset')
    image_id = image.get('id')
    image_model = ImageModel.objects(id=image_id).first()
    if (image_model is None):
        return ({'success': False, 'message': 'Image does not exist'}, 400)
    db_dataset = current_user.datasets.filter(id=image_model.dataset_id).first()
    if (dataset is None):
        return {'success': False, 'message': 'Could not find associated dataset'}
    db_dataset.update(annotate_url=dataset.get('annotate_url', ''))
    categories = CategoryModel.objects.all()
    annotations = AnnotationModel.objects(image_id=image_id)
    current_user.update(preferences=data.get('user', {}))
    annotated = False
    for category in data.get('categories', []):
        category_id = category.get('id')
        db_category = categories.filter(id=category_id).first()
        if (db_category is None):
            continue
        category_update = {'color': category.get('color')}
        if current_user.can_edit(db_category):
            category_update['keypoint_edges'] = category.get('keypoint_edges', [])
            category_update['keypoint_labels'] = category.get('keypoint_labels', [])
        db_category.update(**category_update)
        for annotation in category.get('annotations', []):
            annotation_id = annotation.get('id')
            db_annotation = annotations.filter(id=annotation_id).first()
            if (db_annotation is None):
                continue
            sessions = []
            total_time = 0
            for session in annotation.get('sessions', []):
                date = datetime.datetime.fromtimestamp((int(session.get('start')) / 1000.0))
                model = SessionEvent(user=current_user.username, created_at=date, milliseconds=session.get('milliseconds'), tools_used=session.get('tools'))
                total_time += session.get('milliseconds')
                sessions.append(model)
            db_annotation.update(add_to_set__events=sessions, inc__milliseconds=total_time, set__isbbox=annotation.get('isbbox', False), set__keypoints=annotation.get('keypoints', []), set__metadata=annotation.get('metadata'), set__color=annotation.get('color'))
            paperjs_object = annotation.get('compoundPath', [])
            if (len(paperjs_object) == 2):
                width = db_annotation.width
                height = db_annotation.height
                (segmentation, area, bbox) = coco_util.paperjs_to_coco(width, height, paperjs_object)
                db_annotation.update(set__segmentation=segmentation, set__area=area, set__isbbox=annotation.get('isbbox', False), set__bbox=bbox, set__paper_object=paperjs_object)
                if (area > 0):
                    annotated = True
    image_model.update(set__metadata=image.get('metadata', {}), set__annotated=annotated, set__category_ids=image.get('category_ids', []), set__regenerate_thumbnail=True, set__num_annotations=annotations.filter(deleted=False, area__gt=0).count())
    return {'success': True}
Called when saving data from the annotator client
@profile
@login_required
def post(self):
    '\n        \n        '
    data = request.get_json(force=True)
    image = data.get('image')
    dataset = data.get('dataset')
    image_id = image.get('id')
    image_model = ImageModel.objects(id=image_id).first()
    if (image_model is None):
        return ({'success': False, 'message': 'Image does not exist'}, 400)
    db_dataset = current_user.datasets.filter(id=image_model.dataset_id).first()
    if (dataset is None):
        return {'success': False, 'message': 'Could not find associated dataset'}
    db_dataset.update(annotate_url=dataset.get('annotate_url', ))
    categories = CategoryModel.objects.all()
    annotations = AnnotationModel.objects(image_id=image_id)
    current_user.update(preferences=data.get('user', {}))
    annotated = False
    for category in data.get('categories', []):
        category_id = category.get('id')
        db_category = categories.filter(id=category_id).first()
        if (db_category is None):
            continue
        category_update = {'color': category.get('color')}
        if current_user.can_edit(db_category):
            category_update['keypoint_edges'] = category.get('keypoint_edges', [])
            category_update['keypoint_labels'] = category.get('keypoint_labels', [])
        db_category.update(**category_update)
        for annotation in category.get('annotations', []):
            annotation_id = annotation.get('id')
            db_annotation = annotations.filter(id=annotation_id).first()
            if (db_annotation is None):
                continue
            sessions = []
            total_time = 0
            for session in annotation.get('sessions', []):
                date = datetime.datetime.fromtimestamp((int(session.get('start')) / 1000.0))
                model = SessionEvent(user=current_user.username, created_at=date, milliseconds=session.get('milliseconds'), tools_used=session.get('tools'))
                total_time += session.get('milliseconds')
                sessions.append(model)
            db_annotation.update(add_to_set__events=sessions, inc__milliseconds=total_time, set__isbbox=annotation.get('isbbox', False), set__keypoints=annotation.get('keypoints', []), set__metadata=annotation.get('metadata'), set__color=annotation.get('color'))
            paperjs_object = annotation.get('compoundPath', [])
            if (len(paperjs_object) == 2):
                width = db_annotation.width
                height = db_annotation.height
                (segmentation, area, bbox) = coco_util.paperjs_to_coco(width, height, paperjs_object)
                db_annotation.update(set__segmentation=segmentation, set__area=area, set__isbbox=annotation.get('isbbox', False), set__bbox=bbox, set__paper_object=paperjs_object)
                if (area > 0):
                    annotated = True
    image_model.update(set__metadata=image.get('metadata', {}), set__annotated=annotated, set__category_ids=image.get('category_ids', []), set__regenerate_thumbnail=True, set__num_annotations=annotations.filter(deleted=False, area__gt=0).count())
    return {'success': True}