コード例 #1
0
    class ModelIterPreIter(Model):
        Field1 = IntegerField("a")
        Field2 = IntegerField("b")

        def pre_iter(self):
            # noinspection PyAttributeOutsideInit
            self.field1 = 5
コード例 #2
0
class ChannelConfigModel(Model):
    WITH_OID = False

    # Votes needed to promote a member to be moderator
    VotePromoMod = IntegerField("v-m", default=ChannelConfig.VotesToPromoteMod)
    # Votes needed to promote a member to be admin
    VotePromoAdmin = IntegerField("v-a",
                                  default=ChannelConfig.VotesToPromoteAdmin)
    EnableAutoReply = BooleanField("e-ar", default=True)
    EnableTimer = BooleanField("e-tmr", default=True)
    EnableCalculator = BooleanField("e-calc", default=True)
    EnableBotCommand = BooleanField("e-bot", default=True)
    InfoPrivate = BooleanField("prv", default=False)
    DefaultProfileOid = ObjectIDField("d-prof", allow_none=True)
    DefaultName = TextField("d-name", allow_none=True)
コード例 #3
0
    class ModelOnInvalid(Model):
        Field1 = IntegerField("i")
        Field2 = BooleanField("b")

        def perform_validity_check(self) -> ModelValidityCheckResult:
            if self.field1 > 0:
                return ModelValidityCheckResult.X_UNCATEGORIZED
            else:
                return ModelValidityCheckResult.O_OK

        def on_invalid(self, reason=ModelValidityCheckResult.X_UNCATEGORIZED):
            raise TestBaseModel.TempInvalidException()
コード例 #4
0
class ChannelProfileModel(Model):
    # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    # !!! Check `ProfileManager.process_create_profile_kwargs` when changing the variable name of this class. !!!
    # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    ChannelOid = ObjectIDField("c", default=ModelDefaultValueExt.Required)
    Name = TextField("n", default="-", must_have_content=True)
    Color = ColorField("col")
    # 0 means no need to vote, > 0 means # votes needed to get this profile
    PromoVote = IntegerField("promo", positive_only=True)
    Permission = DictionaryField(
        "perm",
        default=ProfilePermissionDefault.get_default_code_str_dict(),
        allow_none=False)
    PermissionLevel = PermissionLevelField("plv")

    EmailKeyword = ArrayField("e-kw", str)

    @property
    def is_mod(self):
        return self.permission_level >= PermissionLevel.MOD

    @property
    def is_admin(self):
        return self.permission_level >= PermissionLevel.ADMIN

    @property
    def permission_list(self) -> List[ProfilePermission]:
        ret = set()

        for cat, permitted in self.permission.items():
            if permitted:
                perm = ProfilePermission.cast(cat, silent_fail=True)
                if perm:
                    ret.add(perm)

        ret = ret.union(
            ProfilePermissionDefault.get_overridden_permissions(
                self.permission_level))

        return list(sorted(ret, key=lambda x: x.code))

    def pre_iter(self):
        # Will be used when the data will be passed to MongoDB
        d = [
            p.code_str
            for p in ProfilePermissionDefault.get_overridden_permissions(
                self.permission_level)
        ]

        for perm_cat in ProfilePermission:
            k = perm_cat.code_str
            if k not in self.permission:
                self.permission[k] = k in d
コード例 #5
0
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")
コード例 #6
0
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)
コード例 #7
0
 class ModelHasOid(Model):
     Field1 = IntegerField("i")
コード例 #8
0
 class ModelIterNoPreIter(Model):
     Field1 = IntegerField("a")
     Field2 = IntegerField("b")
コード例 #9
0
 class DuplicateJsonModel(Model):
     Field1 = IntegerField("i")
     Field2 = BooleanField("i")
コード例 #10
0
 class TestModel(Model):
     Field1 = IntegerField("f1")
     Field2 = IntegerField("f2", default=ModelDefaultValueExt.Required)
     Field3 = IntegerField("f3", default=ModelDefaultValueExt.Optional)
     Field4 = IntegerField("f4", default=5)
コード例 #11
0
ファイル: int.py プロジェクト: stefaneutu/Jelly-Bot
 def get_field(self) -> BaseField:
     return IntegerField("k")
コード例 #12
0
class SubModel(Model):
    WITH_OID = False

    FInt = IntegerField("i2", default=8)
コード例 #13
0
ファイル: int.py プロジェクト: stefaneutu/Jelly-Bot
 def get_field(self) -> BaseField:
     return IntegerField("k", allow_none=True)
コード例 #14
0
ファイル: int.py プロジェクト: stefaneutu/Jelly-Bot
 def get_field(self) -> BaseField:
     return IntegerField("k", auto_cast=False)
コード例 #15
0
    class ModelNoOid(Model):
        WITH_OID = False

        Field1 = IntegerField("i")
コード例 #16
0
class ModelTest2(Model):
    Field1 = IntegerField("f1")
    Field2 = BooleanField("f2")
コード例 #17
0
ファイル: int.py プロジェクト: stefaneutu/Jelly-Bot
 def get_field(self) -> BaseField:
     return IntegerField("k", positive_only=True)