parameters: (self, username, type_, new_doc=False)
docstring: Generate an audit entry.
  
      :param self: The object.
      :type self: class which inherits from
                  :class:`crits.core.crits_mongoengine.CritsBaseAttributes`
      :param username: The user performing the action.
      :type username: str
      :param type_: The type of action being performed ("save", "delete").
      :type type_: str
      :param new_doc: If this is a new document being added to the database.
      :type new_doc: boolean
docstring_summary: Generate an audit entry.
docstring_tokens: Generate an audit entry .
function: def audit_entry(self, username, type_, new_doc=False):
      """
      Generate an audit entry.
  
      :param self: The object.
      :type self: class which inherits from
                  :class:`crits.core.crits_mongoengine.CritsBaseAttributes`
      :param username: The user performing the action.
      :type username: str
      :param type_: The type of action being performed ("save", "delete").
      :type type_: str
      :param new_doc: If this is a new document being added to the database.
      :type new_doc: boolean
      """
  
      if username is None:
          # If no username, skip the audit log
          return
  
      my_type = self._meta['crits_type']
      # don't audit audits
      if my_type in ("AuditLog", "Service"):
          return
      changed_fields = [f.split('.')[0] for f in self._get_changed_fields() if f not in ("modified",
                                                                    "save",
                                                                    "delete")]
  
      # Remove any duplicate fields
      changed_fields = list(set(changed_fields))
  
      if new_doc and not changed_fields:
          what_changed = "new document"
      else:
          what_changed = ', '.join(changed_fields)
  
      key_descriptor = key_descriptor_from_obj_type(my_type)
  
      if key_descriptor is not None:
          value = getattr(self, key_descriptor, '')
      else:
          value = ""
  
      if type_ == "save":
          a = AuditLog()
          a.user = username
          a.target_type = my_type
          a.target_id = self.id
          a.value = what_changed
          a.method = "save()"
          try:
              a.save()
          except ValidationError:
              pass
      elif type_ == "delete":
          a = AuditLog()
          a.user = username
          a.target_type = my_type
          a.target_id = self.id
          a.value = value
          a.method = "delete()"
          try:
              a.save()
          except ValidationError:
              pass
  
      # Generate audit notification
      generate_audit_notification(username, type_, self, changed_fields, what_changed, new_doc)
function_tokens: def audit_entry ( self , username , type_ , new_doc = False ) : if username is None : # If no username, skip the audit log return my_type = self . _meta [ 'crits_type' ] # don't audit audits if my_type in ( "AuditLog" , "Service" ) : return changed_fields = [ f . split ( '.' ) [ 0 ] for f in self . _get_changed_fields ( ) if f not in ( "modified" , "save" , "delete" ) ] # Remove any duplicate fields changed_fields = list ( set ( changed_fields ) ) if new_doc and not changed_fields : what_changed = "new document" else : what_changed = ', ' . join ( changed_fields ) key_descriptor = key_descriptor_from_obj_type ( my_type ) if key_descriptor is not None : value = getattr ( self , key_descriptor , '' ) else : value = "" if type_ == "save" : a = AuditLog ( ) a . user = username a . target_type = my_type a . target_id = self . id a . value = what_changed a . method = "save()" try : a . save ( ) except ValidationError : pass elif type_ == "delete" : a = AuditLog ( ) a . user = username a . target_type = my_type a . target_id = self . id a . value = value a . method = "delete()" try : a . save ( ) except ValidationError : pass # Generate audit notification generate_audit_notification ( username , type_ , self , changed_fields , what_changed , new_doc )