diff --git a/malojatime.py b/malojatime.py index 6511a6b..f84e1cd 100644 --- a/malojatime.py +++ b/malojatime.py @@ -78,6 +78,15 @@ class MRangeDescriptor: "description":self.desc() } + def __json__(self): + return { + "fromstring":self.fromstr(), + "tostr":self.tostr(), + "fromstamp":self.first_stamp(), + "tostamp":self.last_stamp(), + "description":self.desc() + } + def uri(self): return "&".join(k + "=" + self.urikeys[k] for k in self.urikeys) diff --git a/monkey.py b/monkey.py new file mode 100644 index 0000000..aa29456 --- /dev/null +++ b/monkey.py @@ -0,0 +1,7 @@ +from simplejson import JSONEncoder + +def newdefault(self,object): + return getattr(object.__class__,"__json__", olddefault)(object) + +olddefault = JSONEncoder.default +JSONEncoder.default = newdefault diff --git a/server.py b/server.py index 3a60d90..92f9eed 100755 --- a/server.py +++ b/server.py @@ -3,6 +3,8 @@ # server stuff from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict, redirect, template import waitress +# monkey patching +import monkey # rest of the project import database from utilities import *