Added button to view imported quiz on Kahoot!.

This commit is contained in:
Mawoka
2023-01-27 23:02:53 +01:00
parent 2d05ee26bd
commit 76311ed0ee
8 changed files with 124 additions and 83 deletions
+1
View File
@@ -181,6 +181,7 @@ class Quiz(ormar.Model):
cover_image: Optional[str] = ormar.Text(nullable=True, unique=False)
background_color: str | None = ormar.Text(nullable=True, unique=False)
background_image: str | None = ormar.Text(nullable=True, unique=False)
kahoot_id: uuid.UUID | None = ormar.UUID(nullable=True, default=None)
@validator("background_image")
def must_come_from_local_cdn(cls, v):
+3 -2
View File
@@ -30,7 +30,8 @@ async def import_quiz(quiz_id: str, user: User) -> Quiz | str:
:param quiz_id: The ID of the quiz to import.
:return: True if the import was successful, False otherwise.
"""
quiz = await get_quiz(quiz_id)
kahoot_quiz_id = quiz_id
quiz = await get_quiz(kahoot_quiz_id)
if quiz is None:
return "quiz not found"
quiz_questions: list[dict] = []
@@ -60,7 +61,6 @@ async def import_quiz(quiz_id: str, user: User) -> Quiz | str:
).dict()
)
cover = None
print(quiz.kahoot.cover)
if quiz.kahoot.cover != "" and quiz.kahoot.cover is not None:
image_bytes = await _download_image(quiz.kahoot.cover)
image_name = f"{quiz_id}--{uuid.uuid4()}"
@@ -77,6 +77,7 @@ async def import_quiz(quiz_id: str, user: User) -> Quiz | str:
questions=json.dumps(quiz_questions),
imported_from_kahoot=True,
cover_image=cover,
kahoot_id=uuid.UUID(kahoot_quiz_id),
)
meilisearch.index(settings.meilisearch_index).add_documents([await get_meili_data(quiz_data)])
return await quiz_data.save()
-1
View File
@@ -105,7 +105,6 @@ async def auth(request: Request, response: Response):
if user_data.email is None:
return RedirectResponse("/account/oauth-error?error=email")
user_in_db = await User.objects.get_or_none(email=user_data.email)
print(user_data.id)
if user_in_db is None:
# REGISTER USER
try:
-1
View File
@@ -92,7 +92,6 @@ async def get_public_quiz(quiz_id: str):
except ValueError:
raise HTTPException(status_code=400, detail="badly formed quiz id")
quiz = await Quiz.objects.select_related("user_id").get_or_none(id=quiz_id)
print(quiz.dict(exclude={"user_id": {"avatar"}}))
if quiz is None:
return JSONResponse(status_code=404, content={"detail": "quiz not found"})
else:
+1 -2
View File
@@ -331,8 +331,7 @@ async def get_email_from_jwt(data: GetEmailFromJWT):
try:
payload = jwt.decode(data.jwt, settings.secret_key, algorithms=["HS256"])
return payload.get("sub")
except JWTError as e:
print(e)
except JWTError:
raise HTTPException(status_code=401)