Commit 0f47c510 authored by CeReynAud's avatar CeReynAud

Merge branch 'master' of https://github.com/mrjoes/flask-admin

parents ec7e7554 eac4fef3
...@@ -3,7 +3,7 @@ import logging ...@@ -3,7 +3,7 @@ import logging
from sqlalchemy.orm.attributes import InstrumentedAttribute from sqlalchemy.orm.attributes import InstrumentedAttribute
from sqlalchemy.orm import subqueryload from sqlalchemy.orm import subqueryload
from sqlalchemy.sql.expression import desc from sqlalchemy.sql.expression import desc
from sqlalchemy import or_, Column from sqlalchemy import or_, Column, func
from flask import flash from flask import flash
...@@ -569,10 +569,18 @@ class ModelView(BaseModelView): ...@@ -569,10 +569,18 @@ class ModelView(BaseModelView):
# Database-related API # Database-related API
def get_query(self): def get_query(self):
""" """
Return a query for the model type Return a query for the model type.
If you override this method, don't forget to override `get_count_query` as well.
""" """
return self.session.query(self.model) return self.session.query(self.model)
def get_count_query(self):
"""
Return a the count query for the model type
"""
return self.session.query( func.count('*') ).select_from(self.model)
def get_list(self, page, sort_column, sort_desc, search, filters, execute=True): def get_list(self, page, sort_column, sort_desc, search, filters, execute=True):
""" """
Return models from the database. Return models from the database.
...@@ -595,6 +603,7 @@ class ModelView(BaseModelView): ...@@ -595,6 +603,7 @@ class ModelView(BaseModelView):
joins = set() joins = set()
query = self.get_query() query = self.get_query()
count_query = self.get_count_query()
# Apply search criteria # Apply search criteria
if self._search_supported and search: if self._search_supported and search:
...@@ -602,6 +611,7 @@ class ModelView(BaseModelView): ...@@ -602,6 +611,7 @@ class ModelView(BaseModelView):
if self._search_joins: if self._search_joins:
for jn in self._search_joins.values(): for jn in self._search_joins.values():
query = query.join(jn) query = query.join(jn)
count_query = count_query.join(jn)
joins = set(self._search_joins.keys()) joins = set(self._search_joins.keys())
...@@ -615,6 +625,7 @@ class ModelView(BaseModelView): ...@@ -615,6 +625,7 @@ class ModelView(BaseModelView):
stmt = tools.parse_like_term(term) stmt = tools.parse_like_term(term)
filter_stmt = [c.ilike(stmt) for c in self._search_fields] filter_stmt = [c.ilike(stmt) for c in self._search_fields]
query = query.filter(or_(*filter_stmt)) query = query.filter(or_(*filter_stmt))
count_query = count_query.filter(or_(*filter_stmt))
# Apply filters # Apply filters
if filters and self._filters: if filters and self._filters:
...@@ -629,13 +640,15 @@ class ModelView(BaseModelView): ...@@ -629,13 +640,15 @@ class ModelView(BaseModelView):
for table in join_tables: for table in join_tables:
if table.name not in joins: if table.name not in joins:
query = query.join(table) query = query.join(table)
count_query = count_query.join(table)
joins.add(table.name) joins.add(table.name)
# Apply filter # Apply filter
query = flt.apply(query, value) query = flt.apply(query, value)
count_query = flt.apply(count_query, value)
# Calculate number of rows # Calculate number of rows
count = query.count() count = count_query.scalar()
# Auto join # Auto join
for j in self._auto_joins: for j in self._auto_joins:
......
/* Global styles */ /* Global styles */
body body
{ {
padding-top: 50px; padding-top: 4px;
} }
/* Form customizations */ /* Form customizations */
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
</head> </head>
<body> <body>
{% block page_body %} {% block page_body %}
<div class="navbar navbar-fixed-top"> <div class="container">
<div class="navbar-inner"> <div class="navbar">
<div class="container"> <div class="navbar-inner">
{% block brand %} {% block brand %}
<span class="brand">{{ admin_view.admin.name }}</span> <span class="brand">{{ admin_view.admin.name }}</span>
{% endblock %} {% endblock %}
...@@ -34,11 +34,9 @@ ...@@ -34,11 +34,9 @@
</ul> </ul>
</div> </div>
</div> </div>
</div>
{{ layout.messages() }} {{ layout.messages() }}
<div class="container">
{% block body %}{% endblock %} {% block body %}{% endblock %}
</div> </div>
{% endblock %} {% endblock %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment