def extend(self, records): """ JUST SO WE MODEL A Queue """ records = {v["id"]: v["value"] for v in records} struct.unwrap(self.data).update(records) data_as_json = CNV.object2JSON(self.data, pretty=True) File(self.filename).write(data_as_json) Log.note("{{num}} items added", {"num": len(records)})
def search(self, query): query=wrap(query) f = CNV.esfilter2where(query.query.filtered.filter) filtered=wrap([{"_id": i, "_source": d} for i, d in self.data.items() if f(d)]) if query.fields: return wrap({"hits": {"total":len(filtered), "hits": [{"_id":d._id, "fields":unwrap(Q.select([unwrap(d._source)], query.fields)[0])} for d in filtered]}}) else: return wrap({"hits": {"total":len(filtered), "hits": filtered}})
del bug["everconfirmed"] if bug.id == "692436_1336314345": bug.votes = 3 try: if Math.is_number(bug.cf_last_resolved): bug.cf_last_resolved = long(bug.cf_last_resolved) else: bug.cf_last_resolved = CNV.datetime2milli(CNV.string2datetime(bug.cf_last_resolved, "%Y-%m-%d %H:%M:%S")) except Exception, e: pass bug = transform_bugzilla.rename_attachments(bug) for c in bug.changes: c.field_name = c.field_name.replace("attachments.", "attachments_") if c.attach_id == '': c.attach_id = None else: c.attach_id = CNV.value2int(c.attach_id) bug.attachments = Q.sort(bug.attachments, "attach_id") for a in bug.attachments: a.attach_id = CNV.value2int(a.attach_id) for k, v in list(a.items()): if k.endswith("isobsolete") or k.endswith("ispatch") or k.endswith("isprivate"): struct.unwrap(a)[k] = CNV.value2int(v) # PREVENT dot (.) INTERPRETATION a[k.split(".")[-1].split("_")[-1]] = CNV.value2int(v) bug = transform_bugzilla.normalize(bug) return bug