comparison 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
comparison
equal deleted inserted replaced
285:8fd4984d5c3b 286:72fd300685d5
14 from oembed.core import get_oembed 14 from oembed.core import get_oembed
15 15
16 16
17 def fetch_media(request): 17 def fetch_media(request):
18 """ 18 """
19 This view returns the HTML media of an embeddable resource. 19 This view returns the HTML media of an embeddable resource as
20 This view is the target of an AJAX request. 20 JSON. This view is the target of an AJAX request.
21 """ 21 """
22 if not request.user.is_authenticated(): 22 if not request.user.is_authenticated():
23 return HttpResponseForbidden('Please login or register.') 23 return HttpResponseForbidden('Please login or register.')
24 24
25 url = request.POST.get('q') 25 url = request.POST.get('q')
61 data = dict(id=oembed.id, embed=oembed.html) 61 data = dict(id=oembed.id, embed=oembed.html)
62 return HttpResponse(json.dumps(data), 62 return HttpResponse(json.dumps(data),
63 content_type='application/json') 63 content_type='application/json')
64 64
65 return HttpBadRequest("Sorry, we couldn't find that video.") 65 return HttpBadRequest("Sorry, we couldn't find that video.")
66
67
68 def fetch_saved_media(request):
69 """
70 This view returns the HTML embed information for previously saved Oembed
71 objects as JSON. This view is the target of an AJAX request.
72 """
73 if not request.user.is_authenticated():
74 return HttpResponseForbidden('Please login or register.')
75
76 embed_ids = request.GET.getlist('embeds')
77 if not embed_ids:
78 return HttpResponseBadRequest('Missing embed list.')
79
80 embeds = Oembed.objects.in_bulk(embed_ids)
81
82 # build results in order
83 results = []
84 for pk in embeds:
85 results.append(dict(id=pk, html=embeds[pk].html))
86
87 return HttpResponse(json.dumps(results), content_type='application/json')