def default(self, obj): if isinstance(obj, Crash): crash = obj serializable = href('view_report', project=crash.project, report_id=crash.id_without_project) serializable.update(crash) fix_buckets(serializable) elif isinstance(obj, Bucket): bucket = obj if bucket.project: resource_info = href('view_bucket', project=bucket.project, threshold=bucket.threshold, bucket_id=bucket.id) else: resource_info = href('view_bucket_no_project', threshold=bucket.threshold, bucket_id=bucket.id) serializable = bucket.to_dict(resource_info) elif isinstance(obj, Project): project = obj # TODO: Point to the (currently non-existent) project page. # gh-issue #33 serializable = href( 'query_buckets', # TODO: unhardcode this number! threshold='4.0', project=project.name) serializable.update(name=project.name) elif isinstance(obj, Threshold): # The str output is the JSON output. return str(obj) elif isinstance(obj, datetime): return obj.isoformat() else: raise TypeError('No idea how to encode {!r} object: ' '{!r}'.format(type(obj), obj)) return serializable
def default(self, obj): if isinstance(obj, Crash): crash = obj serializable = href('view_report', project=crash.project, report_id=crash.id_without_project) serializable.update(crash) fix_buckets(serializable) elif isinstance(obj, Bucket): bucket = obj if bucket.project: resource_info = href('view_bucket', project=bucket.project, threshold=bucket.threshold, bucket_id=bucket.id) else: resource_info = href('view_bucket_no_project', threshold=bucket.threshold, bucket_id=bucket.id) serializable = bucket.to_dict(resource_info) elif isinstance(obj, Project): project = obj # TODO: Point to the (currently non-existent) project page. # gh-issue #33 serializable = href('query_buckets', # TODO: unhardcode this number! threshold='4.0', project=project.name) serializable.update(name=project.name) elif isinstance(obj, Threshold): # The str output is the JSON output. return str(obj) elif isinstance(obj, datetime): return obj.isoformat() else: raise TypeError('No idea how to encode {!r} object: ' '{!r}'.format(type(obj), obj)) return serializable
def serialize_top_match(info): # See: bucketer.MLT.make_matching_buckets() if info is not None: match_url = href('view_report', project=info['project'], report_id=info['report_id']) return OrderedDict([ ('report_id', info['report_id']), ('href', match_url['href']), ('project', info['project']), ('score', info['score']), ]) else: return None