Skip to content

Commit

Permalink
💻 Add adventure within customize class (#5313)
Browse files Browse the repository at this point in the history
Fixes #4084 

**How to test:**
1. Go to `/customize-class`
2. Next to the Reset button (top right), click 'Create adventure'. 
3. Check that the Adventure is correctly added to the level and the class you were in.


https://github.com/hedyorg/hedy/assets/48122190/0a5cb4ee-d231-4328-99fa-d9a86e9b8072
  • Loading branch information
Annelein authored Mar 27, 2024
1 parent 7d4e7c3 commit 3a94a4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions templates/customize-class/partial-sortable-adventures.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ <h3 class="flex-1">{{_('select_adventures')}}</h3>
>
{{_('reset_button')}}
</button>
<div class="flex flex-row">
<button id="create_adventure_button" class="green-btn"
hx-trigger="click"
hx-post="/for-teachers/create-adventure/{{class_id}}/{{level}}"
hx-swap="none"
_="on htmx:afterRequest if detail.xhr.response
window.open('/for-teachers/customize-adventure/' + detail.xhr.response, '_self')"
data-cy="edit-link"{% if second_teacher and role == 'viewer' %}disabled{% endif %}>
{{_('create_adventure')}}
</button>
</div>
</div>
</div>
<div class="flex items-center min-w-max">
Expand Down
12 changes: 8 additions & 4 deletions website/for_teachers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,9 @@ def add_adventure_to_class_level(self, user, class_id, adventure_id, level, remo

@route("/create-adventure/", methods=["POST"])
@route("/create-adventure/<class_id>", methods=["POST"])
@route("/create-adventure/<class_id>/<level>", methods=["POST"])
@requires_teacher
def create_adventure(self, user, class_id=None):
def create_adventure(self, user, class_id=None, level=None):
if not is_teacher(user) and not is_admin(user):
return utils.error_page(error=403, ui_message=gettext("retrieve_class_error"))

Expand All @@ -1200,21 +1201,24 @@ def create_adventure(self, user, class_id=None):
name += 'X'
continue

if not level:
level = "1"

session['class_id'] = class_id
adventure = {
"id": adventure_id,
"date": utils.timems(),
"creator": user["username"],
"name": name,
"classes": [class_id],
"level": 1,
"levels": ["1"],
"level": int(level),
"levels": [level],
"content": "",
"public": 0,
"language": g.lang,
}
self.db.store_adventure(adventure)
if class_id:
self.add_adventure_to_class_level(user, class_id, adventure_id, "1", False)
self.add_adventure_to_class_level(user, class_id, adventure_id, str(level), False)

return adventure["id"], 200

0 comments on commit 3a94a4d

Please sign in to comment.