✨ Added basic quiztivity editor
This commit is contained in:
@@ -11,7 +11,9 @@ import ormar
|
||||
from pydantic import BaseModel, Json, validator
|
||||
from enum import Enum
|
||||
from . import metadata, database
|
||||
from .quiztivity import QuizTivityPage
|
||||
from ..config import server_regex
|
||||
from sqlalchemy import func
|
||||
|
||||
|
||||
class UserAuthTypes(Enum):
|
||||
@@ -318,3 +320,21 @@ class GameResults(ormar.Model):
|
||||
tablename = "game_results"
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
|
||||
class QuizTivityInput(BaseModel):
|
||||
title: str
|
||||
pages: list[QuizTivityPage]
|
||||
|
||||
|
||||
class QuizTivity(ormar.Model):
|
||||
id: uuid.UUID = ormar.UUID(primary_key=True)
|
||||
title: str = ormar.Text(nullable=False)
|
||||
created_at: datetime = ormar.DateTime(nullable=False, server_default=func.now())
|
||||
user: User | None = ormar.ForeignKey(User)
|
||||
pages: list[QuizTivityPage] = ormar.JSON(nullable=False)
|
||||
|
||||
class Meta:
|
||||
tablename = "quiztivitys"
|
||||
metadata = metadata
|
||||
database = database
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
from pydantic import BaseModel
|
||||
import enum
|
||||
|
||||
|
||||
class Pdf(BaseModel):
|
||||
url: str
|
||||
|
||||
|
||||
class _MemoryCard(BaseModel):
|
||||
image: str | None
|
||||
text: str | None
|
||||
id: str
|
||||
|
||||
|
||||
class Memory(BaseModel):
|
||||
cards: list[list[_MemoryCard]]
|
||||
|
||||
|
||||
class Markdown(BaseModel):
|
||||
markdown: str
|
||||
|
||||
|
||||
class QuizTivityTypes(str, enum.Enum):
|
||||
SLIDE = "SLIDE"
|
||||
PDF = "PDF"
|
||||
MEMORY = "MEMORY"
|
||||
MARKDOWN = "MARKDOWN"
|
||||
|
||||
|
||||
TYPE_CLASS_LIST = {
|
||||
QuizTivityTypes.PDF: type(Pdf),
|
||||
QuizTivityTypes.MEMORY: type(Memory),
|
||||
QuizTivityTypes.MARKDOWN: type(Markdown),
|
||||
}
|
||||
|
||||
|
||||
class QuizTivityPage(BaseModel):
|
||||
title: str | None
|
||||
type: QuizTivityTypes
|
||||
data: Pdf | Memory | Markdown
|
||||
|
||||
# @validator("type")
|
||||
# def match_type_to_data_type(cls, v, values, **kwargs):
|
||||
# print(values)
|
||||
# if TYPE_CLASS_LIST[v] != type(values["data"]):
|
||||
# raise ValueError("Specified Type doesn't match real data type")
|
||||
# pass
|
||||
Reference in New Issue
Block a user