notifyFrontend

This commit is contained in:
j 2007-07-10 16:37:59 +00:00
parent 7c1c01a756
commit 5a9fd08511
3 changed files with 20 additions and 4 deletions

View File

@ -23,9 +23,13 @@ def httpExpires(sec):
class Root(controllers.RootController):
@expose()
def default(self, md5Hash, action, position = None):
f = ArchiveFile.byMd5sum(md5Hash)
try:
f = ArchiveFile.byMd5sum(md5Hash)
except:
return dict()
if action == 'metadata':
return dict(meta = f)
return dict(metadata = f)
elif action in ('timeline', 'timeline.png'):
cherrypy.response.headerMap['Content-Type'] = "image/jpeg"
cherrypy.response.headerMap["Expires"] = httpExpires(60*60*24*15)
@ -39,4 +43,4 @@ class Root(controllers.RootController):
return f.clip(position)
elif action == 'frame':
return f.frame(position)
redirect('http://0xdb.oil21.org/')
return dict()

View File

@ -7,6 +7,7 @@
#
# @jsonify can convert your objects to following types:
# lists, dicts, numbers and strings
import time
from turbojson.jsonify import jsonify, jsonify_sqlobject
@ -17,7 +18,9 @@ def jsonify_ArchiveFile(obj):
result = jsonify_sqlobject( obj )
#FIXME, possibly do something with the date values
# date, date_added, modDate, pubDate
for key in ('date_added', 'modDate', 'pubDate', 'date'):
result[key] = time.mktime(getattr(obj, key).timetuple())
for key in ('id', 'archiveID', 'subtitle_meta_id'):
result.pop(key)
print "after, json", result
return result

View File

@ -29,6 +29,7 @@ __connection__ = hub
class Archive(SQLObject):
name = UnicodeCol(length=255, alternateID=True)
basePath = UnicodeCol()
baseUrlFrontend = UnicodeCol(default = '')
def _get_basePath(self):
basePath = self._SO_get_basePath()
@ -37,6 +38,12 @@ class Archive(SQLObject):
self.basePath = basePath
return basePath
def notifyFrontend(self, action, md5sum):
if self.baseUrlFrontend:
url = "%s/%s?md5sum=%s" % (self.baseUrlFrontend, action, md5sum)
result = read_url(url)
print "Frontend:", result
def _get_files(self):
q = ArchiveFile.select(ArchiveFile.q.archiveID == self.id)
return [f for f in q]
@ -110,6 +117,7 @@ class Archive(SQLObject):
)
ret = "added entry"
f.updateMeta()
self.notifyFrontend('add', f.md5sum)
return ret
def removeFile(self, md5sum):
@ -123,6 +131,7 @@ class Archive(SQLObject):
if q.count() == 1:
for i in q:
ArchiveFile.delete(i.id)
self.notifyFrontend('remove', f.md5sum)
return dict(result="file removed")
return dict(result="not in archive")