fix: update bedelia views for today and weekly reservations, available rooms and unassigned commissions
This commit is contained in:
@@ -213,6 +213,8 @@ def get_commissions():
|
||||
elif active == 'false':
|
||||
query = query.filter(Commission.active == False)
|
||||
|
||||
unassigned_room = request.args.get('unassigned_room', '').strip().lower()
|
||||
|
||||
commissions = query.order_by(Commission.id.asc()).all()
|
||||
subjects = Subject.query.order_by(Subject.name.asc()).all()
|
||||
|
||||
@@ -220,6 +222,13 @@ def get_commissions():
|
||||
careers = Career.query.order_by(Career.name.asc()).all()
|
||||
careers_data = [{'id': cr.id, 'name': cr.name, 'code': cr.code} for cr in careers]
|
||||
|
||||
# Pre-cargar reservas activas para enriquecer con asignación de aula
|
||||
reservations_by_comm = {}
|
||||
all_res = Reservation.query.filter(Reservation.commission_id.isnot(None)).order_by(Reservation.start_time.asc()).all()
|
||||
for r in all_res:
|
||||
if r.commission_id not in reservations_by_comm:
|
||||
reservations_by_comm[r.commission_id] = r
|
||||
|
||||
commissions_data = []
|
||||
for c in commissions:
|
||||
if search:
|
||||
@@ -228,11 +237,25 @@ def get_commissions():
|
||||
if search not in s_name and search not in c_code:
|
||||
continue
|
||||
|
||||
res = reservations_by_comm.get(c.id)
|
||||
c_room = res.classroom if res else None
|
||||
c_code_val = c_room.code if c_room else None
|
||||
is_virt_room = bool(c_room.is_virtual or 'virtual' in (c_room.code or '').lower() or 'virtual' in (c_room.building or '').lower()) if c_room else False
|
||||
has_v_link = bool(c.virtual_link and c.virtual_link.strip())
|
||||
has_classroom = bool(c_code_val or has_v_link)
|
||||
|
||||
if unassigned_room in ['true', '1'] and has_classroom:
|
||||
continue
|
||||
if unassigned_room in ['false', '0'] and not has_classroom:
|
||||
continue
|
||||
|
||||
career_name = c.career_name if hasattr(c, 'career_name') else 'Carrera General'
|
||||
career_names = c.career_names if hasattr(c, 'career_names') else career_name
|
||||
careers_list = c.careers if hasattr(c, 'careers') else []
|
||||
career_id_val = c.career_id if hasattr(c, 'career_id') else (c.subject.career_id if c.subject else None)
|
||||
|
||||
display_room = c_code_val or ('Campus Virtual' if has_v_link else 'Sin Aula')
|
||||
|
||||
commissions_data.append({
|
||||
'id': c.id,
|
||||
'code': c.code,
|
||||
@@ -256,7 +279,11 @@ def get_commissions():
|
||||
'max_students': c.max_students or 35,
|
||||
'current_students': getattr(c, 'current_students', 0) or 0,
|
||||
'active': c.active,
|
||||
'virtual_link': getattr(c, 'virtual_link', '') or ''
|
||||
'virtual_link': getattr(c, 'virtual_link', '') or '',
|
||||
'has_classroom': has_classroom,
|
||||
'classroom_name': display_room,
|
||||
'classroom_code': c_code_val,
|
||||
'is_virtual': is_virt_room or has_v_link
|
||||
})
|
||||
|
||||
subjects_data = []
|
||||
|
||||
Reference in New Issue
Block a user