# HG changeset patch # User cavaliet # Date 1394810862 -3600 # Node ID 09051e8a61dda885ecbc25bd91d6ed409eaa3a74 # Parent 3f2a118121b79d283ad83cf60acb820fbc997d76 v0.8.8 : avoid imported collection doubloon diff -r 3f2a118121b7 -r 09051e8a61dd src/egonomy/__init__.py --- a/src/egonomy/__init__.py Fri Mar 14 12:04:25 2014 +0100 +++ b/src/egonomy/__init__.py Fri Mar 14 16:27:42 2014 +0100 @@ -1,4 +1,4 @@ -VERSION = (0, 8, 7, "final", 1) +VERSION = (0, 8, 8, "final", 1) VERSION_STR = unicode(".".join(map(lambda i:"%02d" % (i,), VERSION[:2]))) diff -r 3f2a118121b7 -r 09051e8a61dd src/egonomy/views.py --- a/src/egonomy/views.py Fri Mar 14 12:04:25 2014 +0100 +++ b/src/egonomy/views.py Fri Mar 14 16:27:42 2014 +0100 @@ -366,7 +366,7 @@ frg.image = img frg.coordinates = frg_path # We build the svg xml - file = os.path.join(settings.MEDIA_ROOT, str(img.info.image_file)) + file_path = os.path.join(settings.MEDIA_ROOT, str(img.info.image_file)) image_file = default.kvstore.get_or_set(ImageFile(img.info.image_file)) ratio = int(100 * frg.ratio * image_file.ratio) svg = '\n\ @@ -375,8 +375,8 @@ \n\ \n\ \n\ - \n\ - \n\ + \n\ + \n\ ' # We save the svg file uid = str(uuid.uuid1()) @@ -387,7 +387,7 @@ # We execute the batik command args = ["java", "-jar", settings.BATIK_RASTERIZER_PATH, svg_file.name] p = subprocess.Popen(args, stdout=subprocess.PIPE,stderr=subprocess.PIPE) - out, err = p.communicate() + _, err = p.communicate() if p.returncode!=0: return HttpResponse("Batik error : " + str(err)) @@ -804,6 +804,30 @@ return HttpResponse("Wrong image id. It must be like 'XX/XXXXXXX.jpg'.", status=400) if len(img_ids)==0: return HttpResponse("imagelist must not be empty.") + # First we check if the user has not imported a collection with exactly the same images. + user_collections = Collection.objects.filter(author=request.user) + img_content_type = ContentType.objects.get_for_model(Image) + for uc in user_collections: + items = CollectionItem.objects.filter(collection=uc).select_related('content_type', 'object_id').order_by("order") + # We check length + if len(items)==len(img_ids): + # We check if all items are images + all_items_are_img = True + for i in items: + if i.content_type != img_content_type: + all_items_are_img = False + break + # If necessary, we check if all img's ids are the same + if all_items_are_img: + col_img_ids = items.values_list('object_id', flat=True) + same_ids = True + for i in img_ids: + if i not in col_img_ids: + same_ids = False + break + if same_ids: + return redirect("view_collection", collection_pk=uc.pk) + # New collection col = Collection() col.author = request.user @@ -813,13 +837,12 @@ col.publication_type = 1 col.public = True col.save() - content_type = ContentType.objects.get_for_model(Image) order = 1 for i in img_ids: item = get_object_or_404(Image, id=i) col_item = CollectionItem() col_item.collection = col - col_item.content_type = content_type + col_item.content_type = img_content_type col_item.object_id = i col_item.content_object = item col_item.description = ""