def log_field_changes(new_dict, old_dict): ignored_fields = ["modified", "creation", "__onload"] for k, v in old_dict.iteritems(): if type(new_dict[k]) != type(old_dict[k]): new_dict[k] = str(new_dict[k]) old_dict[k] = str(old_dict[k]) if new_dict[k] != old_dict[k] and k not in ignored_fields: doc = { "doctype": get_analytics_doctype_name(old_dict['doctype']), "changed_doctype": new_dict['doctype'], "changed_doc_name": new_dict['name'], "fieldname": k, "old_value": old_dict[k], "new_value": new_dict[k], "modified_by_user": new_dict["modified_by"], "date": new_dict["modified"] } # can't save old/new value as list -> means child table. if type(doc['old_value']) is not list: make_doctype_maybe(doc['doctype']) history = Document(doc) history.insert() else: for idx, entry in enumerate(doc['old_value']): log_field_changes(doc['new_value'][idx], entry)
def log_field_changes(new_dict, old_dict): ignored_fields = ["modified", "creation", "__onload"] for k, v in old_dict.iteritems(): # these are commented out b/c they're causing issues with datetimes # string comparison is wrong, says they're changed b/c Y-m-d != m-d-Y # if type(new_dict[k]) != type(old_dict[k]): # new_dict[k] = str(new_dict[k]) # old_dict[k] = str(old_dict[k]) if new_dict[k] != old_dict[k] and k not in ignored_fields: doc = { "doctype": get_analytics_doctype_name(old_dict['doctype']), "changed_doctype": new_dict['doctype'], "changed_doc_name": new_dict['name'], "fieldname": k, "old_value": old_dict[k], "new_value": new_dict[k], "modified_by_user": new_dict["modified_by"], "date": new_dict["modified"] } # can't save old/new value as list -> means child table. if type(doc['old_value']) is not list: make_doctype_maybe(doc['doctype']) history = Document(doc) history.insert() else: for idx, entry in enumerate(doc['old_value']): log_field_changes(doc['new_value'][idx], entry)
def make_doc(new_dict, old_dict, k): doc = prep_doc(new_dict, old_dict, k) if type(doc['new_value']) is not list: make_doctype_maybe(doc['doctype']) history = Document(doc) history.insert() elif doc['old_value'] != None: for idx, entry in enumerate(doc['old_value']): log_field_changes(doc['new_value'][idx], entry)
def insert_new_doc(dictionary): ignored_fields = ["modified", "creation", "__onload"] for k, v in dictionary.iteritems(): if k not in ignored_fields: doc = { "doctype": get_analytics_doctype_name(dictionary['doctype']), "changed_doctype": dictionary['doctype'], "changed_doc_name": dictionary['name'], "fieldname": k, "old_value": None, "new_value": dictionary[k], "modified_by_user": dictionary["modified_by"], "date": dictionary["modified"] } if type(doc['new_value']) is not list: make_doctype_maybe(doc['doctype']) history = Document(doc) history.insert() else: for idx, entry in enumerate(doc['new_value']): insert_new_doc(doc['new_value'][idx])