|
| 1 | +from enum import Enum |
| 2 | +from typing import Optional |
| 3 | + |
| 4 | +from pydantic import ( |
| 5 | + BaseModel, |
| 6 | + EmailStr, |
| 7 | + Field, |
| 8 | + HttpUrl, |
| 9 | + field_validator, |
| 10 | + model_validator, |
| 11 | +) |
| 12 | + |
| 13 | + |
| 14 | +class SocialMedia(BaseModel): |
| 15 | + linkedIn: Optional[HttpUrl] = Field(None, title='LinkedIn Profile URL') |
| 16 | + facebook: Optional[HttpUrl] = Field(None, title='Facebook Profile URL') |
| 17 | + |
| 18 | + |
| 19 | +class TicketTypes(Enum): |
| 20 | + CODER = 'coder' |
| 21 | + KASOSYO = 'kasosyo' |
| 22 | + |
| 23 | + |
| 24 | +class TShirtType(Enum): |
| 25 | + UNISEX = 'unisex' |
| 26 | + FEMALE = 'female' |
| 27 | + |
| 28 | + |
| 29 | +class TShirtSize(Enum): |
| 30 | + XS = 'XS' |
| 31 | + S = 'S' |
| 32 | + M = 'M' |
| 33 | + L = 'L' |
| 34 | + XL = 'XL' |
| 35 | + XXL = 'XXL' |
| 36 | + XXXL = 'XXXL' |
| 37 | + |
| 38 | + |
| 39 | +class PyconRegistration(BaseModel): |
| 40 | + firstName: str = Field(title='First Name') |
| 41 | + lastName: str = Field(title='Last Name') |
| 42 | + nickname: str = Field(title='Nickname') |
| 43 | + pronouns: str = Field(title='Pronouns') |
| 44 | + email: EmailStr = Field(title='Email') |
| 45 | + contactNumber: str = Field(title='Contact Number', pattern=r'^\+?[1-9]\d{1,14}$') # international number |
| 46 | + organization: str = Field(title='Affiliated Company or Organization') |
| 47 | + jobTitle: str = Field(title='Job Title', description='Your current job title or role in tech') |
| 48 | + socials: Optional[SocialMedia] = Field( |
| 49 | + None, title='Social Media Profiles', description='Links to your social media profiles' |
| 50 | + ) |
| 51 | + ticketType: TicketTypes = Field(title='Ticket Type', description='Type of ticket you are registering for') |
| 52 | + sprintDay: bool = Field( |
| 53 | + False, title='Sprint Day Participation', description='Will you be participating in the sprint day?' |
| 54 | + ) |
| 55 | + availTShirt: bool = Field( |
| 56 | + False, title='T-Shirt Availability', description='Do you want to buy an exclusive PyCon T-shirt?' |
| 57 | + ) |
| 58 | + shirtType: Optional[TShirtType] = Field( |
| 59 | + None, title='T-Shirt Type', description='Type of the T-shirt you want to order' |
| 60 | + ) |
| 61 | + shirtSize: Optional[TShirtSize] = Field( |
| 62 | + None, title='T-Shirt Size', description='Size of the T-shirt you want to order' |
| 63 | + ) |
| 64 | + communityInvolvement: bool = Field( |
| 65 | + False, title='Community Involvement', description='Are you a member of any local tech community?' |
| 66 | + ) |
| 67 | + futureVolunteer: bool = Field( |
| 68 | + False, title='Future Volunteer Interest', description='Would you like to volunteer in the future?' |
| 69 | + ) |
| 70 | + dietaryRestrictions: str = Field( |
| 71 | + '', title='Dietary Restrictions', description='Any dietary restrictions or allergies' |
| 72 | + ) |
| 73 | + accessibilityNeeds: str = Field( |
| 74 | + '', title='Accessibility Needs', description='Any specific accessibility needs or requests' |
| 75 | + ) |
| 76 | + discountCode: Optional[str] = Field( |
| 77 | + None, title='Discount Code', description='If you have a discount code, please enter it here' |
| 78 | + ) |
| 79 | + imageId: Optional[str] = Field(None, title='Image ID Object Key') |
| 80 | + |
| 81 | + @field_validator('firstName', 'lastName', 'nickname') |
| 82 | + @classmethod |
| 83 | + def normalize_names(cls, v: str) -> str: |
| 84 | + if not v.strip(): |
| 85 | + raise ValueError('Name fields cannot be empty') |
| 86 | + return ' '.join(word.capitalize() for word in v.split()) |
| 87 | + |
| 88 | + @model_validator(mode='after') |
| 89 | + def check_shirt_availability(self): |
| 90 | + if self.availTShirt and (self.shirtType is None or self.shirtSize is None): |
| 91 | + raise ValueError('If availTShirt is True, then shirtType and shirtSize must be provided.') |
| 92 | + return self |
0 commit comments