diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-23 01:11:34 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-24 10:39:35 +0100 |
commit | b4e0ba0b0aa84550d0b06338b59557c3050798c9 (patch) | |
tree | ec3f6c1d6166e6d3598ecd630aa64853f8842828 /store.py | |
parent | 07fa7a4bf8f7a6f799120fb9a5965a09bea6c38e (diff) | |
download | Trader-b4e0ba0b0aa84550d0b06338b59557c3050798c9.tar.gz Trader-b4e0ba0b0aa84550d0b06338b59557c3050798c9.tar.zst Trader-b4e0ba0b0aa84550d0b06338b59557c3050798c9.zip |
Store reports to database
Fixes https://git.immae.eu/mantisbt/view.php?id=57
Diffstat (limited to 'store.py')
-rw-r--r-- | store.py | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -36,12 +36,22 @@ class ReportStore: | |||
36 | hash_["date"] = datetime.now() | 36 | hash_["date"] = datetime.now() |
37 | self.logs.append(hash_) | 37 | self.logs.append(hash_) |
38 | 38 | ||
39 | @staticmethod | ||
40 | def default_json_serial(obj): | ||
41 | if isinstance(obj, (datetime, date)): | ||
42 | return obj.isoformat() | ||
43 | return str(obj) | ||
44 | |||
39 | def to_json(self): | 45 | def to_json(self): |
40 | def default_json_serial(obj): | 46 | return json.dumps(self.logs, default=self.default_json_serial, indent=" ") |
41 | if isinstance(obj, (datetime, date)): | 47 | |
42 | return obj.isoformat() | 48 | def to_json_array(self): |
43 | return str(obj) | 49 | for log in (x.copy() for x in self.logs): |
44 | return json.dumps(self.logs, default=default_json_serial, indent=" ") | 50 | yield ( |
51 | log.pop("date"), | ||
52 | log.pop("type"), | ||
53 | json.dumps(log, default=self.default_json_serial, indent=" ") | ||
54 | ) | ||
45 | 55 | ||
46 | def set_verbose(self, verbose_print): | 56 | def set_verbose(self, verbose_print): |
47 | self.verbose_print = verbose_print | 57 | self.verbose_print = verbose_print |