Activity system #3
@ -1,5 +1,5 @@
|
|||||||
from typing import Literal, Self, Annotated
|
from typing import Literal, Self
|
||||||
from pydantic import model_validator, Field
|
from pydantic import model_validator
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@ -11,14 +11,9 @@ from fiber_package.refs import SignupRefList
|
|||||||
from fiber_package.signup.signup import SignupModel
|
from fiber_package.signup.signup import SignupModel
|
||||||
from fiber_package.signup.util import validate_answer
|
from fiber_package.signup.util import validate_answer
|
||||||
|
|
||||||
from fiber_package.signup.element.form_base_text import FormBaseText
|
|
||||||
from fiber_package.signup.element.form_base_question import FormBaseQuestion
|
from fiber_package.signup.element.form_base_question import FormBaseQuestion
|
||||||
|
|
||||||
# Special type which uses enum category to decide type!
|
from fiber_package.signup.element.types import FormElementUnion, FormTextUnion
|
||||||
FieldUnionType = Annotated[
|
|
||||||
FormBaseText | FormBaseQuestion,
|
|
||||||
Field(discriminator="category")
|
|
||||||
]
|
|
||||||
|
|
||||||
class ActivityModel(CommunicationModel):
|
class ActivityModel(CommunicationModel):
|
||||||
category: Literal[CommunicationCategory.activity]
|
category: Literal[CommunicationCategory.activity]
|
||||||
@ -31,7 +26,7 @@ class ActivityModel(CommunicationModel):
|
|||||||
|
|
||||||
payment_info: ActivityPaymentInfo | None = None
|
payment_info: ActivityPaymentInfo | None = None
|
||||||
|
|
||||||
form: list[FieldUnionType]
|
form: list[FormElementUnion]
|
||||||
|
|
||||||
signups: SignupRefList = SignupRefList([], "signup")
|
signups: SignupRefList = SignupRefList([], "signup")
|
||||||
|
|
||||||
@ -51,7 +46,7 @@ class ActivityModel(CommunicationModel):
|
|||||||
question_dict: dict[str, FormBaseQuestion] = {}
|
question_dict: dict[str, FormBaseQuestion] = {}
|
||||||
|
|
||||||
for element in self.form:
|
for element in self.form:
|
||||||
if isinstance(element, FormBaseText):
|
if isinstance(element, FormTextUnion):
|
||||||
continue
|
continue
|
||||||
# so we know it is istance of FormBaseQuestion
|
# so we know it is istance of FormBaseQuestion
|
||||||
answerable.add(element.name)
|
answerable.add(element.name)
|
||||||
|
|||||||
10
src/fiber_package/signup/answer/types.py
Normal file
10
src/fiber_package/signup/answer/types.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
from pydantic import Field
|
||||||
|
|
||||||
|
from .answer_open_questions import AnswerOpenQuestions
|
||||||
|
|
||||||
|
AnswerUnion = Annotated[
|
||||||
|
AnswerOpenQuestions,
|
||||||
|
Field(discriminator="category")
|
||||||
|
]
|
||||||
22
src/fiber_package/signup/element/types.py
Normal file
22
src/fiber_package/signup/element/types.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
from pydantic import Field
|
||||||
|
|
||||||
|
from .form_open_questions import FormOpenQuestions
|
||||||
|
from .form_text import FormText
|
||||||
|
from .form_title import FormTitle
|
||||||
|
|
||||||
|
FormTextUnion = Annotated[
|
||||||
|
FormText | FormTitle,
|
||||||
|
Field(discriminator="category")
|
||||||
|
]
|
||||||
|
|
||||||
|
FormQuestionUnion = Annotated[
|
||||||
|
FormOpenQuestions,
|
||||||
|
Field(discriminator="category")
|
||||||
|
]
|
||||||
|
|
||||||
|
FormElementUnion = Annotated[
|
||||||
|
FormTextUnion | FormQuestionUnion,
|
||||||
|
Field(discriminator="category")
|
||||||
|
]
|
||||||
@ -3,7 +3,7 @@ from typing import Literal
|
|||||||
from fiber_package.base import FiberBaseModel
|
from fiber_package.base import FiberBaseModel
|
||||||
from fiber_package.refs import EntityRef, ActivityRef
|
from fiber_package.refs import EntityRef, ActivityRef
|
||||||
|
|
||||||
from fiber_package.signup.answer.answer_base import AnswerBase
|
from fiber_package.signup.answer.types import AnswerUnion
|
||||||
|
|
||||||
class SignupModel(FiberBaseModel):
|
class SignupModel(FiberBaseModel):
|
||||||
collection_name: Literal["signup"] = "signup"
|
collection_name: Literal["signup"] = "signup"
|
||||||
@ -11,6 +11,6 @@ class SignupModel(FiberBaseModel):
|
|||||||
attendee: EntityRef
|
attendee: EntityRef
|
||||||
activity: ActivityRef
|
activity: ActivityRef
|
||||||
|
|
||||||
answers: list[AnswerBase]
|
answers: list[AnswerUnion]
|
||||||
|
|
||||||
# TODO: signed_up, is_reserve, payment, confirmed, ....
|
# TODO: signed_up, is_reserve, payment, confirmed, ....
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user