Skip to content

Commit 22ac398

Browse files
committed
Merge branch 'enhanced-search' into enhanced_search_brian
2 parents ef2aa98 + 37e3f57 commit 22ac398

File tree

2 files changed

+38
-40
lines changed

2 files changed

+38
-40
lines changed

tcf_website/admin.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,38 @@ def get_queryset(self, request):
6262
qs = qs.prefetch_related("instructors")
6363
return qs
6464

65+
6566
class SectionTimeAdmin(admin.ModelAdmin):
66-
list_display = ['section', 'get_days_display', 'start_time', 'end_time']
67-
list_filter = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'start_time', 'end_time']
67+
list_display = ["section", "get_days_display", "start_time", "end_time"]
68+
list_filter = ["monday", "tuesday", "wednesday", "thursday", "friday", "start_time", "end_time"]
6869
search_fields = [
69-
'section__course__subdepartment__mnemonic',
70-
'section__course__number',
71-
'section__course__title',
70+
"section__course__subdepartment__mnemonic",
71+
"section__course__number",
72+
"section__course__title",
7273
]
73-
autocomplete_fields = ['section']
74+
autocomplete_fields = ["section"]
7475

7576
def get_days_display(self, obj):
7677
"""Return formatted string of meeting days."""
7778
days = []
78-
if getattr(obj, 'monday', False):
79-
days.append('MON')
80-
if getattr(obj, 'tuesday', False):
81-
days.append('TUE')
82-
if getattr(obj, 'wednesday', False):
83-
days.append('WED')
84-
if getattr(obj, 'thursday', False):
85-
days.append('THU')
86-
if getattr(obj, 'friday', False):
87-
days.append('FRI')
88-
return ', '.join(days)
89-
get_days_display.short_description = 'Days'
79+
if getattr(obj, "monday", False):
80+
days.append("MON")
81+
if getattr(obj, "tuesday", False):
82+
days.append("TUE")
83+
if getattr(obj, "wednesday", False):
84+
days.append("WED")
85+
if getattr(obj, "thursday", False):
86+
days.append("THU")
87+
if getattr(obj, "friday", False):
88+
days.append("FRI")
89+
return ", ".join(days)
90+
91+
get_days_display.short_description = "Days"
9092

9193
def get_queryset(self, request):
9294
qs = super().get_queryset(request)
93-
return qs.select_related(
94-
'section__course__subdepartment'
95-
)
95+
return qs.select_related("section__course__subdepartment")
96+
9697

9798
class CourseGradeAdmin(admin.ModelAdmin):
9899
ordering = ["course__subdepartment", "course__number", "course__title"]

tcf_website/management/commands/load_semester.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -310,41 +310,38 @@ def load_section(
310310
def parse_section_times(section_times_str):
311311
if not section_times_str:
312312
return []
313-
313+
314314
times = []
315-
for time_block in section_times_str.split(','):
315+
for time_block in section_times_str.split(","):
316316
if not time_block.strip():
317317
continue
318318
try:
319-
days_part, time_part = time_block.strip().split(' ', 1)
320-
start_time, end_time = time_part.split(' - ')
321-
319+
days_part, time_part = time_block.strip().split(" ", 1)
320+
start_time, end_time = time_part.split(" - ")
321+
322322
# Create time block with boolean fields
323323
time_data = {
324-
'monday': 'Mo' in days_part,
325-
'tuesday': 'Tu' in days_part,
326-
'wednesday': 'We' in days_part,
327-
'thursday': 'Th' in days_part,
328-
'friday': 'Fr' in days_part,
329-
'start_time': datetime.strptime(start_time, '%I:%M%p').time(),
330-
'end_time': datetime.strptime(end_time, '%I:%M%p').time()
324+
"monday": "Mo" in days_part,
325+
"tuesday": "Tu" in days_part,
326+
"wednesday": "We" in days_part,
327+
"thursday": "Th" in days_part,
328+
"friday": "Fr" in days_part,
329+
"start_time": datetime.strptime(start_time, "%I:%M%p").time(),
330+
"end_time": datetime.strptime(end_time, "%I:%M%p").time(),
331331
}
332332
times.append(time_data)
333-
333+
334334
except (ValueError, IndexError):
335335
continue
336-
336+
337337
return times
338338

339339
# Clear existing section times
340340
section.sectiontime_set.all().delete()
341-
341+
342342
# Create new section times
343343
times = parse_section_times(section_times)
344344
for time_data in times:
345-
SectionTime.objects.create(
346-
section=section,
347-
**time_data
348-
)
345+
SectionTime.objects.create(section=section, **time_data)
349346

350347
return section

0 commit comments

Comments
 (0)