Mercurial > public > sg101
annotate gpp/forums/views/attachments.py @ 492:3c48a555298d
Added a custom tag to display a link to a profile. Refactored the avatar tag to optionally display a profile link around the image. Removed the width and height attributes from the avatar image tag. I think this was causing disk hits whenever those properties were not cached. The avatar tag is now an inclusion tag.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 22 Oct 2011 00:07:50 +0000 (2011-10-22) |
parents | 72fd300685d5 |
children |
rev | line source |
---|---|
bgneal@285 | 1 """ |
bgneal@285 | 2 This module contains views for working with post attachments. |
bgneal@285 | 3 """ |
bgneal@285 | 4 from django.http import HttpResponse |
bgneal@285 | 5 from django.http import HttpResponseForbidden |
bgneal@285 | 6 from django.http import HttpResponseBadRequest |
bgneal@285 | 7 from django.http import HttpResponseNotFound |
bgneal@285 | 8 import django.utils.simplejson as json |
bgneal@285 | 9 |
bgneal@285 | 10 from forums.models import Post |
bgneal@285 | 11 |
bgneal@285 | 12 |
bgneal@285 | 13 def fetch_attachments(request): |
bgneal@285 | 14 """ |
bgneal@285 | 15 This view is the target of an AJAX GET request to retrieve the |
bgneal@285 | 16 attachment embed data for a given forum post. |
bgneal@285 | 17 |
bgneal@285 | 18 """ |
bgneal@285 | 19 if not request.user.is_authenticated(): |
bgneal@285 | 20 return HttpResponseForbidden('Please login or register.') |
bgneal@285 | 21 |
bgneal@285 | 22 post_id = request.GET.get('pid') |
bgneal@285 | 23 if post_id is None: |
bgneal@285 | 24 return HttpResponseBadRequest('Missing post ID.') |
bgneal@285 | 25 |
bgneal@285 | 26 try: |
bgneal@285 | 27 post = Post.objects.get(pk=post_id) |
bgneal@285 | 28 except Post.DoesNotExist: |
bgneal@285 | 29 return HttpResponseNotFound("That post doesn't exist.") |
bgneal@286 | 30 |
bgneal@285 | 31 embeds = post.attachments.all().select_related('embed') |
bgneal@285 | 32 data = [{'id': embed.id, 'html': embed.html} for embed in embeds] |
bgneal@285 | 33 |
bgneal@285 | 34 return HttpResponse(json.dumps(data), content_type='application/json') |
bgneal@285 | 35 |