class Client(Model): name: str = Field(title="Client's full name.", min_length=10, max_length=100) address: Optional[str] = Field(title="Client's full address.", min_length=10, max_length=150) state: Optional[State] = Field(title="Client's state.") cpf: Optional[str] = Field( title="Client's full name.", min_length=14, max_length=14, regex=r'([0-9]{3}[\.]?[0-9]{3}[\.]?[0-9]{3}[-]?[0-9]{2})') age: int = Field(title="Client's age.", gt=14, lt=100) user: Optional[User] def update_fields(self, model: Model): values = model.dict(exclude={'id'}, exclude_unset=True, exclude_none=True) for key in values: setattr(self, key, values[key])
class ContactDetails(EmbeddedModel): """contact_details embedded model document.""" name: Name birthdate: Optional[str] = Field(regex=util_regex.DATE) phone: Optional[List[str]] = Field(regex=util_regex.PHONE_NUMBER) email: Optional[str] = Field(regex=util_regex.TEXT) address: Optional[Address] locale: Optional[str] = Field(regex=util_regex.LOCALE)
class User(Model, ABC): id: int = Field(..., primary_field=True) language: str = 'en' last_seen: dt = Field(default_factory=dt.now) personal_details: PersonalDetails saved_stops: List[SavedStop] = Field(default_factory=list) def is_stop_already_saved(self, stop_code: int) -> bool: return any( [stop for stop in self.saved_stops if stop.code == stop_code])
class User(Model): name: str password: str email: EmailStr is_active: Optional[bool] = Field(default=True) is_admin: Optional[bool] = Field(default=False) is_verified: Optional[bool] = Field(default=False) email_validation: Optional[EmailValidation] = None forgot_password: Optional[ForgotPassword] = None created_at: datetime = Field(default=datetime.utcnow()) email_delay: Optional[datetime] = Field(default=datetime.utcnow() + settings.SEND_EMAIL_DELAY_TIME)
class ExampleModel(Model): small_int: int = Field(le=10) big_int: int = Field(gt=1000) even_int: int = Field(multiple_of=2) small_float: float = Field(lt=10) big_float: float = Field(ge=1e10) short_string: str = Field(max_length=10) long_string: str = Field(min_length=100) string_starting_with_the: str = Field(regex=r"^The") short_str_list: List[str] = Field(max_items=5) long_str_list: List[str] = Field(min_items=15)
class User(Model): """user model document.""" id: str = Field( primary_field=True, regex=util_regex.USER_ID, description="username", ) created_datetime: datetime.datetime = Field( default_factory=datetime.datetime.utcnow, ) updated_datetime: datetime.datetime = Field( default_factory=datetime.datetime.utcnow, ) password: str roles: List[UserRoleChoices] name: str = Field(regex=util_regex.TEXT) email: Optional[str] = Field(regex=util_regex.TEXT) disabled: bool = False
class Food(Model, ABC): name: str expire_days: int = Field(ge=0) created: int active: bool food_type: Optional[str] freezer: Optional[bool] = False pantry: Optional[bool] = False shopping_list: Optional[bool] = False
class ViewModel(Model): class Config: collection = "views" id: int = Field(primary_field=True) type: str guild_id: Optional[int] channel_id: Optional[int] data: Dict[str, Any]
class Address(EmbeddedModel): """address embedded model document.""" street: Optional[str] = Field(regex=util_regex.TEXT) number: Optional[str] = Field(regex=util_regex.TEXT) municipality: Optional[str] = Field(regex=util_regex.TEXT) region: Optional[str] = Field(regex=util_regex.TEXT) province: Optional[str] = Field(regex=util_regex.TEXT) postal_code: Optional[str] = Field(regex=util_regex.TEXT) country: Optional[str] = Field(regex=util_regex.TEXT)
class Graph(Model): # open issue on odmantic repo for sets # https://github.com/art049/odmantic/issues/11 # TODO: change when resolved nodes: List[str] # FrozenSet[str] = frozenset() edges: List[Edge] profit: Optional[float] exchange: Optional[str] currency: Optional[str] # data: dict cycle: Optional[dict] timestamp: int = Field(default_factory=default_ts)
class User(Model): login: str = Field(title="User's login.", min_length=4, max_length=20) password1: str = Field( title="User's password.", min_length=8, max_length=20, regex=r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])') password2: Optional[str] = Field( title="User's password.", min_length=8, max_length=20, regex=r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])') @validator('password2') def passwords_match(cls, v, values, **kwargs): if 'password1' in values and v == values['password1']: return v else: raise ValueError('passwords do not match')
class User(Model, ABC): user_id: int personal_info: UserInfo = Field(default_factory=UserInfo) language: Optional[str] = None location_list: List[Location] = Field(default_factory=list) cl_offset: int = 18 havdala_opinion: str = 'tzeis_8_5_degrees' zmanim_settings: ZmanimSettings = Field(default_factory=ZmanimSettings) processor_type: str = 'image' omer: OmerSettings = Field(default_factory=OmerSettings) class Config: collection = config.DB_COLLECTION_NAME @property def location(self) -> Location: loc = list(filter(lambda l: l.is_active, self.location_list)) if not loc: raise NoLocationException return loc[0] def get_location_by_coords(self, lat: float, lng: float) -> Location: resp = list( filter(lambda loc: loc.lat == lat and loc.lng == lng, self.location_list)) if not resp: raise NoLocationException return resp[0] def get_processor(self, location: Optional[Location] = None) -> BaseProcessor: try: return PROCESSORS[self.processor_type]((location and location.name) or self.location.name) except KeyError: raise UnknownProcessorException()
class Publisher(Model): name: str founded: int = Field(ge=1440) location: Optional[str] = None
class Suscripcion(EmbeddedModel): tipo: TipoSuscripcion fecha_ini: datetime fecha_fin: Optional[datetime] = Field(None)
class Player(Model): """This model has a custom primary key""" name: str = Field(primary_field=True) level: int = Field(default=1, ge=1)
class Player(Model): name: str level: int = Field(default=1, ge=1)
class ConfiguracionEstablecimiento(EmbeddedModel): max_aforo: int = 10 margen_aforo: int = Field(8) max_ppm: int = 1000 margen_ppm: int = Field(900)
class Name(EmbeddedModel): """name embedded model document.""" first_name: str = Field(regex=util_regex.TEXT) surname_1: str = Field(regex=util_regex.TEXT) surname_2: Optional[str] = Field(regex=util_regex.TEXT)
class GuildModel(Model): class Config: collection = "guilds" id: int = Field(primary_field=True) prefix: Optional[List[str]]
class Player(Model): name: str = Field(primary_field=True)
class User(Model): name: str = Field(key_name="username")
class Recipe(Model): name: str portions: int = Field(ge=1) owner: Optional[str] = None continent: Optional[str] = None