From 8653073d7523a5bc2ce2547d796a1ff6f33f7ad4 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 13 Dec 2012 03:45:00 +0530 Subject: [PATCH] add videos in gallery, basic --- itf/mediagallery/models.py | 9 ++++++++- itf/mediagallery/urls.py | 2 +- itf/mediagallery/views.py | 18 ++++++++++++++++++ itf/templates/mediagallery/upload.html | 24 ++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/itf/mediagallery/models.py b/itf/mediagallery/models.py index 736d656..605b80c 100644 --- a/itf/mediagallery/models.py +++ b/itf/mediagallery/models.py @@ -32,7 +32,6 @@ class GalleryItem(models.Model): return self.title - class Photo(GalleryItem): image = models.ImageField(upload_to="upload/mediagallery/images", blank=True, null=True) #FIXME: upload to better place, with galleries having folders @@ -50,6 +49,14 @@ class Photo(GalleryItem): return False +class YoutubeVideo(GalleryItem): + youtube_id = models.CharField(max_length=64) + + def __unicode__(self): + return self.title + + + #class Video(GalleryItem): # ... diff --git a/itf/mediagallery/urls.py b/itf/mediagallery/urls.py index e0744fe..8a3b7a6 100644 --- a/itf/mediagallery/urls.py +++ b/itf/mediagallery/urls.py @@ -8,5 +8,5 @@ urlpatterns = patterns('mediagallery.views', (r'^edit_photo/(?P\d+)', 'edit_photo'), (r'^upload/', 'upload'), (r'^(?P\d+)/chunk', 'chunk'), - + (r'^add_youtube/(?P\d+)', 'add_youtube'), ) diff --git a/itf/mediagallery/views.py b/itf/mediagallery/views.py index 7872bde..20d1fcb 100644 --- a/itf/mediagallery/views.py +++ b/itf/mediagallery/views.py @@ -61,6 +61,24 @@ def delete_photo(request, id): return render_to_json_response({'success': 'true'}) +def add_youtube(request, id): + gallery = get_object_or_404(GalleryAlbum, pk=id) + url = request.POST.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.youtube_id = youtube_id + yt.title = "fixme" + yt.save() + return render_to_json_response({ + 'title': yt.title + 'thumbnail': thumbnail + }) + + @csrf_exempt def upload(request): if request.method == 'POST': diff --git a/itf/templates/mediagallery/upload.html b/itf/templates/mediagallery/upload.html index 93c6ac8..5662db9 100644 --- a/itf/templates/mediagallery/upload.html +++ b/itf/templates/mediagallery/upload.html @@ -45,6 +45,21 @@ $(function() { }); }); + $('#addYoutubeVideo').click(function(e) { + e.preventDefault(); + var yt_url = $.trim($('#youtubeURL').val()); + if (yt_url.indexOf("http://youtu.be") == -1) { + alert("please enter a valid youtube share link"); + return; + } + $(this).attr("disabled", "disabled"); + $(this).text("Adding..."); + var url = "/mediagallery/add_youtube/" + GALLERY_ID; + $.post(url, {'url': yt_url}, function(response) { + console.log(response); + }, "json"); + + }); }); @@ -92,4 +107,13 @@ $(function() { +
+
+ Youtube Share Link: + +
+ +
+ + Done {% endblock %}