Mercurial > public > sg101
diff gpp/oembed/views.py @ 286:72fd300685d5
For #95. You can now make posts with no text in the body if you have attachments. And now if you create a new topic with an attachment, and the POST fails (say you forgot the topic title), we will now re-attach attachments. Also fixed a bug in the smiley code that would arise if it was asked to markup an empty string.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 23 Oct 2010 20:19:46 +0000 |
parents | 8fd4984d5c3b |
children | 47a7138fcccb |
line wrap: on
line diff
--- a/gpp/oembed/views.py Thu Oct 14 02:39:35 2010 +0000 +++ b/gpp/oembed/views.py Sat Oct 23 20:19:46 2010 +0000 @@ -16,8 +16,8 @@ def fetch_media(request): """ - This view returns the HTML media of an embeddable resource. - This view is the target of an AJAX request. + This view returns the HTML media of an embeddable resource as + JSON. This view is the target of an AJAX request. """ if not request.user.is_authenticated(): return HttpResponseForbidden('Please login or register.') @@ -63,3 +63,25 @@ content_type='application/json') return HttpBadRequest("Sorry, we couldn't find that video.") + + +def fetch_saved_media(request): + """ + This view returns the HTML embed information for previously saved Oembed + objects as JSON. This view is the target of an AJAX request. + """ + if not request.user.is_authenticated(): + return HttpResponseForbidden('Please login or register.') + + embed_ids = request.GET.getlist('embeds') + if not embed_ids: + return HttpResponseBadRequest('Missing embed list.') + + embeds = Oembed.objects.in_bulk(embed_ids) + + # build results in order + results = [] + for pk in embeds: + results.append(dict(id=pk, html=embeds[pk].html)) + + return HttpResponse(json.dumps(results), content_type='application/json')