def parseDocObjectsToStrings(records, obj_type): """ called by parseDocumentsForW2ui and get_table_data to convert some of the objects in the record dictionaries into strings. For example converts the sources into their names instead of returning the entire object """ for doc in records: for key, value in doc.items(): # all dates should look the same if isinstance(value, datetime.datetime): doc[key] = datetime.datetime.strftime(value, "%Y-%m-%d %H:%M:%S") if key == "_id" or key == "id": doc["recid"] = str(value) doc["details"] = "<a href='"+getHREFLink(doc, obj_type)+"'>"\ "<div class='icon-container'>"\ "<span class='ui-icon ui-icon-document'></span>"\ "</div>"\ "</a>" elif key == "password_reset": doc['password_reset'] = None elif key == "exploit": exploits = [] for ex in value: exploits.append(ex['cve']) doc[key] = "|||".join(exploits) elif key == "campaign": camps = [] for campdict in value: camps.append(campdict['name']) doc[key] = "|||".join(camps) elif key == "source": srcs = [] for srcdict in doc[key]: srcs.append(srcdict['name']) doc[key] = "|||".join(srcs) elif key == "tags": tags = [] for tag in doc[key]: tags.append(tag) doc[key] = "|||".join(tags) elif key == "is_active": if value: doc[key] = "True" else: doc[key] = "False" elif key == "tickets": tickets = [] for ticketdict in value: tickets.append(ticketdict['ticket_number']) doc[key] = "|||".join(tickets) elif key == "datatype": doc[key] = value.keys()[0] elif key == "to": doc[key] = len(value) elif key == "thumb": doc['url'] = reverse("crits.screenshots.views.render_screenshot", args=(unicode(doc["_id"]),)) elif key=="results" and obj_type == "AnalysisResult": doc[key] = len(value) elif isinstance(value, list): if value: for item in value: if not isinstance(item, basestring): break else: doc[key] = ",".join(value) else: doc[key] = "" doc[key] = html_escape(doc[key]) value = doc[key].strip() if isinstance(value, unicode) or isinstance(value, str): val = ' '.join(value.split()) val = val.replace('"',"'") doc[key] = val return records
def parseDocObjectsToStrings(records, obj_type): """ called by parseDocumentsForW2ui and get_table_data to convert some of the objects in the record dictionaries into strings. For example converts the sources into their names instead of returning the entire object """ for doc in records: for key, value in doc.items(): # all dates should look the same if isinstance(value, datetime.datetime): doc[key] = datetime.datetime.strftime(value, "%Y-%m-%d %H:%M:%S") if key == "_id" or key == "id": doc["recid"] = str(value) doc["details"] = "<a href='"+getHREFLink(doc, obj_type)+"'>"\ "<div class='icon-container'>"\ "<span class='ui-icon ui-icon-document'></span>"\ "</div>"\ "</a>" elif key == "password_reset": doc['password_reset'] = None elif key == "campaign": camps = [] for campdict in value: camps.append(campdict['name']) doc[key] = "|||".join(camps) elif key == "source": srcs = [] for srcdict in doc[key]: srcs.append(srcdict['name']) doc[key] = "|||".join(srcs) elif key == "tags": tags = [] for tag in doc[key]: tags.append(tag) doc[key] = "|||".join(tags) elif key == "is_active": if value: doc[key] = "True" else: doc[key] = "False" elif key == "tickets": tickets = [] for ticketdict in value: tickets.append(ticketdict['ticket_number']) doc[key] = "|||".join(tickets) elif key == "datatype": doc[key] = value.keys()[0] elif key == "to": doc[key] = len(value) elif key == "thumb": doc['url'] = reverse( "crits.screenshots.views.render_screenshot", args=(unicode(doc["_id"]), )) elif key == "results" and obj_type == "AnalysisResult": doc[key] = len(value) elif isinstance(value, list): if value: for item in value: if not isinstance(item, basestring): break else: doc[key] = ",".join(value) else: doc[key] = "" doc[key] = html_escape(doc[key]) value = doc[key].strip() if isinstance(value, unicode) or isinstance(value, str): val = ' '.join(value.split()) val = val.replace('"', "'") doc[key] = val return records