Esempio n. 1
0
def update_annotations(image_id):
    data = request.json
    attributes = ["annotations"]
    attribute_missing = check_attributes(data, attributes)
    if attribute_missing:
        return jsonify(attribute_missing), 422

    success = images.update_annotations(image_id, data["annotations"])
    if success:
        return jsonify(success), 200
    else:
        return jsonify({"error": "Could update annotations for image"}), 409
Esempio n. 2
0
def add_image():
    """adds a image to the database"""
    data = request.json
    attributes = ["file-name", "file-extension", "path", "width", "height"]
    attribute_missing = check_attributes(data, attributes)
    if attribute_missing:
        return jsonify(attribute_missing), 422

    success = images.add_image(data["file-name"], data["file-extension"],
                               data["path"], data["width"], data["height"])
    if success:
        return jsonify(success), 200
    else:
        return jsonify({"error": "Could not add image"}), 409
Esempio n. 3
0
def add_collection():
    """adds a collection to the database"""
    data = request.json
    attributes = ["label", "description", "attribution", "logo"]
    attribute_missing = check_attributes(data, attributes)
    if attribute_missing:
        return jsonify(attribute_missing), 422

    success = collections.add_collection(data["label"],
                                         data["description"],
                                         data["attribution"],
                                         data["logo"], g.user.username)
    if success:
        return jsonify(success), 200
    else:
        return jsonify({"error": "Could not add collection"}), 409
Esempio n. 4
0
def add_item(collection_id):
    """add a item to the database"""
    data = request.json
    attributes = ["label", "description", "attribution", "logo"]
    attribute_missing = check_attributes(data, attributes)
    if attribute_missing:
        return jsonify(attribute_missing), 422
    metadata = extract_metadata(data)
    success = items.add_item(data["label"], data["description"],
                             data["attribution"], data["logo"], metadata,
                             g.user.username)
    if success:
        collections.add_item_to_collection(collection_id, success["_id"])
        return jsonify(success), 200
    else:
        return jsonify({"error": "Could not add item"}), 409
Esempio n. 5
0
def update_collection(collection_id):
    """update a collection"""

    data = request.json
    attributes = ["label", "description", "attribution", "logo"]
    attribute_missing = check_attributes(data, attributes)
    if attribute_missing:
        return jsonify(attribute_missing), 422

    success = collections.update_collection(collection_id,
                                            data["label"],
                                            data["description"],
                                            data["attribution"],
                                            data["logo"],
                                            )
    if success:
        return jsonify(success), 200
    else:
        return jsonify({"error": "Could not update collection " + collection_id}), 409
Esempio n. 6
0
def update_item(item_id):
    """update an item"""

    data = request.json
    attributes = ["label", "description", "attribution", "logo"]
    attribute_missing = check_attributes(data, attributes)
    if attribute_missing:
        return jsonify(attribute_missing), 422
    metadata = extract_metadata(data)
    success = items.update_metadata(
        item_id, {
            "label": data["label"],
            "description": data["description"],
            "attribution": data["attribution"],
            "logo": data["logo"]
        }, metadata)
    if success:
        return jsonify(success), 200
    else:
        return jsonify({"error": "Could not update item " + item_id}), 409