Skip to content

Commit

Permalink
Merge pull request #5326 from hedyorg/old-curly-braces
Browse files Browse the repository at this point in the history
💻 format all old adventure contents with curlies
  • Loading branch information
hasan-sh authored Apr 3, 2024
2 parents 3ead5ea + d507ad6 commit 1acc763
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion website/frontend_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get(self, key, default=None):

@staticmethod
def from_teacher_adventure_database_row(row):
text, example_code = halve_adventure_content(row["content"])
text, example_code = halve_adventure_content(row.get("formatted_content", row["content"]))
return Adventure(
short_name=row['id'],
name=row['name'],
Expand Down
46 changes: 24 additions & 22 deletions website/public_adventures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json

import hedy
import hedy_content
import utils
from config import config
from website.auth import requires_teacher
Expand All @@ -13,6 +14,7 @@
from .achievements import Achievements
from .database import Database
from .website_module import WebsiteModule, route
from safe_format import safe_format

cookie_name = config["session"]["cookie_name"]
invite_length = config["session"]["invite_length"] * 60
Expand All @@ -30,7 +32,6 @@ def __init__(self, db: Database, achievements: Achievements):
self.available_tags = set()

def init(self, user):
adventures = []
included = {}
self.adventures = {}
self.available_languages = set()
Expand All @@ -49,32 +50,33 @@ def init(self, user):
continue
public_profile = self.db.get_public_profile_settings(adventure.get('creator'))
included[adventure["name"]] = True
adventures.append(
{
"id": adventure.get("id"),
"name": adventure.get("name"),
"short_name": adventure.get("name"),
"author": adventure.get("author", adventure["creator"]),
"creator": adventure.get("creator"),
"creator_public_profile": public_profile,
"date": utils.localized_date_format(adventure.get("date")),
"level": adventure.get("level"),
"levels": adventure.get("levels"),
"language": adv_lang,
"cloned_times": adventure.get("cloned_times"),
"tags": adv_tags,
"text": adventure.get("content"),
"is_teacher_adventure": True,
# "content": adventure.get("content")
}
)

content = safe_format(adventure.get('formatted_content', adventure['content']),
**hedy_content.KEYWORDS.get(g.keyword_lang))
current_adventure = {
"id": adventure.get("id"),
"name": adventure.get("name"),
"short_name": adventure.get("name"),
"author": adventure.get("author", adventure["creator"]),
"creator": adventure.get("creator"),
"creator_public_profile": public_profile,
"date": utils.localized_date_format(adventure.get("date")),
"level": adventure.get("level"),
"levels": adventure.get("levels"),
"language": adv_lang,
"cloned_times": adventure.get("cloned_times"),
"tags": adv_tags,
"text": content,
"is_teacher_adventure": True,
}

# save adventures for later usage.
for _level in adventure.get("levels", [adventure.get("level")]):
_level = int(_level)
if self.adventures.get(_level):
self.adventures[_level].append(adventures[-1])
self.adventures[_level].append(current_adventure)
else:
self.adventures[_level] = [adventures[-1]]
self.adventures[_level] = [current_adventure]

available_levels = adventure["levels"] if adventure.get("levels") else [adventure["level"]]
self.customizations["available_levels"].update([int(adv_level) for adv_level in available_levels])
Expand Down

0 comments on commit 1acc763

Please sign in to comment.