-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Несколько правильных ответов + корректные схемы вопросов
- Loading branch information
1 parent
9dc64d3
commit 6ea6c74
Showing
8 changed files
with
172 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../migrations/versions/2023_11_15_1205-5bc05f78249a_добавляет_таблицы_вопросов_и_ответов.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
"""Добавляет таблицы вопросов и ответов | ||
Revision ID: 5bc05f78249a | ||
Revises: 5aa9681ef1db | ||
Create Date: 2023-11-15 12:05:18.429020 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '5bc05f78249a' | ||
down_revision: Union[str, None] = '5aa9681ef1db' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('answers', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('question_id', sa.UUID(), nullable=False), | ||
sa.Column('content', sa.String(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('questions', | ||
sa.Column('id', sa.UUID(), nullable=False), | ||
sa.Column('type', sa.Enum(name='question_types'), nullable=False), | ||
sa.Column('question', sa.String(), nullable=False), | ||
sa.Column('correct_answer_id', sa.UUID(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('task_employees', | ||
sa.Column('task_id', sa.UUID(), nullable=False), | ||
sa.Column('employee_id', sa.UUID(), nullable=False), | ||
sa.Column('state', sa.Enum(name='task_states'), nullable=False), | ||
sa.ForeignKeyConstraint(['employee_id'], ['employees.id'], ), | ||
sa.ForeignKeyConstraint(['task_id'], ['tasks.id'], ), | ||
sa.PrimaryKeyConstraint('task_id', 'employee_id') | ||
) | ||
op.add_column('tasks', sa.Column('type', sa.Enum(name='task_types'), nullable=False)) | ||
op.add_column('tasks', sa.Column('requires_review', sa.Boolean(), nullable=False)) | ||
op.drop_column('tasks', 'content') | ||
op.drop_column('tasks', 'is_accomplished') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('tasks', sa.Column('is_accomplished', sa.BOOLEAN(), autoincrement=False, nullable=False)) | ||
op.add_column('tasks', sa.Column('content', sa.TEXT(), autoincrement=False, nullable=False)) | ||
op.drop_column('tasks', 'requires_review') | ||
op.drop_column('tasks', 'type') | ||
op.drop_table('task_employees') | ||
op.drop_table('questions') | ||
op.drop_table('answers') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import uuid | ||
import enum | ||
from typing import TYPE_CHECKING | ||
|
||
from sqlalchemy import UUID, Enum, String | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from database import BaseModel | ||
|
||
if TYPE_CHECKING: | ||
from game.units.tasks.models import TaskUnit | ||
|
||
|
||
class QuestionTypes(enum.Enum): | ||
SingleChoice = enum.auto() | ||
MultipleChoice = enum.auto() | ||
|
||
|
||
class Question(BaseModel): | ||
__tablename__ = 'questions' | ||
|
||
id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) | ||
type: Mapped[QuestionTypes] = mapped_column( | ||
Enum(name='question_types'), nullable=False, default=QuestionTypes.SingleChoice) | ||
question: Mapped[str] = mapped_column(String, nullable=False, default="Вопрос!") | ||
correct_answer_id: Mapped[uuid.UUID] = mapped_column(UUID, default=uuid.uuid4) | ||
|
||
task: Mapped["TaskUnit"] = relationship(back_populates='questions') | ||
possible_answers: Mapped[list["Answer"]] = relationship(back_populates='question') | ||
correct_answers: Mapped[list["Answer"]] = relationship(back_populates='question') | ||
|
||
|
||
class Answer(BaseModel): | ||
__tablename__ = 'answers' | ||
|
||
id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True, default=uuid.uuid4) | ||
question_id: Mapped[uuid.UUID] = mapped_column(UUID, default=uuid.uuid4) | ||
content: Mapped[str] = mapped_column(String, nullable=False, default='Ответ?') | ||
|
||
question: Mapped["Question"] = relationship(back_populates='answers') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import uuid | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel, ConfigDict | ||
|
||
from game.units.tasks.questions.models import QuestionTypes | ||
|
||
|
||
class __QuestionBase(BaseModel): | ||
type: QuestionTypes | ||
question: str | ||
possible_answers: list[str] | ||
|
||
model_config = ConfigDict(from_attributes=True) | ||
|
||
|
||
class TaskRead(__QuestionBase): | ||
id: UUID | ||
task_id: UUID | ||
|
||
|
||
class TaskCreate(__QuestionBase): | ||
correct_answers: list[str] | ||
task_id: UUID | ||
|
||
|
||
class TaskUpdate(__QuestionBase): | ||
question: str | None | ||
possible_answers: list[str] | None | ||
correct_answers: list[str] | None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters