From 49bccbc5e6fa9b04196ce7d274702d0f889ba324 Mon Sep 17 00:00:00 2001 From: sanj Date: Wed, 28 Jul 2010 02:34:24 +0530 Subject: [PATCH] tested basics, updating server --- edgware/editor/models.py | 14 +- edgware/editor/views.py | 21 +- edgware/files/convert.py | 14 +- edgware/files/models.py | 23 +- edgware/static/css/editor.css | 4 +- edgware/static/js/editor.js | 24 +- edgware/templates/article_frontend.html | 307 ++++++++++++------------ edgware/templates/editor.html | 8 +- 8 files changed, 218 insertions(+), 197 deletions(-) diff --git a/edgware/editor/models.py b/edgware/editor/models.py index 49afe20..41e07a4 100644 --- a/edgware/editor/models.py +++ b/edgware/editor/models.py @@ -160,7 +160,12 @@ class Revision(models.Model): def saveRevision(r): page = Page.objects.get(pk=r['page_id']) article = page.article - rev = Revision(article=article, page=page, user=r.user, box_type=r['box_type'], box_id=r['box_id'], prop=r['prop'], old_val=r['old_val'], new_val=r['new_val'], uuid=r['uuid']) + #FIXME: all calls to saveRevision should always send user, so this should not be required. + if r.has_key('user'): + user = r['user'] + else: + user = User.objects.get(pk=1) + rev = Revision(article=article, page=page, user=user, box_type=r['box_type'], box_id=r['box_id'], prop=r['prop'], old_val=r['old_val'], new_val=r['new_val'], uuid=r['uuid']) rev.save() return rev.id @@ -576,8 +581,11 @@ class ImageBox(models.Model): self.height = height self.save() tpl = (self.crop_x1, self.crop_y1, self.crop_x2, self.crop_y2,) - original_cropped = Image.open(MEDIA_ROOT + "/" + self.original_print()).crop(tpl) - original_cropped.save(self.cropped_path()) + image_full_path = join(MEDIA_ROOT, self.original_print()) + print + original_cropped = Image.open(image_full_path).crop(tpl) + save_path = join(MEDIA_ROOT, self.cropped_path(), self.cropped_fname()) + original_cropped.save(save_path) return self def cropped_fname(self): diff --git a/edgware/editor/views.py b/edgware/editor/views.py index 0b73d23..296acb0 100644 --- a/edgware/editor/views.py +++ b/edgware/editor/views.py @@ -44,14 +44,15 @@ def add_media(request): file_id = request.GET['resource_id'] page = Page.objects.get(pk=page_id) fil = File.objects.get(pk=file_id) - typ = Type.objects.get(pk=fil.type_id) - if typ.mime == 'ogv': + typ = fil.type +# typ = Type.objects.get(pk=fil.type_id) + if typ == 'video': try: video = Video.objects.get(fil__id=file_id) page.videos.append(video) except: pass - elif typ.mime == 'mp3': + elif typ == 'audio': try: audio = Audio.objects.get(fil__id=file_id) page.audios.append(audio) @@ -68,9 +69,9 @@ def add_srt(request): mime = request.POST['mime'] srt_file = request.FILES['srt'] ## REMEMBER TO SAVE SRT FILE!!!## - if mime == 'ogv': + if mime == 'video': media = Video.objects.get(fil_id=file_id) - elif mime == 'mp3': + elif mime == 'audio': media = Audio.objects.get(fil_id=file_id) media.srt.append(srt) media.save() @@ -378,7 +379,7 @@ def category_json(request): # these should not be here width = 0 height = 0 - if r.type.mime == 'jpg': + if r.type == 'image': filePath = r.original_print() try: fil = Image.open(join(MEDIA_ROOT, filePath)) @@ -399,13 +400,13 @@ def category_json(request): filePath = r.file.url iconPath = "/static/images/binimages/%s.jpg" % (r.type.mime) resizedPath = filePath - if r.type.mime == 'ogv': + if r.type == 'video': try: v = Video.objects.filter(fil=r)[0] media_id = v.id except: media_id = 0 - elif r.type.mime == 'mp3': + elif r.type == 'audio': try: a = Audio.objects.filter(fil=r)[0] media_id = a.id @@ -417,7 +418,7 @@ def category_json(request): d = { 'id': r.id, - 'type': r.type.name, + 'type': r.type, 'title': r.title, 'file': filePath, 'description': r.description, @@ -427,7 +428,7 @@ def category_json(request): 'height': int(height), 'resized': resizedPath, 'added': str(r.added), - 'mime': r.type.mime, + 'mime': r.type, 'media_id': media_id } rList.append(d) diff --git a/edgware/files/convert.py b/edgware/files/convert.py index f447f8b..50b5652 100644 --- a/edgware/files/convert.py +++ b/edgware/files/convert.py @@ -48,15 +48,15 @@ def ignoreFile(f): #This function is called from the post_save signal, receives kwargs['instance'] as a File instance def convertFile(**kwargs): fn = { - 'jpg': ignoreFile, - 'mp3': toOgg, - 'txt': ignoreFile, - 'ogv': toOgv, - 'oth': ignoreFile, - 'hid': ignoreFile + 'image': ignoreFile, + 'audio': toOgg, + 'text': ignoreFile, + 'video': toOgv, + 'other': ignoreFile, +# 'other': ignoreFile } f = kwargs['instance'] - fn[f.type.mime](f) + fn[f.type](f) return diff --git a/edgware/files/models.py b/edgware/files/models.py index 48e4dd5..30b50a2 100755 --- a/edgware/files/models.py +++ b/edgware/files/models.py @@ -8,7 +8,7 @@ from os.path import join from convert import convertFile from django.db.models.signals import post_save from settings import UPLOAD_ROOT, MEDIA_ROOT -from utils.add_file import hashFile, fileInfo +from utils.add_file import hashFile, fileInfo, getFileType #FIXME: The following two functions are ridiculous. please remove and clean up all references to them. def baseFileName(filename): @@ -30,6 +30,13 @@ MIME_TYPES = ( ('hid', 'Hidden'), ) +TYPE_CHOICES = ( + ('image', 'Image'), + ('audio', 'Audio'), + ('text', 'Text'), + ('video', 'Video'), +) + class Folder(models.Model): name = models.CharField(max_length=1024) relative_path = models.CharField(max_length=2048) @@ -71,7 +78,8 @@ class File(models.Model): file_date = models.DateField("Date", blank=True, null=True) added = models.DateField("Date Added", auto_now_add=True) categories = models.ManyToManyField('Category', verbose_name='Studies') - type = models.ForeignKey('Type', verbose_name='File Type') +# type = models.ForeignKey('Type', verbose_name='File Type') + type = models.CharField(max_length=255, choices=TYPE_CHOICES) ext = models.CharField(max_length=100, blank=True) oshash = models.CharField(max_length=128, blank=True, db_index=True) # folder = models.ForeignKey("Folder") @@ -88,13 +96,14 @@ class File(models.Model): filename = os.path.basename(path) title = kwargs.get("title", filename) description = kwargs.get("description", "") - ext = os.path.splitext(filename)[1][1:] - django_file_path = UPLOAD_ROOT.replace(MEDIA_ROOT, "")[1:] - f = cls(file=django_file_path, full_path=path, title=title, description=description, ext=ext, oshash=oshash, info=info) + ext = os.path.splitext(filename)[1][1:].lower() + typ = getFileType(path, ext) + django_file_path = join(path.replace(MEDIA_ROOT, "")[1:]) + f = cls(file=django_file_path, full_path=path, title=title, description=description, ext=ext, type=typ, oshash=oshash, info=info) f.userID = user f.save() - f.categories.append(category) - f.save_m2m() + f.categories.add(category) + f.save() return f @classmethod diff --git a/edgware/static/css/editor.css b/edgware/static/css/editor.css index 75c84ae..b6ca40c 100644 --- a/edgware/static/css/editor.css +++ b/edgware/static/css/editor.css @@ -232,9 +232,9 @@ p { } .binSelect { - width: 208px; + width: 45%; font-size: 12px; - margin-left: 7px; + margin-left: 2px; } #addElements { diff --git a/edgware/static/js/editor.js b/edgware/static/js/editor.js index 9e9b73e..004b297 100644 --- a/edgware/static/js/editor.js +++ b/edgware/static/js/editor.js @@ -262,7 +262,7 @@ Canvas.prototype.init = function() { c = edgeArticle[$(this).attr('data-index')]; if ($(ui.draggable).attr('class') == 'resource ui-draggable') { r = edgeBin.allResources[$(ui.draggable).attr("data-index")]; - if (r.mime == 'jpg') { + if (r.mime == 'image') { top = $(this).position().top; left = $(this).position().left; height = parseInt(r.height) / 2; @@ -273,7 +273,7 @@ Canvas.prototype.init = function() { // 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)}}); } - else if (r.mime == 'mp3') { + else if (r.mime == 'audio') { media_box = $(this).children('.audio_video'); $.getJSON('/edit/add_media/', { resource_id: r.id, @@ -283,7 +283,7 @@ Canvas.prototype.init = function() { }); } - else if (r.mime == 'ogv') { + else if (r.mime == 'video') { media_box = $(this).children('.audio_video'); $.getJSON('/edit/add_media/', { @@ -798,7 +798,7 @@ var Bin = function() { this.allResources = []; }; -Bin.prototype.loadCategory = function(catid) { +Bin.prototype.loadCategory = function(catid, type) { var that = this; this.jq.find('.resource').remove(); this.resources = []; @@ -815,13 +815,15 @@ Bin.prototype.loadCategory = function(catid) { }); }; +/* +This function is a very good idea. You would send a json object with parameters to the back-end to filter results by, allowing search to get a lot better. Bin.prototype.loadResources = function(url, params) { var that = this; this.jq.find('.resource').remove(); this.resources = []; } - +*/ Bin.prototype.searchString = function(str) { var that = this; @@ -948,7 +950,7 @@ var MyResource = function(json, index) { this.file = json.file; this.description = json.description; this.tags = json.tags; - this.mime = json.mime; + this.mime = json.mime; //inaccurately called 'mime' - this is either image, text, audio or video, as a string. this.icon = json.icon; this.added = json.added; this.addToBin(); @@ -1016,10 +1018,10 @@ Resource.prototype.addEventHandlers = function() { var that = this; this.jq.tooltip(); var mim2tmpl = { - 'jpg': "tmpl_resource_image", - 'ogv': "tmpl_resource_av", - 'mp3': "tmpl_resource_av", - 'txt': "tmpl_resource_doc" + 'image': "tmpl_resource_image", + 'video': "tmpl_resource_av", + 'audio': "tmpl_resource_av", + 'text': "tmpl_resource_doc" } this.jq.hover(function() { var tmpl_id = mim2tmpl[that.mime]; @@ -1615,7 +1617,7 @@ $(function() { $('.upload_srts').live("click", function(e) { var r = $(this).getResource(); var media_id = r.media_id; - var type = r.mime == 'ogv' ? 'video' : 'audio'; + var type = r.mime == 'video' ? 'video' : 'audio'; if (media_id == 0) { alert("sorry, there was some problem with converting this audio / video, ID: " + r.id); } else { diff --git a/edgware/templates/article_frontend.html b/edgware/templates/article_frontend.html index 3895bbc..e3d5d30 100644 --- a/edgware/templates/article_frontend.html +++ b/edgware/templates/article_frontend.html @@ -1,26 +1,27 @@ {% load alter_size %} - - - - -Edgwareroad.org {{article.title}} - - - - - - - - - - - - - - - -
-
- -
-
-
Transcript:
-
- -
-
->
-
- -
-
-
- -
-
- -
-
-
Transcript:
-
- -
- -
- -
-
-
- - -
- -
-
- - - - - - - - -
Edgware Road, Vol 1, January 2010
-
ادجوار رود ، المجلد 1 يناير 2010
-
االقائمة العربية English Menu
-
- + + + + + + + + + + + +
+
+ +
+
+
Transcript:
+
+ +
+
->
+
+ +
+
+
+ +
+
+ +
+
+
Transcript:
+
+ +
+ +
+ +
+
+
+ + +
+ +
+
+ + + + + + + + +
Edgware Road, Vol 1, January 2010
+
ادجوار رود ، المجلد 1 يناير 2010
+
االقائمة العربية English Menu
+
+ {% autoescape off %} -{% for p in pages %} -
+{% for p in pages %} +
{% for t in p.textBoxes %}
{{t.html|parse_html:m}} @@ -182,41 +183,41 @@ p {
- {% endfor %} -
-{% endfor %} -{% endautoescape %} - -

 

-
-
+ {% endfor %} +
+{% endfor %} +{% endautoescape %} + +

 

+
+

Contents:
- {% for a_b in articles_before %} + {% for a_b in articles_before %} {{a_b.order}}. {{a_b.title}}
{% endfor %} - {{article.order}}. {{article.title}} -

-
-

متلامس:
-
-

- -
- -
-
-

- {% for a_a in articles_after %} + {{article.order}}. {{article.title}} +

+
+

متلامس:
+
+

+ +
+ +
+
+

+ {% for a_a in articles_after %} {{a_a.order}}. {{a_a.title}}
- {% endfor %} -

-
- -
-
- -

-
- - - + {% endfor %} +

+
+ +
+
+ +

+
+ + + diff --git a/edgware/templates/editor.html b/edgware/templates/editor.html index 8043fad..8c0cfd3 100644 --- a/edgware/templates/editor.html +++ b/edgware/templates/editor.html @@ -59,7 +59,7 @@ }); - Edgware Editor - {{ user.username }} + Edgware Editor - Hi {{ user.username }} @@ -206,13 +206,13 @@

+