Skip to content

Commit

Permalink
🪲 fix programs page (#5332)
Browse files Browse the repository at this point in the history
The program overview currently throws an error. 
![image](https://github.com/hedyorg/hedy/assets/20051470/c56cb40e-4ff0-4e1a-9518-c9d6140ff6c4)

This PR fixes it and makes sure that we show a custom adventure's name and not id in the program block.

**How to test?**
- run a program/adventure 
- go to my programs
- it should work. 
- stop the server
- remove the `adventure_name` field from that program/adventure's in dev_database > programs > your program
- re-run the server
- my programs page should still run fine!
  • Loading branch information
hasan-sh authored Apr 2, 2024
1 parent 97d245d commit 0f90c91
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions hedy_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,27 +554,28 @@ def get_sorted_level_programs(self, programs, adventure_names):
for item in programs:
programs_by_level.append(
{'level': item['level'],
'adventure_name': item.get('adventure_name'),
'adventure_name': item.get('adventure_name', item['name']),
}
)

sort = {}

for program in programs_by_level:
if program['level'] in sort:
sort[program['level']].append(adventure_names.get(program['adventure_name'], program['adventure_name']))
else:
sort[program['level']] = [adventure_names.get(program['adventure_name'], program['adventure_name'])]
for level, adventures in sort.copy().items():
sort[level] = sorted(adventures, key=lambda s: s.lower())
sort[level] = sorted(adventures, key=lambda s: s.lower() if s else "")

return dict(sorted(sort.items(), key=lambda item: item[0]))

def get_sorted_adventure_programs(self, programs, adventure_names):
programs_by_adventure = []
for item in programs:
if item.get('adventure_name') != '':
if item.get('adventure_name'):
programs_by_adventure.append(
{'adventure_name': adventure_names.get(item.get('adventure_name'), item.get('adventure_name')),
{'adventure_name': adventure_names.get(item.get('adventure_name')) or item.get('adventure_name'),
'level': item['level'],
}
)
Expand All @@ -589,7 +590,7 @@ def get_sorted_adventure_programs(self, programs, adventure_names):
sort[adventure] = sorted(levels, key=lambda item: item)

return {key: sort[key]
for key in sorted(sort.keys(), key=lambda s: s.lower())}
for key in sorted(sort.keys(), key=lambda s: s.lower() if s else "")}

def get_adventure_names(self, keyword_lang):
return {aid: adv['name'] for aid, adv in deep_translate_keywords(
Expand Down
2 changes: 1 addition & 1 deletion static/js/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ export async function runit(level: number, lang: string, disabled_prompt: string
is_debug: run_type === 'debug',
tutorial: $('#code_output').hasClass("z-40"), // if so -> tutorial mode
read_aloud : !!$('#speak_dropdown').val(),
adventure_name: adventureName,
adventure_name: adventure.name,

// Save under an existing id if this field is set
program_id: isServerSaveInfo(adventure?.save_info) ? adventure.save_info.id : undefined,
Expand Down
2 changes: 1 addition & 1 deletion static/js/appbundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -99293,7 +99293,7 @@ def note_with_error(value, err):
is_debug: run_type === "debug",
tutorial: $("#code_output").hasClass("z-40"),
read_aloud: !!$("#speak_dropdown").val(),
adventure_name: adventureName,
adventure_name: adventure.name,
program_id: isServerSaveInfo(adventure == null ? void 0 : adventure.save_info) ? adventure.save_info.id : void 0,
save_name: saveNameFromInput()
};
Expand Down
4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

0 comments on commit 0f90c91

Please sign in to comment.