Example #1
0
def editLinkByID (id: str, newLink):
    #TODO normalize
    if (isinstance(newLink, Link)):
        dbconnection.updateLinkById(id, newLink)
    else:
        link = Link()
        link.fromJSON(newLink)
        dbconnection.updateLinkById(id, link)
Example #2
0
def getLinkByField(field, value):
    if field == "_id":
        query = {field: ObjectId(value)}
    else:
        query = {field: value}
    entity = docsCollection.find_one(query)
    if entity:
        link = Link()
        link.fromJSON(entity)
        return link
    else:
        return False
Example #3
0
def getLinksContainingWord(field, word):
    current_app.logger.info("call to getLinksContainingWord")
    regularExpression = "^.*" + word + ".*$"
    regularExpression = re.compile(regularExpression, re.IGNORECASE)
    query = {field: {"$regex": regularExpression}}
    entities = docsCollection.find(query)
    entitiesFormatted = []
    for entity in entities:
        link = Link()
        link.fromJSON(entity)
        entitiesFormatted.append(link)
    return entitiesFormatted
Example #4
0
def getLinksByField(field, value):
    if field == "_id":
        query = {field: ObjectId(value)}
    else:
        query = {field: value}
    entities = docsCollection.find(query)
    entitiesFormatted = []
    for entity in entities:
        #current_app.logger.info("prueba")
        link = Link()
        link.fromJSON(entity)
        entitiesFormatted.append(link)
    return entitiesFormatted
Example #5
0
def editLinkPartially (title, newLink):
    #TODO rewrite for query by id, check if needed
    editionLink = getLink(title)
    formattedNewLink = Link()
    formattedNewLink.fromJSON(newLink)

    if formattedNewLink.alias:
        editionLink.alias = formattedNewLink.alias
    
    if formattedNewLink.operation:
        editionLink.operation = formattedNewLink.operation
    
    if formattedNewLink.links:
        editionLink.links = formattedNewLink.links

    editLinkByID(editionLink.id, editionLink)
Example #6
0
def getLink(title):
    query = {"alias": title}
    entity = docsCollection.find_one(query)
    link = Link()
    link.fromJSON(entity)
    return link