src/egonomy/views.py
changeset 234 886cbc53b854
parent 226 d602d53379e7
child 237 923b5823ef15
--- a/src/egonomy/views.py	Wed Jul 10 19:06:54 2013 +0200
+++ b/src/egonomy/views.py	Fri Jul 12 13:42:06 2013 +0200
@@ -688,7 +688,6 @@
 
 
 
-
 def remove_item_from_collection(request):
     
     col_pk = request.GET["collection_pk"] or None
@@ -707,13 +706,13 @@
     # We check if the current user is the collection's author
     if col.author != request.user:
         return HttpResponseForbidden(_("You are not allowed to modify this collection."))
-    # We update the collection's modification date because by create an item we don't really touch the collection objet
+    # We update the collection's modification date because by creating an item we don't touch the collection object
     col.modification = datetime.now()
     col.save()
     
     # Test item's pk
     if not item_pk:
-        return HttpResponse("item-id must be set.", status_code=400)
+        return HttpResponse("item_pk must be set.", status_code=400)
     # Get item
     item = get_object_or_404(CollectionItem, pk=item_pk)
     # Everything has been checked, we can delete the item
@@ -724,3 +723,41 @@
     # It is an ajax call, everything is saved and we return the collection's url
     #return HttpResponse(reverse("view_collection", args=[col_pk]))
 
+
+
+@login_required
+def modify_item_in_collection(request):
+    
+    item_pk = request.POST["item-pk"] or None
+    col_pk = request.POST["collection_pk"] or None
+    description = request.POST["item-description"] or None
+    
+    # Test collection
+    try:
+        col_pk = int(col_pk)
+    except:
+        return HttpResponse("Collection number invalid.", status_code=400)
+    col = get_object_or_404(Collection.objects.select_related('author'), pk=col_pk)
+    # We check if the current user is the collection's author
+    if col.author != request.user:
+        return HttpResponseForbidden(_("You are not allowed to modify this collection."))
+    # We update the collection's modification date because by modifying an item we don't touch the collection object
+    col.modification = datetime.now()
+    col.save()
+    
+    # Test item's pk
+    if not item_pk:
+        return HttpResponse("item_pk must be set.", status_code=400)
+    # Get item
+    item = get_object_or_404(CollectionItem, pk=item_pk)
+    if item.collection != col:
+        return HttpResponse("Item and collection are not related.", status_code=400)
+    # Everything has been checked, we can modify and save the item
+    item.description = description
+    item.save()
+    
+    # It is an ajax call, we juste return "ok"
+    return HttpResponse("modifyok")
+
+
+