parameters: (sobject, snapshot_type, context, column="snapshot",
              description="No description",
              snapshot_data=None, is_current=None, is_revision=False,
              level_type=None, level_id=None, commit=True, is_latest=True,
              is_synced=True, process=None, version=None, triggers=True,
              set_booleans=True)
return_statement: return snapshot
docstring: rev = None
          if is_revision:
              rev = -1
docstring_summary: rev = None
          if is_revision:
              rev = -1
docstring_tokens: rev = None if is_revision : rev = - 1
function: def create(sobject, snapshot_type, context, column="snapshot",
              description="No description",
              snapshot_data=None, is_current=None, is_revision=False,
              level_type=None, level_id=None, commit=True, is_latest=True,
              is_synced=True, process=None, version=None, triggers=True,
              set_booleans=True):
  
          # Provide a default empty snapshot definition
          if snapshot_data == None:
              if sobject.has_value(column):
                  snapshot_data = sobject.get_value(column)
              if not snapshot_data:
                  snapshot_data = "<snapshot/>"
  
  
          if not process:
              # if not specified ...
              # by default process is the first element of the context
              context_parts = context.split("/")
              process = context_parts[0]
  
          search_type = sobject.get_search_type()
          search_id = sobject.get_id()
          search_code = sobject.get_value("code", no_exception=True)
          # temp var
          search_combo = search_code
          if not search_code:
              search_combo = search_id
          """
          rev = None
          if is_revision:
              rev = -1
          """
          # we are always interested in revision = -1 when finding the last one
          rev = -1
          # to find the version number, we have to find the highest number
          # of a particular snapshot
          if version is None:
              old_snapshot = Snapshot._get_by_version(search_type, search_combo, context, version="max", revision=rev, use_cache=False, level_type=level_type, level_id=level_id, show_retired=True)
              # have to clear the cache here, because after it is created
              # it shouldn't be None anymore
              if not old_snapshot:
                  Snapshot.clear_cache()
  
              # handle revisions, with no previous version, revision starts at 1
              revision = 1
              if old_snapshot and is_revision:
                  revision = old_snapshot.get_value("revision", no_exception=True)
                  if revision:
                      revision = int(revision) + 1
                  else:
                      revision = 1
  
                  # keep the same version
                  version = old_snapshot.get_value("version")
                  if version:
                      version = int(version)
                  else:
                      version = 1
              else:
                  if version != None:
                      # force the version
                      pass
                  elif old_snapshot:
                      old_version = old_snapshot.get_value("version")
                      # in case only the versionless snapshot is left behind
                      if old_version == -1:
                          old_version = 0
                      version = int(old_version) + 1
                  else:
                      version = 1
  
          snapshot = Snapshot(Snapshot.SEARCH_TYPE)
          snapshot.set_value("search_type", search_type )
          if SearchType.column_exists("sthpw/snapshot", "search_id"):
              if isinstance(search_id, int):
                  snapshot.set_value("search_id", search_id )
  
          snapshot.set_value("search_code", search_code )
          snapshot.set_value("column_name", column )
          snapshot.set_value("snapshot", snapshot_data )
          snapshot.set_value("snapshot_type", snapshot_type )
  
          snapshot.set_value("version", version)
  
          
          if is_revision:
              snapshot.set_value("revision", revision)
  
          # add level type and level_id
          if level_type:
              assert level_id
              snapshot.set_value("level_type", level_type)
              snapshot.set_value("level_id", level_id)
  
  
          # add the description
          if description == None or description == "":
              if version == 1:
                  description = "Initial insert"
              else:
                  description = "No comment"
          snapshot.set_value("description", description )
  
          # get the login
          security = Environment.get_security()
          login_name = security.get_login().get_login()
          snapshot.set_value("login", login_name)
  
          # extract the timestamp from the snapshot
          snapshot_xml = Xml()
          snapshot_xml.read_string(snapshot_data)
          #snapshot.set_value("timestamp", timestamp )
  
          snapshot.set_value("context", context )
          snapshot.set_value("process", process )
          snapshot.set_value("project_code", sobject.get_project_code())
  
          snapshot.set_value("is_synced", is_synced)
  
          server = Config.get_value("install", "server")
          if server:
              snapshot.set_value("server", server)
  
  
  
          # if commit is false, then just return the snapshot.  Do not run
          # any of the latest or current code.
          if not commit:
              return snapshot
         
          # if this is a simple snapshot create like API method create_snapshot(),
          # it defaults to running set_boolean
          if set_booleans:
              Snapshot.set_booleans(sobject, snapshot, is_latest=is_latest, is_current=is_current)
  
          snapshot.commit(triggers=triggers)
  
          return snapshot
function_tokens: def create ( sobject , snapshot_type , context , column = "snapshot" , description = "No description" , snapshot_data = None , is_current = None , is_revision = False , level_type = None , level_id = None , commit = True , is_latest = True , is_synced = True , process = None , version = None , triggers = True , set_booleans = True ) : # Provide a default empty snapshot definition if snapshot_data == None : if sobject . has_value ( column ) : snapshot_data = sobject . get_value ( column ) if not snapshot_data : snapshot_data = "<snapshot/>" if not process : # if not specified ... # by default process is the first element of the context context_parts = context . split ( "/" ) process = context_parts [ 0 ] search_type = sobject . get_search_type ( ) search_id = sobject . get_id ( ) search_code = sobject . get_value ( "code" , no_exception = True ) # temp var search_combo = search_code if not search_code : search_combo = search_id # we are always interested in revision = -1 when finding the last one rev = - 1 # to find the version number, we have to find the highest number # of a particular snapshot if version is None : old_snapshot = Snapshot . _get_by_version ( search_type , search_combo , context , version = "max" , revision = rev , use_cache = False , level_type = level_type , level_id = level_id , show_retired = True ) # have to clear the cache here, because after it is created # it shouldn't be None anymore if not old_snapshot : Snapshot . clear_cache ( ) # handle revisions, with no previous version, revision starts at 1 revision = 1 if old_snapshot and is_revision : revision = old_snapshot . get_value ( "revision" , no_exception = True ) if revision : revision = int ( revision ) + 1 else : revision = 1 # keep the same version version = old_snapshot . get_value ( "version" ) if version : version = int ( version ) else : version = 1 else : if version != None : # force the version pass elif old_snapshot : old_version = old_snapshot . get_value ( "version" ) # in case only the versionless snapshot is left behind if old_version == - 1 : old_version = 0 version = int ( old_version ) + 1 else : version = 1 snapshot = Snapshot ( Snapshot . SEARCH_TYPE ) snapshot . set_value ( "search_type" , search_type ) if SearchType . column_exists ( "sthpw/snapshot" , "search_id" ) : if isinstance ( search_id , int ) : snapshot . set_value ( "search_id" , search_id ) snapshot . set_value ( "search_code" , search_code ) snapshot . set_value ( "column_name" , column ) snapshot . set_value ( "snapshot" , snapshot_data ) snapshot . set_value ( "snapshot_type" , snapshot_type ) snapshot . set_value ( "version" , version ) if is_revision : snapshot . set_value ( "revision" , revision ) # add level type and level_id if level_type : assert level_id snapshot . set_value ( "level_type" , level_type ) snapshot . set_value ( "level_id" , level_id ) # add the description if description == None or description == "" : if version == 1 : description = "Initial insert" else : description = "No comment" snapshot . set_value ( "description" , description ) # get the login security = Environment . get_security ( ) login_name = security . get_login ( ) . get_login ( ) snapshot . set_value ( "login" , login_name ) # extract the timestamp from the snapshot snapshot_xml = Xml ( ) snapshot_xml . read_string ( snapshot_data ) #snapshot.set_value("timestamp", timestamp ) snapshot . set_value ( "context" , context ) snapshot . set_value ( "process" , process ) snapshot . set_value ( "project_code" , sobject . get_project_code ( ) ) snapshot . set_value ( "is_synced" , is_synced ) server = Config . get_value ( "install" , "server" ) if server : snapshot . set_value ( "server" , server ) # if commit is false, then just return the snapshot.  Do not run # any of the latest or current code. if not commit : return snapshot # if this is a simple snapshot create like API method create_snapshot(), # it defaults to running set_boolean if set_booleans : Snapshot . set_booleans ( sobject , snapshot , is_latest = is_latest , is_current = is_current ) snapshot . commit ( triggers = triggers ) return snapshot