added video and audio stuff

This commit is contained in:
sanj 2011-01-14 17:44:50 +05:30
parent a9a34564ec
commit 0e6ca63a4a
4 changed files with 95 additions and 42 deletions

14
COPYING Normal file
View File

@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2010 Sanjay Bhangar <sanjay@camputer.org>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

View File

@ -309,18 +309,34 @@ class Page(models.Model):
textBoxes = [] textBoxes = []
for t in TextBox.objects.filter(page = self).exclude(is_displayed = False): for t in TextBox.objects.filter(page = self).exclude(is_displayed = False):
textBoxes.append(t.to_dict()) textBoxes.append(t.to_dict())
'''
videos = [] videos = []
for v in self.videos: for v in self.videos.all():
r = { r = {
'title' = v.fil.title, 'id': v.id,
'description' = v.fil.description 'title': v.fil.title,
'srts' = [] 'description': v.fil.description,
for s in v.srt: 'file': v.fil.file.url,
'mime': 'video'
}
videos.append(r)
audios = []
for a in self.audios.all():
r = {
'id': a.id,
'title': a.fil.title,
'description': a.fil.description,
'file': a.fil.file.url,
'mime': 'audio'
}
audios.append(r)
''' '''
#Resources: #Resources:
'''
resources = [] resources = []
for res in self.resources.all(): for res in self.resources.all():
r = {} r = {}
@ -339,6 +355,8 @@ class Page(models.Model):
'id': self.id, 'id': self.id,
'imageBoxes' : imageBoxes, 'imageBoxes' : imageBoxes,
'textBoxes': textBoxes, 'textBoxes': textBoxes,
'videos': videos,
'audios': audios
# 'resources' : resources # 'resources' : resources
} }

View File

@ -39,6 +39,7 @@ def edit_page(request, id):
""" """
send GET request to to /edit/add_media/ with page_id and resource_id . send GET request to to /edit/add_media/ with page_id and resource_id .
""" """
@login_required
def add_media(request): def add_media(request):
page_id = request.GET['page_id'] page_id = request.GET['page_id']
file_id = request.GET['resource_id'] file_id = request.GET['resource_id']
@ -49,13 +50,15 @@ def add_media(request):
if typ == 'video': if typ == 'video':
try: try:
video = Video.objects.get(fil__id=file_id) video = Video.objects.get(fil__id=file_id)
page.videos.append(video) page.videos.add(video)
page.save()
except: except:
pass pass
elif typ == 'audio': elif typ == 'audio':
try: try:
audio = Audio.objects.get(fil__id=file_id) audio = Audio.objects.get(fil__id=file_id)
page.audios.append(audio) page.audios.add(audio)
page.save()
except: except:
pass pass
page.save() page.save()
@ -64,6 +67,7 @@ def add_media(request):
} }
return HttpResponse(simplejson.dumps(r), mimetype="application/json") return HttpResponse(simplejson.dumps(r), mimetype="application/json")
@login_required
def add_srt(request): def add_srt(request):
file_id = request.POST['id'] file_id = request.POST['id']
mime = request.POST['mime'] mime = request.POST['mime']
@ -95,7 +99,7 @@ def edit_article(request, id):
} }
return render_to_response("editor.html", rDict) return render_to_response("editor.html", rDict)
@login_required
def image_rotate(request, id): def image_rotate(request, id):
image_id = int(id) image_id = int(id)
if request.GET.has_key('degree'): if request.GET.has_key('degree'):
@ -121,6 +125,7 @@ def testCrop(request):
} }
return render_to_response("testCrop.html", d) return render_to_response("testCrop.html", d)
@login_required
def imagebox_crop(request): def imagebox_crop(request):
o = request.GET o = request.GET
# project_path = "/home/sanj/soc/edgware-py/" # project_path = "/home/sanj/soc/edgware-py/"
@ -150,6 +155,7 @@ def test_thumb(request):
r = {'path': 'media/images/original/facade.jpg'} r = {'path': 'media/images/original/facade.jpg'}
return render_to_response("thumbnailTmp.txt", r) return render_to_response("thumbnailTmp.txt", r)
@login_required
def textbox_new(request): def textbox_new(request):
if request.GET['json']: if request.GET['json']:
box = TextBox() box = TextBox()
@ -182,6 +188,7 @@ def textbox_new(request):
else: else:
return False return False
@login_required
def textbox_update_css(request): def textbox_update_css(request):
box_id = request.GET['id'] box_id = request.GET['id']
try: try:
@ -215,6 +222,7 @@ def textbox_update_css(request):
j = json.dumps(r) j = json.dumps(r)
return HttpResponse(j, mimetype="application/json") return HttpResponse(j, mimetype="application/json")
@login_required
def textbox_set_html(request): def textbox_set_html(request):
id = request.GET['id'] id = request.GET['id']
html = request.GET['html'] html = request.GET['html']
@ -238,6 +246,7 @@ def textbox_set_html(request):
} }
return HttpResponse(json.dumps(r), mimetype="application/json") return HttpResponse(json.dumps(r), mimetype="application/json")
@login_required
def textbox_delete(request): def textbox_delete(request):
id = request.GET['id'] id = request.GET['id']
box = TextBox.objects.get(pk=id) box = TextBox.objects.get(pk=id)
@ -256,6 +265,7 @@ def textbox_delete(request):
}) })
return HttpResponse(str(rev_id)) return HttpResponse(str(rev_id))
@login_required
def imagebox_new(request): def imagebox_new(request):
jsonString = request.GET['json'] jsonString = request.GET['json']
d = json.loads(jsonString) d = json.loads(jsonString)
@ -287,6 +297,7 @@ def imagebox_new(request):
j = json.dumps(r) j = json.dumps(r)
return HttpResponse(j, mimetype="application/json") return HttpResponse(j, mimetype="application/json")
@login_required
def imagebox_update_css(request): def imagebox_update_css(request):
box_id = request.GET['id'] box_id = request.GET['id']
box = ImageBox.objects.get(pk = box_id) box = ImageBox.objects.get(pk = box_id)
@ -315,6 +326,7 @@ def imagebox_update_css(request):
j = json.dumps(r) j = json.dumps(r)
return HttpResponse(j, mimetype="application/json") return HttpResponse(j, mimetype="application/json")
@login_required
def imagebox_resize(request): def imagebox_resize(request):
box_id = request.GET['id'] box_id = request.GET['id']
width = request.GET['width'] width = request.GET['width']
@ -352,6 +364,7 @@ def imagebox_resize(request):
j = json.dumps(r) j = json.dumps(r)
return HttpResponse(j, mimetype="application/json") return HttpResponse(j, mimetype="application/json")
@login_required
def imagebox_delete(request): def imagebox_delete(request):
id = request.GET['id'] id = request.GET['id']
box = ImageBox.objects.get(pk=id) box = ImageBox.objects.get(pk=id)

View File

@ -272,30 +272,11 @@ Canvas.prototype.init = function() {
new_index = parseInt(highest_index) + 1; new_index = parseInt(highest_index) + 1;
// console.log('index: ' + new_index); // console.log('index: ' + new_index);
i = new ImageBox(c, r, {css: {'z-index': "" + new_index, 'top':toPx((ev.pageY - top) - height), 'left': toPx((ev.pageX - left) - width)}}); i = new ImageBox(c, r, {css: {'z-index': "" + new_index, 'top':toPx((ev.pageY - top) - height), 'left': toPx((ev.pageX - left) - width)}});
} else if (r.mime == 'audio' || r.mime == 'video') {
that.addMedia(r);
} }
else if (r.mime == 'audio') {
media_box = $(this).children('.audio_video');
$.getJSON('/edit/add_media/', {
resource_id: r.id,
page_id: c.id
}, function(data) {
media_box.append("<img class='media_icon' src='/static/images/icons/Speaker.png'>");
});
} } else {
else if (r.mime == 'video') {
media_box = $(this).children('.audio_video');
$.getJSON('/edit/add_media/', {
resource_id: r.id,
page_id: c.id
}, function(data) {
media_box.append("<img class='media_icon' src='/static/images/icons/video.png'>");
});
}
}
else {
var elem = $(ui.draggable); var elem = $(ui.draggable);
top = $(this).position().top; top = $(this).position().top;
left = $(this).position().left; left = $(this).position().left;
@ -315,13 +296,32 @@ Canvas.prototype.init = function() {
} }
}); });
return this; return this;
} }
Canvas.prototype.addMedia = function(resource) {
var that = this;
$.getJSON("/edit/add_media/", {
resource_id: resource.id,
page_id: that.id
}, function(response) {
that.addMediaIcon(resource);
});
}
Canvas.prototype.addMediaIcon = function(resource) {
var typ = resource.mime;
var media_box = this.jq.find('.audio_video');
$('<img />').addClass('media_icon').addClass(typ + '_icon').attr("src", "/static/images/icons/" + typ + ".png").attr("title", resource.title).data("resource", resource).appendTo(media_box);
}
Canvas.prototype.loadFromJSON = function(json) { Canvas.prototype.loadFromJSON = function(json) {
// alert(JSON.stringify(json));
// GLOBALFOO = json; // GLOBALFOO = json;
var imageBoxes = json.imageBoxes; var imageBoxes = json.imageBoxes;
var textBoxes = json.textBoxes; var textBoxes = json.textBoxes;
var videos = json.videos;
var audios = json.audios;
// alert(audios.length);
var that = this; var that = this;
for (var i=0; i < imageBoxes.length; i++) { for (var i=0; i < imageBoxes.length; i++) {
var resource = imageBoxes[i].resource; var resource = imageBoxes[i].resource;
@ -332,7 +332,15 @@ Canvas.prototype.loadFromJSON = function(json) {
var b = new TextBox(that, textBoxes[t]); var b = new TextBox(that, textBoxes[t]);
// that.textBoxes.append(b); // that.textBoxes.append(b);
} }
for (var v=0; v < videos.length; v++) {
var video = videos[v];
that.addMediaIcon(video);
} }
for (var a=0; a < audios.length; a++) {
var audio = audios[a];
that.addMediaIcon(audio);
}
}
Canvas.prototype.toObj = function() { Canvas.prototype.toObj = function() {
var that = this; var that = this;