Ejemplo n.º 1
0
def registerSimpleLink(jsonInput: object) -> list:
    """
    Creates and saves a new link to the database, using a json as input. Validates that the json has the required format. The created link will either have just an alias (an empty link), or be complete (alias, plus operation and links). The function returns the created link.

    Parameters
    ----------
    name : jsonInput
        A json provided as input, which will be validated against the TextOperations.validateJSON function (an "alias" property is the only requirement).

    Raises
    ------
    TypeError
        If jsonInput parameter doesn't pass the validation, an error is raised.
    """    
    if (TextOperations.validateJSON(jsonInput)):
        linkAlias = jsonInput["alias"]
        link = Link(linkAlias)
        if propertyExists(jsonInput, "text"):
            link.fromUnformattedText(jsonInput["text"])
        createdLinks = saveLink(link)
        return createdLinks
    else:
        raise TypeError("Inadequate json input format. JSON input must have a name attribute, at least.")
Ejemplo n.º 2
0
def registerLinkFromUnformattedText(title: str, text: str):
    #TODO normalize and check if needed
    newEntry = Link(title, text, [], "")
    newEntry.fromUnformattedText(text)
    saveLink(newEntry)