Skip to content

Commit

Permalink
refactor: remove old 'adventures' pages (hedyorg#1357)
Browse files Browse the repository at this point in the history
The pages under `/hedy/adventures` are no longer used. Their code
can be removed.

Co-authored-by: Felienne <[email protected]>
  • Loading branch information
rix0rrr and Felienne authored Nov 21, 2021
1 parent e5f4218 commit 4a0bac0
Showing 1 changed file with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,71 +763,6 @@ def quiz_feedback(level_source, question_nr):
menu=render_main_menu('adventures'),
auth=TRANSLATIONS.data[g.lang]['Auth'])


# Adventure mode
@app.route('/hedy/adventures', methods=['GET'])
def adventures_list():
adventures = load_adventure_for_language(g.lang)
menu = render_main_menu('adventures')
return render_template('adventures.html', adventures=adventures, menu=menu, auth=TRANSLATIONS.get_translations(g.lang, 'Auth'))

@app.route('/hedy/adventures/<adventure_name>', methods=['GET'], defaults={'level': 1})
@app.route('/hedy/adventures/<adventure_name>/<level>', methods=['GET'])
def adventure_page(adventure_name, level):

user = current_user()
level = int(level)
adventures = load_adventure_for_language(g.lang)

# If requested adventure does not exist, return 404
if not adventure_name in adventures:
return utils.page_404 (TRANSLATIONS, render_main_menu('adventures'), current_user()['username'], g.lang, TRANSLATIONS.get_translations (g.lang, 'ui').get ('no_such_adventure'))

adventure = adventures[adventure_name]

# If no level is specified(this will happen if the last element of the path(minus the query parameter) is the same as the adventure_name)
if re.sub(r'\?.+', '', request.url.split('/')[len(request.url.split('/')) - 1]) == adventure_name:
# If user is logged in, check if they have a program for this adventure
# If there are many, note the highest level for which there is a saved program
desired_level = 0
if user['username']:
existing_programs = DATABASE.programs_for_user(user['username'])
for program in existing_programs:
if 'adventure_name' in program and program['adventure_name'] == adventure_name and program['level'] > desired_level:
desired_level = program['level']
# If the user has a saved program for this adventure, redirect them to the level with the highest adventure
if desired_level != 0:
return redirect(request.url.replace('/' + adventure_name, '/' + adventure_name + '/' + str(desired_level)), code=302)
# If user is not logged in, or has no saved programs for this adventure, default to the lowest level available for the adventure
if desired_level == 0:
for key in adventure['levels'].keys():
if isinstance(key, int) and(desired_level == 0 or desired_level > key):
desired_level = key
level = desired_level

# If requested level is not in adventure, return 404
if not level in adventure['levels']:
return utils.page_404 (TRANSLATIONS, render_main_menu('adventures'), current_user()['username'], g.lang, TRANSLATIONS.get_translations (g.lang, 'ui').get ('no_such_adventure_level'))

adventures_for_level = load_adventures_per_level(g.lang, level)
level_defaults_for_lang = LEVEL_DEFAULTS[g.lang]
defaults = level_defaults_for_lang.get_defaults_for_level(level)
max_level = level_defaults_for_lang.max_level()

g.prefix = '/hedy'
return hedyweb.render_code_editor_with_tabs(
level_defaults=defaults,
max_level=max_level,
level_number=level,
menu=render_main_menu('hedy'),
translations=TRANSLATIONS,
version=version(),
adventures=adventures_for_level,
restrictions='',
# The relevant loaded program will be available to client-side js and it will be loaded by js.
loaded_program='',
adventure_name=adventure_name)

# routing to index.html
@app.route('/ontrack', methods=['GET'], defaults={'level': '1', 'step': 1})
@app.route('/onlinemasters', methods=['GET'], defaults={'level': '1', 'step': 1})
Expand Down

0 comments on commit 4a0bac0

Please sign in to comment.