summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js8
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py33
2 files changed, 24 insertions, 17 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
index 328997af3b..98e87f4a6b 100644
--- a/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
+++ b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
@@ -9,6 +9,8 @@ function newCustomImageModalInit(){
9 var nameInput = imgCustomModal.find('input'); 9 var nameInput = imgCustomModal.find('input');
10 10
11 var invalidMsg = "Image names cannot contain spaces or capital letters. The only allowed special character is dash (-)."; 11 var invalidMsg = "Image names cannot contain spaces or capital letters. The only allowed special character is dash (-).";
12 var duplicateImageMsg = "An image with this name already exists in this project.";
13 var duplicateRecipeMsg = "A non-image recipe with this name already exists.";
12 14
13 newCustomImgBtn.click(function(e){ 15 newCustomImgBtn.click(function(e){
14 e.preventDefault(); 16 e.preventDefault();
@@ -22,8 +24,10 @@ function newCustomImageModalInit(){
22 console.warn(ret.error); 24 console.warn(ret.error);
23 if (ret.error === "invalid-name") { 25 if (ret.error === "invalid-name") {
24 showError(invalidMsg); 26 showError(invalidMsg);
25 } else if (ret.error === "already-exists") { 27 } else if (ret.error === "image-already-exists") {
26 showError("An image with this name already exists. Image names must be unique."); 28 showError(duplicateImageMsg);
29 } else if (ret.error === "recipe-already-exists") {
30 showError(duplicateRecipeMsg);
27 } 31 }
28 } else { 32 } else {
29 imgCustomModal.modal('hide'); 33 imgCustomModal.modal('hide');
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index a11c9da5f5..9744f4efaf 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -2409,21 +2409,24 @@ if True:
2409 if re.search(r'[^a-z|0-9|-]', request.POST["name"]): 2409 if re.search(r'[^a-z|0-9|-]', request.POST["name"]):
2410 return {"error": "invalid-name"} 2410 return {"error": "invalid-name"}
2411 2411
2412 # Are there any recipes with the name already? 2412 custom_images = CustomImageRecipe.objects.all()
2413 for existing_recipe in Recipe.objects.filter( 2413
2414 name=request.POST["name"]): 2414 # Are there any recipes with this name already in our project?
2415 try: 2415 existing_image_recipes_in_project = custom_images.filter(
2416 ci = CustomImageRecipe.objects.get(pk=existing_recipe.pk) 2416 name=request.POST["name"], project=params["project"])
2417 if ci.project == params["project"]: 2417
2418 return {"error": "already-exists" } 2418 if existing_image_recipes_in_project.count() > 0:
2419 else: 2419 return {"error": "image-already-exists"}
2420 # It is a CustomImageRecipe but not in our project 2420
2421 # this is fine so 2421 # Are there any recipes with this name which aren't custom
2422 continue 2422 # image recipes?
2423 except: 2423 custom_image_ids = custom_images.values_list('id', flat=True)
2424 # It isn't a CustomImageRecipe so is a recipe from 2424 existing_non_image_recipes = Recipe.objects.filter(
2425 # another source. 2425 Q(name=request.POST["name"]) & ~Q(pk__in=custom_image_ids)
2426 return {"error": "already-exists" } 2426 )
2427
2428 if existing_non_image_recipes.count() > 0:
2429 return {"error": "recipe-already-exists"}
2427 2430
2428 # create layer 'Custom layer' and verion if needed 2431 # create layer 'Custom layer' and verion if needed
2429 layer = Layer.objects.get_or_create( 2432 layer = Layer.objects.get_or_create(