Skip to content

Commit

Permalink
🪲 Dont try translating program with blanks (#5854)
Browse files Browse the repository at this point in the history
Fixes the problem by checking if the program has blanks before trying to translate it. Also, I changed the in-site calculation if a program was modified, for the flag that comes from the DB

Fixes #5833 

**How to test**

* Log in as student3 and then go to level 1 and execute this program
```
print Welcome to Hedy's restaurant 🍟
_ What would you like to order?
echo So you would like to order
print Thank you for your order!
print It's on its way!
echo So you would like to order
print Thank you for your order!
print It's on its way!
echo So you would like to order
print Thank you for your order!
print It's on its way!
```
* Now log in as teacher1, change your keyword language to anything other than English and go check the program uploaded by student1, it should work normally.
  • Loading branch information
jpelay authored Oct 16, 2024
1 parent 4480cf3 commit a28ae64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1877,12 +1877,15 @@ def view_program(user, id):
result['username']) else None

code = result['code']
if result.get("lang") != "en" and result.get("lang") in ALL_KEYWORD_LANGUAGES.keys():
# if the snippet has blanks, it'll fail in the translation process
# so we just dont translate it if it has any
has_blanks = hedy.location_of_first_blank(code) > 0
if not has_blanks and result.get("lang") != "en" and result.get("lang") in ALL_KEYWORD_LANGUAGES.keys():
code = hedy_translation.translate_keywords(code, from_lang=result.get(
'lang'), to_lang="en", level=int(result.get('level', 1)))
# If the keyword language is non-English -> parse again to guarantee
# completely localized keywords
if g.keyword_lang != "en":
if not has_blanks and g.keyword_lang != "en":
code = hedy_translation.translate_keywords(
code,
from_lang="en",
Expand Down
2 changes: 1 addition & 1 deletion website/for_teachers.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def get_grid_info(self, user, class_id, level):
name = adventure_names.get(program['adventure_name'], program['adventure_name'])
customized_level = class_adventures_formatted.get(str(program['level']))
if next((adventure for adventure in customized_level if adventure["name"] == name), False)\
and self.is_program_modified(program, adventures, teacher_adventures):
and program.get('is_modified'):
student_adventure_id = f"{student}-{program['adventure_name']}-{level}"
current_adventure = self.db.student_adventure_by_id(student_adventure_id)
if not current_adventure:
Expand Down

0 comments on commit a28ae64

Please sign in to comment.