Skip to content

Commit

Permalink
🪲 Old programs without 'is_modified' are shown (#5521)
Browse files Browse the repository at this point in the history
Also fixes that only modified programs are shown in 'My public profile'

**How to test**
Is it correct that we don't have saved programs in the test database? Then it's a bit difficult to test:
1. Go to programs.py and comment out line 101, 104 and 106
2. Save a few programs, check if they are shown in `/my-programs`
3. Make a few public and see if they are shown in 'My public profile'
  • Loading branch information
Annelein authored May 13, 2024
1 parent 6416382 commit 5807494
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,9 @@ def programs_page(user):
date = utils.delta_timestamp(item['date'])
# This way we only keep the first 4 lines to show as preview to the user
preview_code = "\n".join(item['code'].split("\n")[:4])
if item.get('is_modified'):
# When saving a program, 'is_modified' is set to True or False
# But for older programs, 'is_modified' doesn't exist yet, therefore the check
if item.get('is_modified') or 'is_modified' not in item:
programs.append(
{'id': item['id'],
'preview_code': preview_code,
Expand Down Expand Up @@ -2667,10 +2669,15 @@ def public_user_page(username):
public=True,
pagination_token=page)

modified_programs = []
for program in all_programs:
if program.get('is_modified') or 'is_modified' not in program:
modified_programs.append(program)

sorted_level_programs = hedy_content.Adventures(
g.lang).get_sorted_level_programs(all_programs, adventure_names)
g.lang).get_sorted_level_programs(modified_programs, adventure_names)
sorted_adventure_programs = hedy_content.Adventures(
g.lang).get_sorted_adventure_programs(all_programs, adventure_names)
g.lang).get_sorted_adventure_programs(modified_programs, adventure_names)

favorite_program = None
if 'favourite_program' in user_public_info and user_public_info['favourite_program']:
Expand Down
2 changes: 1 addition & 1 deletion website/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def store_user_program(self,
# and if it was already modified and now is so again, count should not increase.
if is_modified and not program.get('is_modified'):
self.db.increase_user_program_count(user["username"])
program = self.db.update_program(program['id'], {'is_modified': True})
program = self.db.update_program(program['id'], {'is_modified': is_modified})

querylog.log_value(program_id=program['id'],
adventure_name=adventure_name, error=error, code_lines=len(code.split('\n')))
Expand Down

0 comments on commit 5807494

Please sign in to comment.