Skip to content

Commit

Permalink
refactor media and attribut filter
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Aug 1, 2023
1 parent 6d1cde5 commit 2417942
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions apptax/admin/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ def get_dynamic_options(self, view):
yield from [(list.id_liste, list.nom_liste) for list in BibListes.query.all()]


from flask_admin.model.filters import BaseBooleanFilter


class FilterIsValidName(BaseFilter):
def apply(self, query, value, alias=None):
if int(value) == 1:
Expand All @@ -80,23 +77,23 @@ def operation(self):

class FilterMedia(BaseFilter):
def apply(self, query, value, alias=None):
medias_filter = Taxref.medias.any()
if int(value) == 1:
return query.join(TMedias, TMedias.cd_ref == Taxref.cd_ref)
return query.filter(medias_filter)
else:
# TODO
return query
return query.filter(~medias_filter)

def operation(self):
return lazy_gettext("equal")


class FilterAttributes(BaseFilter):
def apply(self, query, value, alias=None):
attr_filter = Taxref.attributs.any()
if int(value) == 1:
return query.join(CorTaxonAttribut, CorTaxonAttribut.cd_ref == Taxref.cd_ref)
return query.filter(attr_filter)
else:
# TODO
return query
return query.filter(~attr_filter)

def operation(self):
return lazy_gettext("equal")
2 changes: 1 addition & 1 deletion apptax/taxonomie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class CorNomListe(db.Model):
primary_key=True,
)

taxref = db.relationship("Taxref")
# backref : Medias et Attributs

bib_liste = db.relationship("BibListes")

Expand Down

0 comments on commit 2417942

Please sign in to comment.