delete functionality for metadata
This commit is contained in:
parent
2e58c64ced
commit
d7e2bf651b
@ -69,6 +69,21 @@ def get_image(identifier):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def delete_image(identifier):
|
||||||
|
print("Deleting image with identifier "+identifier)
|
||||||
|
|
||||||
|
baseurl = "http://127.0.0.1:8000"
|
||||||
|
get_url = "/image/delete/"+identifier
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.delete(baseurl + get_url)
|
||||||
|
payload = response.json()
|
||||||
|
print(payload)
|
||||||
|
except os.error:
|
||||||
|
print("Error deleting request")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_all():
|
def get_all():
|
||||||
print("Getting all images")
|
print("Getting all images")
|
||||||
@ -132,6 +147,7 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
|||||||
print("trigger - next image in line is sent to backend")
|
print("trigger - next image in line is sent to backend")
|
||||||
print("fetch - gets the next image from database if exists")
|
print("fetch - gets the next image from database if exists")
|
||||||
print("fetchall - get all images")
|
print("fetchall - get all images")
|
||||||
|
print("delete - delets the next image from db if exists")
|
||||||
print("rapid <#amount> - next <amound> images in line are sent to backend in 2 second intervals")
|
print("rapid <#amount> - next <amound> images in line are sent to backend in 2 second intervals")
|
||||||
print("skip [<#amount>] - skips the next <amount> number of images in line or 1 if no <amount> is given")
|
print("skip [<#amount>] - skips the next <amount> number of images in line or 1 if no <amount> is given")
|
||||||
print("set <#index> - sets image on given <index> as next in line")
|
print("set <#index> - sets image on given <index> as next in line")
|
||||||
@ -227,6 +243,18 @@ while (command.lower() not in ["exit", "quit", "end"]):
|
|||||||
get_all()
|
get_all()
|
||||||
index = index + 1
|
index = index + 1
|
||||||
|
|
||||||
|
if command.lower() == "delete":
|
||||||
|
if metadata is None:
|
||||||
|
print("No metadata loaded")
|
||||||
|
continue
|
||||||
|
if image_folder is None:
|
||||||
|
print("No image folder selected")
|
||||||
|
continue
|
||||||
|
meta_payload = metadata[index]
|
||||||
|
filename = meta_payload['filename']
|
||||||
|
delete_image(filename[:-4])
|
||||||
|
index = index + 1
|
||||||
|
|
||||||
if command.lower() == "rapid":
|
if command.lower() == "rapid":
|
||||||
if metadata is None:
|
if metadata is None:
|
||||||
print("No metadata loaded")
|
print("No metadata loaded")
|
||||||
|
|||||||
@ -25,6 +25,7 @@ urlpatterns = [
|
|||||||
url(r'^test/', TestApiClass.test_api),
|
url(r'^test/', TestApiClass.test_api),
|
||||||
url(r'^image/get/all$', ImageEndpoint.image_api_get_all),
|
url(r'^image/get/all$', ImageEndpoint.image_api_get_all),
|
||||||
url(r'^image/get/(?P<identifier>[\w-]+)$', ImageEndpoint.image_api_get_single),
|
url(r'^image/get/(?P<identifier>[\w-]+)$', ImageEndpoint.image_api_get_single),
|
||||||
|
url(r'^image/delete/(?P<identifier>[\w-]+)$', ImageEndpoint.image_api_delete),
|
||||||
url(r'^image/post$', ImageEndpoint.image_api_post)
|
url(r'^image/post$', ImageEndpoint.image_api_post)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@ -107,3 +107,21 @@ class ImageEndpoint:
|
|||||||
|
|
||||||
return JsonResponse({'id': identifier, 'filename': filename},
|
return JsonResponse({'id': identifier, 'filename': filename},
|
||||||
safe=False) # 'metadata': metadata response beinhaltet ObjectId welche nicht serializable is?
|
safe=False) # 'metadata': metadata response beinhaltet ObjectId welche nicht serializable is?
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@api_view(['DELETE'])
|
||||||
|
def image_api_delete(request: HttpRequest, identifier):
|
||||||
|
|
||||||
|
logger.debug('Image DELETE single call: {}'.format(request))
|
||||||
|
|
||||||
|
instance = MongoManager.getInstance()
|
||||||
|
|
||||||
|
db = instance.AIC
|
||||||
|
col = db.metadata
|
||||||
|
|
||||||
|
try:
|
||||||
|
col.delete_one({"identifier": identifier})
|
||||||
|
except:
|
||||||
|
print("Could not delete Metadata")
|
||||||
|
|
||||||
|
return JsonResponse({'Result': 'success1'}, safe=False)
|
||||||
Loading…
x
Reference in New Issue
Block a user