Exemplo n.º 1
0
 def _commandAppendAndInsert(self, node, target, command, name):
     """
 Processes Append and Insert commands for targets of Column and Table.
 :param NamedTree node:
 :param str target:
 :param str command:
 :param str name: name for new Column
 :return str error:
 """
     versioned = self.getVersionedFile()
     UITable._versionCheckpoint(versioned, target, command)
     error = Column.isPermittedName(name)
     if self._isDuplicateInGlobalScope(name):
         error = "%s conflics with existing names" % proposed_name
     if error is None:
         new_column = Column(name)
         increment = 0
         if command == "Append":
             increment = 1
         parent = node.getParent()
         column_index = node.getPosition()
         new_column_index = column_index + increment
         parent.addChild(new_column, new_column_index)
     return error
Exemplo n.º 2
0
 def _columnCommand(self, cmd_dict):
   # Processes a UI request for a Column
   # Input: cmd_dict - dictionary with the keys
   # Output: response - response to user
   error = None
   target = "Column"
   command = cmd_dict["command"]
   column = self.visibleColumnFromIndex(cmd_dict["column_index"])
   versioned = self.getVersionedFile()
   if (command == "Append") or (command == "Insert"):
     versioned.checkpoint(id="%s/%s" % (target, command))
     name = cmd_dict["args"][0]
     error = Column.isPermittedName(name)
     if error is None:
       new_column = Column(name)
       increment = 0
       if command == "Append":
         increment = 1
       column_index = self.indexFromColumn(column)
       new_column_index = column_index + increment
       self.addColumn(new_column, new_column_index)
   elif command == "Delete":
     versioned.checkpoint(id="%s/%s" % (target, command))
     self.deleteColumn(column)
   elif command == "Formula":
     versioned.checkpoint(id="%s/%s" % (target, command))
     formula = cmd_dict["args"][0]
     if len(formula.strip()) == 0:
       error = column.setFormula(None)
     else:
       error = column.setFormula(formula)
   elif command == "Move":
     versioned.checkpoint(id="%s/%s" % (target, command))
     dest_column_name = cmd_dict["args"][0]
     try:
       if dest_column_name == "LAST":
         new_column_index = self.numColumns() - 1
       else:
         dest_column = self.columnFromName(dest_column_name)
         new_column_index = self.indexFromColumn(dest_column)
       cur_column = self.visibleColumnFromIndex(cmd_dict["column_index"])
       self.moveColumn(cur_column, new_column_index)
     except Exception:
       error = "Column %s does not exists." % dest_column_name
   elif command == "Refactor":
     versioned.checkpoint(id="%s/%s" % (target, command))
     proposed_name = cmd_dict["args"][0]
     try:
       self.refactorColumn(column.getName(), proposed_name)
     except Exception as err:
       error = str(err)
   elif command == "Rename":
     versioned.checkpoint(id="%s/%s" % (target, command))
     proposed_name = cmd_dict["args"][0]
     if not self.renameColumn(column, proposed_name):
       error = "%s is a duplicate column name." % proposed_name
   else:
     msg = "Unimplemented %s command: %s." % (target, command)
     raise NotYetImplemented(msg)
   response = self._createResponse(error)
   return response