make youtube videos sort've work
This commit is contained in:
parent
8653073d75
commit
efa48df80b
|
@ -55,7 +55,8 @@ class YoutubeVideo(GalleryItem):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
def thumbnail(self):
|
||||||
|
return "http://i.ytimg.com/vi/%s/default.jpg" % self.youtube_id
|
||||||
|
|
||||||
#class Video(GalleryItem):
|
#class Video(GalleryItem):
|
||||||
# ...
|
# ...
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
from django.shortcuts import render_to_response, get_object_or_404
|
from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from models import GalleryAlbum, GalleryItem, Photo
|
from models import GalleryAlbum, GalleryItem, Photo, YoutubeVideo
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django import forms
|
from django import forms
|
||||||
|
@ -63,19 +63,21 @@ def delete_photo(request, id):
|
||||||
|
|
||||||
def add_youtube(request, id):
|
def add_youtube(request, id):
|
||||||
gallery = get_object_or_404(GalleryAlbum, pk=id)
|
gallery = get_object_or_404(GalleryAlbum, pk=id)
|
||||||
url = request.POST.get("url", None)
|
url = request.GET.get("url", None)
|
||||||
if not url:
|
if not url:
|
||||||
return render_to_json_response({'error': 'No URL supplied'})
|
return render_to_json_response({'error': 'No URL supplied'})
|
||||||
youtube_id = url.replace("http://youtu.be/", "")
|
youtube_id = url.replace("http://youtu.be/", "")
|
||||||
thumbnail = "http://i.ytimg.com/vi/%s/default.jpg" % youtube_id
|
|
||||||
# info = youtube.info(youtube_id)
|
# info = youtube.info(youtube_id)
|
||||||
yt = YoutubeVideo()
|
yt = YoutubeVideo(album=gallery)
|
||||||
yt.youtube_id = youtube_id
|
yt.youtube_id = youtube_id
|
||||||
yt.title = "fixme"
|
yt.title = "fixme"
|
||||||
|
|
||||||
yt.save()
|
yt.save()
|
||||||
return render_to_json_response({
|
return render_to_json_response({
|
||||||
'title': yt.title
|
'id': yt.id,
|
||||||
'thumbnail': thumbnail
|
'title': yt.title,
|
||||||
|
'thumbnail': yt.thumbnail()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,17 @@ $(function() {
|
||||||
$(this).attr("disabled", "disabled");
|
$(this).attr("disabled", "disabled");
|
||||||
$(this).text("Adding...");
|
$(this).text("Adding...");
|
||||||
var url = "/mediagallery/add_youtube/" + GALLERY_ID;
|
var url = "/mediagallery/add_youtube/" + GALLERY_ID;
|
||||||
$.post(url, {'url': yt_url}, function(response) {
|
$.get(url, {'url': yt_url}, function(data) {
|
||||||
console.log(response);
|
var $ul = $('#youtubeVideos');
|
||||||
|
var $li = $('<li />')
|
||||||
|
.attr("data-id", data.id)
|
||||||
|
.appendTo($ul);
|
||||||
|
var $img = $('<img />').attr("src", data.thumbnail).appendTo($li);
|
||||||
|
var $title = $('<div />').addClass("videoTitle").text(data.title).appendTo($li);
|
||||||
|
var $delete = $('<span />')
|
||||||
|
.addClass("deleteVideo")
|
||||||
|
.text("X")
|
||||||
|
.appendTo($li);
|
||||||
}, "json");
|
}, "json");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -111,6 +120,10 @@ $(function() {
|
||||||
<div id="addYoutubeVideos">
|
<div id="addYoutubeVideos">
|
||||||
Youtube Share Link: <input type="text" id="youtubeURL" placeholder="eg. http://youtu.be/Wo_mFYW-jLU" />
|
Youtube Share Link: <input type="text" id="youtubeURL" placeholder="eg. http://youtu.be/Wo_mFYW-jLU" />
|
||||||
<button id="addYoutubeVideo">Add</button>
|
<button id="addYoutubeVideo">Add</button>
|
||||||
|
|
||||||
|
<ul id="youtubeVideos">
|
||||||
|
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user