diff --git a/app/routes/facilities.py b/app/routes/facilities.py index cf1cd07..ea6ca2f 100644 --- a/app/routes/facilities.py +++ b/app/routes/facilities.py @@ -23,7 +23,28 @@ def list_facilities(): ).order_by(Facility.name).all() else: facilities = Facility.query.order_by(Facility.name).all() - return render_template('facilities/list.html', facilities=facilities) + + # Group facilities by Contract (Project) for the collapsible list view. + # Facilities with no contract are collected under key '__none__' and + # rendered last as "No Contract Assigned". + from collections import OrderedDict + grouped = OrderedDict() + ungrouped = [] + for f in facilities: + if f.project: + key = f.project.name + grouped.setdefault(key, {'project': f.project, 'facilities': []}) + grouped[key]['facilities'].append(f) + else: + ungrouped.append(f) + + grouped = OrderedDict(sorted(grouped.items())) + if ungrouped: + grouped['__none__'] = {'project': None, 'facilities': ungrouped} + + logger.info('FACILITIES | list | user=%s | total=%s | groups=%s', + current_user.username, len(facilities), len(grouped)) + return render_template('facilities/list.html', facilities=facilities, grouped=grouped) @bp.route('/new', methods=['GET', 'POST']) @login_required diff --git a/app/templates/facilities/list.html b/app/templates/facilities/list.html index 418af8d..5e6db75 100644 --- a/app/templates/facilities/list.html +++ b/app/templates/facilities/list.html @@ -16,58 +16,94 @@ -
- {{ facility.address }} -
++ {{ facility.address }} +
+ {% endif %} + +