Skip to content

Commit

Permalink
feat(taxref): taxons comparison through path
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Oct 8, 2024
1 parent ba350c6 commit e84cb84
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions apptax/taxonomie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ def where_params(cls, filters=None, *, query):
query = query.filter(col.ilike(value + "%"))
return query

def __le__(self, other):
return self.tree <= other.tree

Check warning on line 234 in apptax/taxonomie/models.py

View check run for this annotation

Codecov / codecov/patch

apptax/taxonomie/models.py#L234

Added line #L234 was not covered by tests


@serializable
class BibListes(db.Model):
Expand Down Expand Up @@ -546,6 +549,11 @@ class TaxrefTree(db.Model):
taxref = db.relationship(Taxref, backref=backref("tree", uselist=False))
path = db.Column(db.String, nullable=False)

def __le__(self, other):
# self <= other means taxon other is the same or a parent of self
p1, p2 = self.path.split("."), other.path.split(".")
return len(p1) >= len(p2) and p1[: len(p2)] == p2

Check warning on line 555 in apptax/taxonomie/models.py

View check run for this annotation

Codecov / codecov/patch

apptax/taxonomie/models.py#L554-L555

Added lines #L554 - L555 were not covered by tests


# Taxref deffered properties

Expand Down

0 comments on commit e84cb84

Please sign in to comment.