Author: gregoryjnewman
Date: Thu Sep 11 13:28:09 2008
New Revision: 869
Modified:
trunk/pinax/local_apps/photos/views.py
trunk/pinax/templates/photos/photo_right_panel.html
Log:
adding list of dictionaries for tribe photo pools to show add or remove
buttons on photo details page
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 13:28:09 2008
@@ -52,7 +52,19 @@
tribes = Tribe.objects.filter(members=request.user)
projects = Project.objects.filter(members=request.user)
photo = get_object_or_404(Photos, id=id)
+
+
+ if tribes:
+ t = []
+ for tribe in tribes:
+ phototribe = Tribe.objects.get(pk=tribe.id)
+ if phototribe.photos.filter(photo=photo).count():
+
t.append({"name":tribe.name, "slug":tribe.slug, "id":tribe.id,
"has_photo":True})
+ else:
+
t.append({"name":tribe.name, "slug":tribe.slug, "id":tribe.id,
"has_photo":False})
+
# @@@ is there a better way?
+ # TODO: redo this exif routine
photo_path = os.path.join(settings.MEDIA_ROOT, "photologue/photos",
photo.image_filename())
f = open(photo_path, 'rb')
exif = EXIF.process_file(f)
@@ -74,31 +86,33 @@
# 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 project 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,
- "photo": photo,
- "is_me": is_me,
- "other_user": other_user,
- "projects": projects,
- "tribes": tribes},
context_instance=RequestContext(request))
+ return HttpResponseRedirect(reverse('details',
args=(photo.id,)))
- if request.method == "POST" and request.POST["action"]
== "add_to_tribe":
- tribeid = request.POST["tribe"]
- mytribe = Tribe.objects.get(pk=tribeid)
- 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,
- "photo": photo,
- "is_me": is_me,
- "other_user": other_user,
- "projects": projects,
- "tribes": tribes},
context_instance=RequestContext(request))
+ if request.method == "POST":
+ if request.POST["action"] == "addtotribe":
+ tribeid = request.POST["tribe"]
+ mytribe = Tribe.objects.get(pk=tribeid)
+ 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 HttpResponseRedirect(reverse('details',
args=(photo.id,)))
+
+ if request.POST["action"] == "removefromtribe":
+ tribeid = request.POST["tribe"]
+ mytribe = Tribe.objects.get(pk=tribeid)
+ if mytribe.photos.filter(photo=photo).count():
+ mytribe.photos.destroy(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 HttpResponseRedirect(reverse('details',
args=(photo.id,)))
+
return render_to_response("photos/details.html", {
@@ -108,7 +122,7 @@
"is_me": is_me,
"other_user": other_user,
"projects": projects,
- "tribes": tribes
+ "tribes": t
}, context_instance=RequestContext(request))
@login_required
@@ -133,13 +147,3 @@
return HttpResponseRedirect(reverse("photos_yours"))
else:
return HttpResponseRedirect(reverse("photos_yours"))
-
[EMAIL PROTECTED]
-def addproject(request, project):
- photo = get_object_or_404(Photos, id=id)
- title = photo.title
- project = Project.objects.get(pk=tribe)
- pool = Pool(content_type=photo)
- pool.save()
- request.user.message_set.create(message=_("Successfully add photo '%s'
to tribe") % title)
- return HttpResponseRedirect(reverse("photos_yours", photo))
Modified: trunk/pinax/templates/photos/photo_right_panel.html
==============================================================================
--- trunk/pinax/templates/photos/photo_right_panel.html (original)
+++ trunk/pinax/templates/photos/photo_right_panel.html Thu Sep 11 13:28:09
2008
@@ -64,10 +64,14 @@
<h2>Add photo to tribe</h2>
{% for tribe in tribes %}
<form action="{% url details photo.id %}" method="POST">
- <input type="hidden" name="action" value="add_to_tribe"/>
<input type="hidden" name="tribe" value="{{ tribe.id }}"/>
+ {% if tribe.has_photo %}
+ {{ tribe.name }}
+ {% else %}
+ <input type="hidden" name="action" value="addtotribe"/>
<input type="submit" value="add"/>
- <a href="{% url tribes.views.tribe tribe.slug %}">{{
tribe.name }}</a>
+ {{ tribe.name }}
+ {% endif %}
</form>
{% endfor %}
{% endif %}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---