From 7a7eb74e560fb77b709e292dac26fee2a6967156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Pelay?= Date: Mon, 4 Mar 2024 11:09:43 -0400 Subject: [PATCH 1/2] add check for programs with empty string --- app.py | 4 +++- hedy_content.py | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index a67beda4416..fe17e81041e 100644 --- a/app.py +++ b/app.py @@ -1006,8 +1006,10 @@ def programs_page(user): submitted=submitted, pagination_token=page) ids_to_fetch = [] + # Some old programs don't have adventure_name in them, or the field is emtpy. for program in all_programs: - if 'adventure_name' in program and program['adventure_name'] not in adventure_names: + if 'adventure_name' in program and program['adventure_name'] != '' and\ + program['adventure_name'] not in adventure_names: ids_to_fetch.append(program['adventure_name']) teacher_adventures = DATABASE.batch_get_adventures(ids_to_fetch) diff --git a/hedy_content.py b/hedy_content.py index 669b3c48506..bd485e5eca5 100644 --- a/hedy_content.py +++ b/hedy_content.py @@ -542,11 +542,12 @@ def get_sorted_level_programs(self, programs, adventure_names): def get_sorted_adventure_programs(self, programs, adventure_names): programs_by_adventure = [] for item in programs: - programs_by_adventure.append( - {'adventure_name': adventure_names.get(item.get('adventure_name'), item.get('adventure_name')), - 'level': item['level'], - } - ) + if item.get('adventure_name') != '': + programs_by_adventure.append( + {'adventure_name': adventure_names.get(item.get('adventure_name'), item.get('adventure_name')), + 'level': item['level'], + } + ) sort = {} for program in programs_by_adventure: From 0f787e2f716d5d7cf1cc910e8469bc8f780a72cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Pelay?= Date: Tue, 5 Mar 2024 10:48:44 -0400 Subject: [PATCH 2/2] more pythonic way of checking if string is empty --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index fe17e81041e..1aaa2169b1c 100644 --- a/app.py +++ b/app.py @@ -1008,7 +1008,7 @@ def programs_page(user): ids_to_fetch = [] # Some old programs don't have adventure_name in them, or the field is emtpy. for program in all_programs: - if 'adventure_name' in program and program['adventure_name'] != '' and\ + if 'adventure_name' in program and program['adventure_name'] and\ program['adventure_name'] not in adventure_names: ids_to_fetch.append(program['adventure_name'])