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)
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
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
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
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)
def getLink(title): query = {"alias": title} entity = docsCollection.find_one(query) link = Link() link.fromJSON(entity) return link