add videos in gallery, basic

This commit is contained in:
Sanj 2012-12-13 03:45:00 +05:30
parent 9eaace35e8
commit 8653073d75
4 changed files with 51 additions and 2 deletions

View File

@ -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):
# ...

View File

@ -8,5 +8,5 @@ urlpatterns = patterns('mediagallery.views',
(r'^edit_photo/(?P<id>\d+)', 'edit_photo'),
(r'^upload/', 'upload'),
(r'^(?P<id>\d+)/chunk', 'chunk'),
(r'^add_youtube/(?P<id>\d+)', 'add_youtube'),
)

View File

@ -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':

View File

@ -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() {
</ul>
</div>
<div id="addVideos">
<div id="addYoutubeVideos">
Youtube Share Link: <input type="text" id="youtubeURL" placeholder="eg. http://youtu.be/Wo_mFYW-jLU" />
<button id="addYoutubeVideo">Add</button>
</div>
</div>
<a href="Javascript:close()">Done</a>
{% endblock %}