parameters: (self, commands)
return_statement: return True
docstring: 批量保存命令到数据库, command的顺序和save中一致
docstring_summary: 批量保存命令到数据库, command的顺序和save中一致
docstring_tokens: 批量保存命令到数据库 command的顺序和save中一致
function: def bulk_save(self, commands):
          """
          批量保存命令到数据库, command的顺序和save中一致
          """
          _commands = []
          for c in commands:
              _commands.append(self.model(
                  user=c["user"], asset=c["asset"], system_user=c["system_user"],
                  input=c["input"], output=c["output"], session=c["session"],
                  risk_level=c.get("risk_level", 0), org_id=c["org_id"],
                  timestamp=c["timestamp"]
              ))
          error = False
          try:
              with transaction.atomic():
                  self.model.objects.bulk_create(_commands)
          except OperationalError:
              error = True
          except:
              return False
  
          if not error:
              return True
          for command in _commands:
              try:
                  with transaction.atomic():
                      command.save()
              except OperationalError:
                  command.output = str(command.output.encode())
                  command.save()
          return True
function_tokens: def bulk_save ( self , commands ) : _commands = [ ] for c in commands : _commands . append ( self . model ( user = c [ "user" ] , asset = c [ "asset" ] , system_user = c [ "system_user" ] , input = c [ "input" ] , output = c [ "output" ] , session = c [ "session" ] , risk_level = c . get ( "risk_level" , 0 ) , org_id = c [ "org_id" ] , timestamp = c [ "timestamp" ] ) ) error = False try : with transaction . atomic ( ) : self . model . objects . bulk_create ( _commands ) except OperationalError : error = True except : return False if not error : return True for command in _commands : try : with transaction . atomic ( ) : command . save ( ) except OperationalError : command . output = str ( command . output . encode ( ) ) command . save ( ) return True