Enhance search functionality with pagination and improve eager loading in utils
This commit is contained in:
parent
eb7e446e56
commit
cffdc27724
5 changed files with 56 additions and 46 deletions
Binary file not shown.
Binary file not shown.
|
@ -316,6 +316,7 @@ def search():
|
|||
if not query:
|
||||
return redirect(url_for('index'))
|
||||
|
||||
InventoryAlias = aliased(Inventory)
|
||||
UserAlias = aliased(User)
|
||||
|
||||
inventory_query = eager_load_inventory_relationships(db.session.query(Inventory).join(UserAlias, Inventory.owner)).filter(
|
||||
|
@ -334,11 +335,14 @@ def search():
|
|||
User.last_name.ilike(f"%{query}%")
|
||||
))
|
||||
user_pagination = make_paginated_data(user_query, user_page)
|
||||
worklog_query = eager_load_worklog_relationships(db.session.query(WorkLog).join(UserAlias, WorkLog.contact)).filter(
|
||||
worklog_query = eager_load_worklog_relationships(db.session.query(WorkLog).join(UserAlias, WorkLog.contact).join(InventoryAlias, WorkLog.work_item)).filter(
|
||||
or_(
|
||||
WorkLog.notes.ilike(f"%{query}%"),
|
||||
UserAlias.first_name.ilike(f"%{query}%"),
|
||||
UserAlias.last_name.ilike(f"%{query}%")
|
||||
UserAlias.last_name.ilike(f"%{query}%"),
|
||||
InventoryAlias.inventory_name.ilike(f"%{query}%"),
|
||||
InventoryAlias.serial.ilike(f"%{query}%"),
|
||||
InventoryAlias.barcode.ilike(f"%{query}%")
|
||||
))
|
||||
worklog_pagination = make_paginated_data(worklog_query, worklog_page)
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ title=title,
|
|||
) }}
|
||||
|
||||
<div class="container">
|
||||
{% if results['inventory']['rows'] %}
|
||||
<div>
|
||||
{{ tables.render_table(
|
||||
headers = results['inventory']['headers'],
|
||||
|
@ -30,6 +31,8 @@ title=title,
|
|||
'worklog_page': results['worklog']['pagination']['page']
|
||||
})}}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if results['users']['rows'] %}
|
||||
<div>
|
||||
{{ tables.render_table(
|
||||
headers = results['users']['headers'],
|
||||
|
@ -49,6 +52,8 @@ title=title,
|
|||
'worklog_page': results['worklog']['pagination']['page']
|
||||
})}}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if results['worklog']['rows'] %}
|
||||
<div>
|
||||
{{ tables.render_table(
|
||||
headers = results['worklog']['headers'],
|
||||
|
@ -69,5 +74,6 @@ title=title,
|
|||
'user_page': results['users']['pagination']['page']
|
||||
})}}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
6
utils.py
6
utils.py
|
@ -1,4 +1,4 @@
|
|||
from sqlalchemy.orm import joinedload
|
||||
from sqlalchemy.orm import joinedload, selectinload
|
||||
from .models import User, Room, Inventory, WorkLog
|
||||
|
||||
def eager_load_user_relationships(query):
|
||||
|
@ -19,8 +19,8 @@ def eager_load_room_relationships(query):
|
|||
return query.options(
|
||||
joinedload(Room.area),
|
||||
joinedload(Room.room_function),
|
||||
joinedload(Room.inventory),
|
||||
joinedload(Room.users)
|
||||
selectinload(Room.inventory),
|
||||
selectinload(Room.users)
|
||||
)
|
||||
|
||||
def eager_load_worklog_relationships(query):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue