Author: brosner
Date: Thu Sep 11 00:28:03 2008
New Revision: 867

Modified:
    trunk/pinax/local_apps/photos/views.py

Log:
Fixed a condition where adding a photo to a tribe caused an IntegrityError  
with a duplicate key.

Modified: trunk/pinax/local_apps/photos/views.py
==============================================================================
--- trunk/pinax/local_apps/photos/views.py      (original)
+++ trunk/pinax/local_apps/photos/views.py      Thu Sep 11 00:28:03 2008
@@ -81,8 +81,12 @@
          if request.method == "POST" and request.POST["action"]  
== "add_to_tribe":
              tribeid = request.POST["tribe"]
              mytribe = Tribe.objects.get(pk=tribeid)
-            mytribe.photos.create(photo=photo)
-            request.user.message_set.create(message=_("Successfully add  
photo '%s' to tribe") % title)
+            if not mytribe.photos.filter(photo=photo).count():
+                mytribe.photos.create(photo=photo)
+                request.user.message_set.create(message=_("Successfully  
add photo '%s' to tribe") % title)
+            else:
+                # TODO: this applies to pinax in general. dont use  
ugettext_lazy here. its usage is fragile.
+                request.user.message_set.create(message=_("Did not add  
photo '%s' to tribe because it already exists.") % title)
              # TODO: figure out why reverse doesn't work and redo this
              return render_to_response("photos/details.html", {
                        "host": host,

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to