示例#1
0
def delRelationship(fro, to):
    """Helper function to remove relationships from class."""
    rel_to_del = Relationship.query.get({"from_name":fro, "to_name":to})
    if not rel_to_del is None:
        delRelCmd = del_rel(fro, to, rel_to_del.rel_type)
        cmd_stack.execute(delRelCmd)
    else:
        flash("ERROR: Unable to delete relationship from " + fro + " to " + to, 'error')
示例#2
0
def delAttribute(name, attr):
    """Helper to remove attributes from class."""
    attr_to_del = Attribute.query.get({"class_name":name, "attribute":attr})
    if not attr_to_del is None:
        delAttrCmd = del_attr(name, attr, attr_to_del.attr_type)
        cmd_stack.execute(delAttrCmd)
    else:
        flash("ERROR: Unable to remove attribute " + attr + " from " + name, 'error')
    def execute(self):
        parsedType = parseType(self.attrName)
        if parsedType is not None:
            # link it to the related class if applicable
            ClassList = Class.query.all()
            for CurrentClass in ClassList:
                if CurrentClass.name == parsedType:
                    cmd_stack.execute(
                        add_rel(self.className, CurrentClass.name, "agg"))
                    break

        return core_add_attr(self.className, self.attrName, self.attrType)
示例#4
0
def updateCoords():
    """Deals with requests from GUI to save dragged coordinates."""

    name = request.form['name']
    x = request.form['left']
    y = request.form['top']

    updatee = Class.query.get_or_404(name)
    moveCmd = move(name,  x, y)
    cmd_stack.execute(moveCmd)

    db.session.commit()
    return "Name: " + updatee.name + "\nX: " + str(updatee.x) + "\nY: " + str(updatee.y)
示例#5
0
def index():
    """Deals with requests to the base index.

    On POST request, adds requested class and redirects
      to itself to re-render with updated data
    On GET request, renders the base index with current data
    """

    if request.method == 'POST':
        # form tag 'content'
        class_name = request.form['class_name']

        if class_name == '':
            return redirect('/')

        classList = core_parse(class_name)
        for class_ in classList:
            addCmd = add_class(class_)
            if cmd_stack.execute(addCmd):
                flash('ERROR: Unable to add class ' + class_, 'error')
        return redirect('/')

    else:
        # grab all entries in order
        classes = Class.query.order_by(Class.date_created).all()
        attributes = Attribute.query.order_by(Attribute.date_created).all()
        theme = Settings.query.get({"name":"theme"})
        if theme is None:
            theme = "Dark-Green"
        else:
            theme = theme.value

        athemes = populateThemes();
        return render_template('index.html', classes=classes, attributes=attributes, cmd_stack=cmd_stack, theme=theme, availThemes=athemes)
示例#6
0
def addAttributes(name, attrString, attrType):
    """Helper to add attributes to class."""
    attrList = core_parse(attrString)
    for attr in attrList:
        addAttrCmd = add_attr(name, attr, attrType)
        if cmd_stack.execute(addAttrCmd):
            flash('ERROR: Unable to add attribute ' + attr + " to " + name, 'error')
示例#7
0
def addRelationship():
    """Helper function to add relationships to class."""
    try:
        fro = request.form['class_name']
        to = request.form['to']
        rel_type = request.form['rel_type']
        addRelCmd = add_rel(fro, to, rel_type)
        if cmd_stack.execute(addRelCmd):
            flash("ERROR: Unable to add relationship from " + fro + " to " + to, 'error')
    except:
        flash("Invalid arguments, try again.", 'error')

    return redirect('/')
示例#8
0
 def do_delete(self, args):
     """Accepts a single class name OR a list separated by commas and removes them from the database.
 Usage: delete <class_name1>, <class_name2>, ... , <class_nameN>
 """
     argList = core_parse(args)
     if argList:
         for name in argList:
             deleteCmd = delete_class(name)
             if cmd_stack.execute(deleteCmd):
                 print('ERROR: Unable to delete class \'' + name + '\'')
             else:
                 print('Successfully deleted class \'' + name + '\'')
     else:
         print("Usage: delete <class_name1>, <class_name2>, ... , <class_nameN>")
示例#9
0
 def do_add(self, args):
     """Accepts a single class name OR a list separated by commas and adds them to the database.
 Usage: add <class_name1>, <class_name2>, ... , <class_nameN>
 """
     argList = core_parse(args)
     if argList:
         for name in argList:
             addCmd = add_class(name)
             if cmd_stack.execute(addCmd):
                 print('ERROR: Unable to add class \'' + name + '\'')
             else:
                 print('Successfully added class \'' + name + '\'')
     else:
         print("Usage: add <class_name1>, <class_name2>, ... , <class_nameN>")
示例#10
0
def delete():
    """Deals with requests to remove a class.

    Removes the requested class from database, if successful
    """
    try:
        name = request.form['delete']
        deleteCmd = delete_class(name)
        if cmd_stack.execute(deleteCmd):
            flash('ERROR: Unable to delete class ' + name, 'error')
    except:
        flash("Invalid name", 'error')

    return redirect('/')
示例#11
0
 def do_edit(self, args):
     """Accepts a single class name followed by a replacement name, separated by commas, and changes instances of old name in database with new name.
 Usage: edit <old_name>, <new_name>
 """
     argList = core_parse(args)
     if len(argList) == 2:
         old_name = argList.pop(0)
         new_name = argList.pop(0)
         editCmd = edit_class(old_name, new_name)
         if cmd_stack.execute(editCmd):
             print('ERROR: Unable to update class \'' + old_name + '\' to \'' + new_name + '\'')
         else:
             print('Successfully updated class \'' + old_name + '\' to \'' + new_name + '\'')
     else:
         print("Usage: edit <old_name>, <new_name>")
示例#12
0
 def do_delRel(self, args):
     """Accepts a single 'from' class name followed by a list of 'to' class names separated by commas and removes these relationships from the database.
 Usage: delRel <class_name>, <relationship1>, <relationship2>, ... , <relationshipN>
 """
     argList = core_parse(args)
     if len(argList) > 1:
         class_name = argList.pop(0)
         for rel in argList:
             rel_to_del = Relationship.query.get({"from_name":class_name, "to_name":rel})
             if rel_to_del is None or cmd_stack.execute(del_rel(class_name, rel, rel_to_del.rel_type)):
                 print('ERROR: Unable to delete relationship from \'' + class_name + '\' to \'' + rel + '\'')
             else:
                 print('Successfully deleted relationship from \'' + class_name + '\' to \'' + rel + '\'')
     else:
         print("Usage: delRel <class_name>, <relationship1>, <relationship2>, ... , <relationshipN>")
示例#13
0
 def do_delAttr(self, args):
     """Accepts a single class name followed by a list of attribute names separated by commas and removes them from the class.
 Usage: delAttr <class_name>, <attribute1>, <attribute2>, ... , <attributeN>
 """
     argList = core_parse(args)
     if len(argList) > 1:
         class_name = argList.pop(0)
         for attr in argList:
             attr_to_del = Attribute.query.get({"class_name":class_name, "attribute":attr})
             if attr_to_del is None or cmd_stack.execute(del_attr(class_name, attr, attr_to_del.attr_type)):
                 print('ERROR: Unable to delete attribute \'' + attr + '\'')
             else:
                 print('Successfully deleted attribute \'' + attr + '\'')
     else:
         print("Usage: delAttr <class_name>, <attribute1>, <attribute2>, ... , <attributeN>")
示例#14
0
 def do_editAttr(self, args):
     """Accepts a single class name followed by an existing attribute within and a new name which will replace said attribute in the class, all separated by commas.
 Usage: editAttr <class_name>, <old_attribute>, <new_attribute>
 """
     argList = core_parse(args)
     if len(argList) == 3:
         class_name = argList.pop(0)
         old_name = argList.pop(0)
         new_name = argList.pop(0)
         editAttrCmd = edit_attr(class_name, old_name, new_name)
         if cmd_stack.execute(editAttrCmd):
             print('ERROR: Unable to update attribute \'' + old_name + '\' to \'' + new_name + '\'')
         else:
             print('Successfully updated attribute \'' + old_name + '\' to \'' + new_name + '\'')
     else:
         print("Usage: editAttr <class_name>, <old_attribute>, <new_attribute>")
示例#15
0
 def do_addAttr(self, args):
     """Accepts a single class name and attribute type followed by a list of attribute names separated by commas and adds them to the class.
 Usage: addAttr <class_name>, <field/method>, <attribute1>, <attribute2>, ... , <attributeN>
 """
     argList = core_parse(args)
     if len(argList) > 2:
         class_name = argList.pop(0)
         attr_type = argList.pop(0).lower()
         if not attr_type in ["field", "method"]:
             print('ERROR: Invalid attribute type: ' + attr_type + "\n\tValid attribute types: field, method")
             return
         for attr in argList:
             addAttrCmd = add_attr(class_name, attr, attr_type)
             if cmd_stack.execute(addAttrCmd):
                 print('ERROR: Unable to add ' + attr_type + ' \'' + attr + '\'')
             else:
                 print('Successfully added ' + attr_type + ' \'' + attr + '\'')
     else:
         print("Usage: addAttr <class_name>, <field/method>, <attribute1>, <attribute2>, ... , <attributeN>")
示例#16
0
 def do_addRel(self, args):
     """Accepts a single 'from' class name and relationship type followed by a list of 'to' class names separated by commas and adds these relationships to the database.
 Usage: addRel <class_name>, <relationship type>, <relationship1>, <relationship2>, ... , <relationshipN>
     Valid relationship types: agg, comp, gen, none
 """
     argList = core_parse(args)
     if len(argList) > 2:
         class_name = argList.pop(0)
         rel_type = argList.pop(0).lower()
         if not rel_type in ["agg", "comp", "gen", "none"]:
             print('ERROR: Invalid relationship type: ' + rel_type + "\n  Valid relationship types: agg, comp, gen, none")
             return
         for rel in argList:
             addRelCmd = add_rel(class_name, rel, rel_type)
             if cmd_stack.execute(addRelCmd):
                 print('ERROR: Unable to add relationship from \'' + class_name + '\' to \'' + rel + '\' of type \'' + rel_type + '\'')
             else:
                 print('Successfully added relationship from \'' + class_name + '\' to \'' + rel + '\' of type \'' + rel_type + '\'')
     else:
         print("Usage: addRel <class_name>, <relationship type>, <relationship1>, <relationship2>, ... , <relationshipN>\n  Valid relationship types: agg, comp, gen, none")
示例#17
0
def update(oldName, newName):
    """Helper to update a class's name."""
    updateCmd = edit_class(oldName, newName)
    if cmd_stack.execute(updateCmd):
        flash("ERROR: Unable to update class " + oldName + " to " + newName, 'error')
示例#18
0
def updateAttribute(name, oldAttr, newAttr):
    """Helper to update attributes in class."""

    editAttrCmd = edit_attr(name, oldAttr, newAttr)
    if cmd_stack.execute(editAttrCmd):
        flash("ERROR: Unable to update attribute " + oldAttr + " in " + name + " to " + newAttr, 'error')