コード例 #1
0
    def getFamily(self, id):
        # Find the parents
        # Make a list to put all the family taxa inside of
        familyList = []
        # Get the base taxon object
        base = Taxon.findTaxonById(id)
        # Add the base to the list
        familyList.append(base.json())
        taxon = base
        # While there is a taxon with a parent id
        while taxon and taxon.parent_id:
            # The parent taxon becomes the taxon, so the while loop keeps looking
            taxon = taxon.findTaxonById(taxon.parent_id)
            # Add the parent taxon to the list
            familyList.append(taxon.json())

        #Find the children of the base ID
        lookForChildren = []
        lookForChildren.append(id)

        while len(lookForChildren) > 0:
            children = Taxon.findChildrenById(lookForChildren)
            lookForChildren.clear()
            for child in children:
                lookForChildren.append(child.id)
                familyList.append(child.json())
            lookForChildren.clear()

        return familyList
コード例 #2
0
 def findOrCreate(self):
     json = request.json
     taxonList = []
     for soort in json:
         taxon = Taxon.findTaxonByName(soort)
         if taxon is None:
             taxon = Taxon(name=soort)
         taxonList.append(taxon.json())
     return jsonify(taxonList)
コード例 #3
0
 def removeTaxon(self, id):
     taxon = Taxon.findTaxonById(id)
     if taxon:
         taxon.delete()
         return {"message": "The taxon with id '{}' is deleted!".format(id)}
     else:
         return "The taxon does not exist!"
コード例 #4
0
 def getTaxonByIds(self):
     data = request.get_json(force=True)
     print(data)
     taxons = []
     for x in data:
         taxon = Taxon.findTaxonById(x)
         taxons.append(taxon)
     return list(map(lambda x: x.json(), taxons))
コード例 #5
0
    def addTaxon(self, id):
        try:
            data = TaxonService.parser.parse_args()
            taxon = Taxon.findTaxonById(id)

            if taxon:
                return "The Taxon already exists!"
            else:
                taxon = Taxon(data["id"], data["name"], data["group_id"],
                              data["level_id"], data["parent_id"],
                              data["refer_id"])
                taxon.save()
                return taxon.json()
        except exc.IntegrityError:
            return "The name already exists!"
コード例 #6
0
 def getAllTaxons(self):
     return list(map(lambda x: x.json(), Taxon.findAllTaxons()))
コード例 #7
0
 def getTaxon(self, id):
     taxon = Taxon.findTaxonById(id)
     if taxon:
         return taxon.json(), 201
     return {"message": "The taxon is not found!"}, 404