From 7c1c01a756a0a4534a9cfcc478875ecc5f6a50bf Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 10 Jul 2007 14:14:50 +0000 Subject: [PATCH] jsonify --- oxdbarchive/cache.py | 15 +-------------- oxdbarchive/config/app.cfg | 2 ++ oxdbarchive/controllers.py | 2 +- oxdbarchive/json.py | 23 ++++++++++------------- oxdbarchive/midentify.py | 1 + oxdbarchive/model.py | 2 -- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/oxdbarchive/cache.py b/oxdbarchive/cache.py index 9105040..93ee6ee 100644 --- a/oxdbarchive/cache.py +++ b/oxdbarchive/cache.py @@ -32,19 +32,6 @@ def loadStaticFile(fname): return loadFile(join(dirname(abspath(__file__)), "static", fname)) -def loadDefaultFrame(afile): - frame = join(afile.frameFolder, 'default.png') - if not exists(frame): - data = loadStaticFile('images/stillDark.png') - imageIO = StringIO(data) - sourceImage = Image.open(imageIO) - sourceWidth = sourceImage.size[0] - sourceHeight = sourceImage.size[1] - top = (sourceHeight - afile.sceneHeight) / 2 - targetImage = sourceImage.crop((0, top, sourceWidth, top + afile.sceneHeight)) - targetImage.save(frame, 'PNG') - return loadFile(frame) - def loadFrame(afile, position): position = basename(position) frame = join(afile.frameFolder, '%s.%s' % (position, img_extension)) @@ -52,7 +39,7 @@ def loadFrame(afile, position): afile.extractFrame(position) if exists(frame): return loadFile(frame) - return loadDefaultFrame(afile) + return '' def loadClip(afile, position): position = basename(position) diff --git a/oxdbarchive/config/app.cfg b/oxdbarchive/config/app.cfg index f42a1e0..b9d0948 100644 --- a/oxdbarchive/config/app.cfg +++ b/oxdbarchive/config/app.cfg @@ -25,7 +25,9 @@ # Allow every exposed function to be called as json, # tg.allow_json = False + tg.no_empty_flash = True +tg.empty_flash = False # List of Widgets to include on every page. # for exemple ['turbogears.mochikit'] diff --git a/oxdbarchive/controllers.py b/oxdbarchive/controllers.py index 56cff71..223e933 100644 --- a/oxdbarchive/controllers.py +++ b/oxdbarchive/controllers.py @@ -4,6 +4,7 @@ from turbogears import controllers, expose, flash, redirect from model import * +from json import * import cherrypy # import logging @@ -24,7 +25,6 @@ class Root(controllers.RootController): def default(self, md5Hash, action, position = None): f = ArchiveFile.byMd5sum(md5Hash) if action == 'metadata': - print f return dict(meta = f) elif action in ('timeline', 'timeline.png'): cherrypy.response.headerMap['Content-Type'] = "image/jpeg" diff --git a/oxdbarchive/json.py b/oxdbarchive/json.py index 73aa352..44e6353 100644 --- a/oxdbarchive/json.py +++ b/oxdbarchive/json.py @@ -8,19 +8,16 @@ # @jsonify can convert your objects to following types: # lists, dicts, numbers and strings -from turbojson.jsonify import jsonify +from turbojson.jsonify import jsonify, jsonify_sqlobject + +from model import ArchiveFile @jsonify.when('isinstance(obj, ArchiveFile)') def jsonify_ArchiveFile(obj): - result = jsonify_sqlobject( obj ) - #FIXME, possibly do something with the date values - # date, date_added, modDate, pubDate - for key in ('id', 'archiveID', 'subtitle_meta_id'): - result.pop(key) - - return result - -@jsonify.when('isinstance(obj, datetime.datetime)') -def jsonify_datetime(obj): - return str(obj) - + result = jsonify_sqlobject( obj ) + #FIXME, possibly do something with the date values + # date, date_added, modDate, pubDate + for key in ('id', 'archiveID', 'subtitle_meta_id'): + result.pop(key) + print "after, json", result + return result diff --git a/oxdbarchive/midentify.py b/oxdbarchive/midentify.py index 6336c62..8ce150c 100644 --- a/oxdbarchive/midentify.py +++ b/oxdbarchive/midentify.py @@ -7,6 +7,7 @@ import sys _audio_codec_map = { 'ffmp3': 'mp3', + 'mad': 'mp3', } _video_codec_map = { diff --git a/oxdbarchive/model.py b/oxdbarchive/model.py index b62840b..9286936 100644 --- a/oxdbarchive/model.py +++ b/oxdbarchive/model.py @@ -196,8 +196,6 @@ class ArchiveFile(SQLObject): extracted = BoolCol(default = False) - filename = UnicodeCol(default = '') - def _get_part(self): part = 1 parts = re.compile('Part (\d)').findall(self.path)