From efa48df80ba60cd2d32e7f06f02b89cbd0b4ecb7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 13 Dec 2012 04:02:53 +0530 Subject: [PATCH] make youtube videos sort've work --- itf/mediagallery/models.py | 3 ++- itf/mediagallery/views.py | 14 ++++++++------ itf/templates/mediagallery/upload.html | 17 +++++++++++++++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/itf/mediagallery/models.py b/itf/mediagallery/models.py index 605b80c..ca971ac 100644 --- a/itf/mediagallery/models.py +++ b/itf/mediagallery/models.py @@ -55,7 +55,8 @@ class YoutubeVideo(GalleryItem): def __unicode__(self): return self.title - + def thumbnail(self): + return "http://i.ytimg.com/vi/%s/default.jpg" % self.youtube_id #class Video(GalleryItem): # ... diff --git a/itf/mediagallery/views.py b/itf/mediagallery/views.py index 20d1fcb..d807109 100644 --- a/itf/mediagallery/views.py +++ b/itf/mediagallery/views.py @@ -2,7 +2,7 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.template import RequestContext 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.views.decorators.csrf import csrf_exempt from django import forms @@ -63,19 +63,21 @@ def delete_photo(request, id): def add_youtube(request, id): gallery = get_object_or_404(GalleryAlbum, pk=id) - url = request.POST.get("url", None) + url = request.GET.get("url", None) if not url: return render_to_json_response({'error': 'No URL supplied'}) youtube_id = url.replace("http://youtu.be/", "") - thumbnail = "http://i.ytimg.com/vi/%s/default.jpg" % youtube_id + # info = youtube.info(youtube_id) - yt = YoutubeVideo() + yt = YoutubeVideo(album=gallery) yt.youtube_id = youtube_id yt.title = "fixme" + yt.save() return render_to_json_response({ - 'title': yt.title - 'thumbnail': thumbnail + 'id': yt.id, + 'title': yt.title, + 'thumbnail': yt.thumbnail() }) diff --git a/itf/templates/mediagallery/upload.html b/itf/templates/mediagallery/upload.html index 5662db9..2f9a727 100644 --- a/itf/templates/mediagallery/upload.html +++ b/itf/templates/mediagallery/upload.html @@ -55,8 +55,17 @@ $(function() { $(this).attr("disabled", "disabled"); $(this).text("Adding..."); var url = "/mediagallery/add_youtube/" + GALLERY_ID; - $.post(url, {'url': yt_url}, function(response) { - console.log(response); + $.get(url, {'url': yt_url}, function(data) { + var $ul = $('#youtubeVideos'); + var $li = $('
  • ') + .attr("data-id", data.id) + .appendTo($ul); + var $img = $('').attr("src", data.thumbnail).appendTo($li); + var $title = $('
    ').addClass("videoTitle").text(data.title).appendTo($li); + var $delete = $('') + .addClass("deleteVideo") + .text("X") + .appendTo($li); }, "json"); }); @@ -111,6 +120,10 @@ $(function() {
    Youtube Share Link: + +
      + +