From 5807494b7e7990c5d9959ef0891fa9fb1e191847 Mon Sep 17 00:00:00 2001 From: Annelein <48122190+Annelein@users.noreply.github.com> Date: Mon, 13 May 2024 19:02:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=B2=20Old=20programs=20without=20'is?= =?UTF-8?q?=5Fmodified'=20are=20shown=20(#5521)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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' --- app.py | 13 ++++++++++--- website/programs.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 6b9c982e33b..96a20f2191f 100644 --- a/app.py +++ b/app.py @@ -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, @@ -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']: diff --git a/website/programs.py b/website/programs.py index c0a70cac11a..e850bd6bba3 100644 --- a/website/programs.py +++ b/website/programs.py @@ -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')))