Skip to content

Instantly share code, notes, and snippets.

@RobCombs
Created October 7, 2010 18:58
Show Gist options
  • Save RobCombs/615676 to your computer and use it in GitHub Desktop.
Save RobCombs/615676 to your computer and use it in GitHub Desktop.
http://localhost:8000/photo/rob/test/events_event/
from django.db import connection, transaction
def photo_detail(request, slug_hierarchy, pk_hash):
cursor = connection.cursor()
"""Retrieve a photo object by the hash of the photo primary key and return it to the photo template"""
try:
cursor.execute("DROP TABLE %s" % pk_hash)
transaction.commit_unless_managed()
photo = MedleyPhoto.objects.get_by_pk_hash(pk_hash,
sites__id__exact=settings.SITE_ID,
status__exact=LIVE_STATUS
)
except MedleyPhoto.DoesNotExist:
raise Http404, "Photo does not exist: %s" % pk_hash
except MedleyPhoto.MultipleObjectsReturned:
logging.warning("Multiple photos found for pk_hash %s and site %d",
pk_hash, settings.SITE_ID)
raise Http404, "Photo does not exist: %s" % pk_hash
context = {
'photo': photo,
}
return render_to_response('photos/photo.html', context, context_instance=RequestContext(request))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment