Mercurial > public > sg101
view oembed/views.py @ 693:ad69236e8501
For issue #52, update many 3rd party Javascript libraries.
Updated to jquery 1.10.2, jquery ui 1.10.3.
This broke a lot of stuff.
- Found a newer version of the jquery cycle all plugin (3.0.3).
- Updated JPlayer to 2.4.0.
- Updated to MarkItUp 1.1.14. This also required me to add multiline attributes
set to true on various buttons in the markdown set.
- As per a stackoverflow post, added some code to get multiline titles in
a jQuery UI dialog. They removed that functionality but allow you to put it
back.
Tweaked the MarkItUp preview CSS to show blockquotes in italic.
Did not update TinyMCE at this time. I'm not using the JQuery version and this
version appears to work ok for now.
What I should do is make a repo for MarkItUp and do a vendor branch thing so
I don't have to futz around diffing directories to figure out if I'll lose
changes when I update.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 04 Sep 2013 19:55:20 -0500 |
parents | 89b240fe9297 |
children | 344f7914d421 |
line wrap: on
line source
""" Views for the oembed application. """ import json import re from django.http import HttpResponse from django.http import HttpResponseBadRequest from django.http import HttpResponseForbidden from django.conf import settings from oembed.models import Provider from oembed.models import Oembed from oembed.core import get_oembed def fetch_media(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.') url = request.POST.get('q') if not url: return HttpResponseBadRequest('Please provide a valid URL.') # Is this already in our database? try: oembed = Oembed.objects.get(url=url) except Oembed.DoesNotExist: pass else: data = dict(id=oembed.id, embed=oembed.html) return HttpResponse(json.dumps(data), content_type='application/json') # It isn't in the database, try to find it from our providers providers = Provider.objects.all() for provider in providers: if re.match(provider.url_regex, url): try: data = get_oembed(provider.api_endpoint, url, maxwidth=settings.OEMBED_MAXWIDTH, maxheight=settings.OEMBED_MAXHEIGHT) except IOError, e: return HttpResponseBadRequest( "Sorry, we could not retrieve your video (%s)" % e) if 'type' not in data or data['type'] != 'video': return HttpResponseBadRequest( "Hey, this doesn't look like a video..??") oembed = Oembed(url=url, type=Oembed.VIDEO, title=data.get('title', ''), width=int(data.get('width', 0)), height=int(data.get('height', 0)), html=data.get('html', '')) oembed.save() data = dict(id=oembed.id, embed=oembed.html) return HttpResponse(json.dumps(data), content_type='application/json') return HttpResponseBadRequest("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')