Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #40 #42

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/utils_flask_sqla/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,14 @@ def build_query_order(self, query, parameters):
return query.order_by(ordel_col)
return query

def raw_query(self, process_filter=True):
def set_limit(self, q):
return q.limit(self.limit).offset(self.offset * self.limit)

def raw_query(self, process_filter=True, with_limit=True):
"""
Renvoie la requete 'brute' (sans .all)
- process_filter: application des filtres (et du sort)
- with_limit: application de la limite sur la query
"""

q = self.DB.session.query(self.view.tableDef)
Expand All @@ -251,24 +255,24 @@ def raw_query(self, process_filter=True):
unordered_q = self.build_query_filters(q, self.filters)
q = self.build_query_order(unordered_q, self.filters)

if self.limit != -1:
q = q.limit(self.limit).offset(self.offset * self.limit)
if self.limit != -1 and with_limit:
q = self.set_limit(q)

return q

def query(self):
"""
Lance la requete et retourne l'objet sqlalchemy
"""
q = self.raw_query(process_filter=False)
q = self.DB.session.query(self.view.tableDef)
nb_result_without_filter = q.count()

q = self.raw_query()
nb_results = q.count() if self.filters else nb_result_without_filter
q = self.raw_query(process_filter=True, with_limit=False)
total_filtered = q.count() if self.filters else nb_result_without_filter

data = q.all()
data = self.set_limit(q).all()

return data, nb_result_without_filter, nb_results
return data, nb_result_without_filter, total_filtered

def return_query(self):
"""
Expand Down
Loading