class RemoteControlEntryModel(Model): UserOid = ObjectIDField("uid", default=ModelDefaultValueExt.Required, stores_uid=True) LocaleCode = TextField("loc", default="Asia/Taipei") SourceChannelOid = ObjectIDField("src", default=ModelDefaultValueExt.Required) TargetChannelOid = ObjectIDField("dst", default=ModelDefaultValueExt.Required) ExpiryUtc = DateTimeField("exp", default=ModelDefaultValueExt.Required) @property def expiry(self): tzinfo = LocaleInfo.get_tzinfo(self.locale_code) return localtime(self.expiry_utc, tzinfo) @property def target_channel(self): from mongodb.factory import ChannelManager return ChannelManager.get_channel_oid(self.target_channel_oid) @property def expiry_str(self) -> str: return self.expiry.strftime("%Y-%m-%d %H:%M:%S (UTC%Z)")
class MessageRecordModel(Model): ChannelOid = ObjectIDField("ch", default=ModelDefaultValueExt.Required) UserRootOid = ObjectIDField("u", default=ModelDefaultValueExt.Required, stores_uid=True) MessageType = MessageTypeField("t", default=ModelDefaultValueExt.Required) MessageContent = TextField("ct", default=ModelDefaultValueExt.Required) ProcessTimeSecs = FloatField("pt", default=ModelDefaultValueExt.Optional) Timestamp = DateTimeField("ts")
class TimerModel(Model): ChannelOid = ObjectIDField("ch", default=ModelDefaultValueExt.Required) Keyword = TextField("k", default=ModelDefaultValueExt.Required) Title = TextField("t", default=ModelDefaultValueExt.Required) TargetTime = DateTimeField("tt", default=ModelDefaultValueExt.Required) DeletionTime = DateTimeField("del", default=ModelDefaultValueExt.Optional) Countup = BooleanField("c", default=False) PeriodSeconds = IntegerField("p") Notified = BooleanField("nt", default=False) NotifiedExpired = BooleanField("nt-e", default=False) @property def is_periodic(self) -> bool: return self.period_seconds > 0 def get_target_time_diff(self, dt: datetime): return abs(self.target_time - make_tz_aware(dt)) def is_after(self, dt: datetime) -> bool: """Check if the target time of the timer is after the given ``dt``.""" return self.target_time >= make_tz_aware(dt)
class ExtraContentModel(Model): Type = ExtraContentTypeField("tp") Title = TextField("t", default=ModelDefaultValueExt.Optional) Content = GeneralField("c", default=ModelDefaultValueExt.Required) Timestamp = DateTimeField("e", default=ModelDefaultValueExt.Required) ChannelOid = ObjectIDField("ch", default=ModelDefaultValueExt.Optional) @property def expires_on(self): return self.timestamp + timedelta( seconds=Database.ExtraContentExpirySeconds) @property def content_html(self) -> str: return ExtraContentHTMLTransformer.transform(self)
class ModelTest(Model): FModel = ModelField("m", SubModel) FInt = IntegerField("i", default=ModelDefaultValueExt.Required) FModelArray = ModelArrayField("ma", SubModel, default=ModelDefaultValueExt.Optional) FDict = DictionaryField("d") FFloat = FloatField("f", default=7.5) FBool = BooleanField("b") FUrl = UrlField("u", default=ModelDefaultValueExt.Optional) FText = TextField("t") FOid = ObjectIDField("o") FGeneral = GeneralField("g") FDatetime = DateTimeField("dt") FColor = ColorField("c") FArray = ArrayField("a", int, default=[17, 21]) FArContent = AutoReplyContentTypeField("ac")
class APIStatisticModel(Model): Timestamp = DateTimeField("t", default=ModelDefaultValueExt.Required, allow_none=False) SenderOid = ObjectIDField("sd", default=ModelDefaultValueExt.Optional, allow_none=True, stores_uid=True) ApiAction = APICommandField("a") Parameter = DictionaryField("p", allow_none=True) PathParameter = DictionaryField("pp", allow_none=True) Response = DictionaryField("r", allow_none=True) Success = BooleanField("s", allow_none=True) PathInfo = TextField("pi", default=ModelDefaultValueExt.Required, must_have_content=True, allow_none=False) PathInfoFull = TextField("pf", default=ModelDefaultValueExt.Required, must_have_content=True, allow_none=False)
def test_repair_dt(self): self.missing_has_default("dt", {"dt": DateTimeField.none_obj()})
def get_field(self) -> BaseField: return DateTimeField("k", auto_cast=False)
def get_field(self) -> BaseField: return DateTimeField("k")
def get_field(self) -> BaseField: return DateTimeField("k", allow_none=True)