Skip to content

Commit 3c445a9

Browse files
committed
Improve sanity of custom SQL in Ajax scheduler json view
Fixes #1698 by avoiding the cast to a string, since what we really wanted was a list of ints anyway.
1 parent 61b1d57 commit 3c445a9

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

esp/esp/program/modules/handlers/jsondatamodule.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,9 @@ def resource_types(prog):
136136
@needs_admin
137137
@cached_module_view
138138
def schedule_assignments(prog):
139-
data = ClassSection.objects.filter(status__gte=0, parent_class__status__gte=0, parent_class__parent_program=prog).select_related('resourceassignment__resource__name', 'resourceassignment__resource__event').extra({'timeslots': 'SELECT string_agg(to_char(resources_resource.event_id, \'999\'), \',\') FROM resources_resource, resources_resourceassignment WHERE resources_resource.id = resources_resourceassignment.resource_id AND resources_resourceassignment.target_id = program_classsection.id'}).values('id', 'resourceassignment__resource__name', 'timeslots').distinct()
140-
# Convert comma-separated timeslot IDs to lists
139+
data = ClassSection.objects.filter(status__gte=0, parent_class__status__gte=0, parent_class__parent_program=prog).select_related('resourceassignment__resource__name', 'resourceassignment__resource__event').extra({'timeslots': 'SELECT array_agg(resources_resource.event_id) FROM resources_resource, resources_resourceassignment WHERE resources_resource.id = resources_resourceassignment.resource_id AND resources_resourceassignment.target_id = program_classsection.id'}).values('id', 'resourceassignment__resource__name', 'timeslots').distinct()
141140
for i in range(len(data)):
142-
if data[i]['timeslots']:
143-
data[i]['timeslots'] = [int(x) for x in data[i]['timeslots'].strip().split(',')]
144-
else:
141+
if not data[i]['timeslots']:
145142
data[i]['timeslots'] = []
146143
return {'schedule_assignments': list(data)}
147144
schedule_assignments.method.cached_function.depend_on_row(ClassSection, lambda sec: {'prog': sec.parent_class.parent_program})

0 commit comments

Comments
 (0)