class WarningCV(TimestampMixin, Model): frame = fields.TextField(null=True) duration = fields.TimeDeltaField() report: fields.ForeignKeyRelation[Report] = fields.ForeignKeyField('models.Report', related_name='warnings') type_warning = fields.SmallIntField(default=1) class Meta: table = 'warning'
class Report(Model): time_duration = fields.TimeDeltaField(default=timedelta(seconds=0)) video_web = fields.TextField() video_screen = fields.TextField() trust_point = fields.IntField(default=100) session: fields.ForeignKeyRelation[Session] = fields.ForeignKeyField('models.Session', related_name='reports') student: fields.ForeignKeyRelation[Student] = fields.ForeignKeyField('models.Student', related_name='reports') warnings: fields.ReverseRelation["WarningCV"]
class SomeModel(Model): id = fields.IntField(pk=True) string = fields.CharField(255, null=True) decimal = fields.DecimalField(20, 10, null=True) enum = fields.CharEnumField(SomeEnum, null=True) reversed_enum = ReversedCharEnumField(SomeReversedEnum, null=True) date = fields.DateField(null=True) datetime = fields.DatetimeField(null=True) timedelta = fields.TimeDeltaField(null=True) bool = fields.BooleanField(null=True) relation = fields.ForeignKeyField('models.SomeModel', 'id', null=True) class Meta: # pylint: disable=too-few-public-methods) table = 'test_models'
class TimeDeltaFields(Model): id = fields.IntField(pk=True) timedelta = fields.TimeDeltaField() timedelta_null = fields.TimeDeltaField(null=True)
class BotList(Model): votes: fields.ReverseRelation["Vote"] # **Generic Data** key = fields.CharField( help_text="The unique key to recognise the bot list", max_length=50, pk=True) name = fields.CharField(help_text="Name of the bot list", max_length=128) bot_url = fields.TextField(help_text="URL for the main bot page") notes = fields.TextField(help_text="Informations about this bot list", blank=True) auth = fields.TextField( help_text="Token used to authenticate requests to/from the bot") # **Votes** can_vote = fields.BooleanField( help_text="Can people vote (more than once) on that list ?", default=True) vote_url = fields.TextField(help_text="URL for an user to vote") vote_every = fields.TimeDeltaField(help_text="How often can users vote ?", null=True) check_vote_url = fields.TextField( help_text="URL the bot can use to check if an user voted recently") check_vote_key = fields.CharField( help_text="Key in the returned JSON to check for presence of vote", default="voted", max_length=128) check_vote_negate = fields.BooleanField( help_text= "Does the boolean says if the user has voted (True) or if they can vote (False) ?", default=True) webhook_handler = fields.CharField( help_text= "What is the function that'll receive the request from the vote hooks", choices=(("generic", "generic"), ("top.gg", "top.gg"), ("None", "None")), default="generic", max_length=20) webhook_authorization_header = fields.CharField( help_text="Name of the header used to authenticate webhooks requests", default="Authorization", max_length=20) webhook_user_id_json_field = fields.CharField( help_text="Key that gives the user ID in the provided JSON", default="id", max_length=20) webhook_auth = fields.TextField( help_text= "Secret used for authentication of the webhooks messages if not the same the auth token", blank=True) # **Statistics** post_stats_method = fields.CharField( help_text="What HTTP method should be used to send the stats", choices=(("POST", "POST"), ("PATCH", "PATCH"), ("None", "None")), default="POST", max_length=10) post_stats_url = fields.TextField( help_text="Endpoint that will receive statistics") post_stats_server_count_key = fields.CharField( help_text="Name of the server count key in the statistics JSON", default="server_count", blank=True, max_length=128) post_stats_shard_count_key = fields.CharField( help_text="Name of the shard count key in the statistics JSON", default="shard_count", blank=True, max_length=128) # **Others** bot_verified = fields.BooleanField( help_text="Whether the bot was verified by the bot list staff", default=False) bot_certified = fields.BooleanField( help_text="Whether the bot was certified on that bot list", default=False) embed_code = fields.TextField( help_text= "Code to show this bot list embed. This HTML won't be escaped.", blank=True)
class TimeDeltaFields(Model): id = fields.IntegerField(primary_key=True) timedelta = fields.TimeDeltaField() timedelta_null = fields.TimeDeltaField(null=True)
class ModeratorEvent(Model): id_ = fields.IntField(pk=True, source_field="id") moderator: fields.ForeignKeyRelation[User] = fields.ForeignKeyField( 'models.User', related_name='my_moderator_events') user: fields.ForeignKeyRelation[User] = fields.ForeignKeyField( 'models.User', related_name='my_restriction_events') chat: fields.ForeignKeyRelation[Chat] = fields.ForeignKeyField( 'models.Chat', related_name='moderator_events') date = fields.DatetimeField(auto_now=True, null=False) type_restriction = fields.CharField(max_length=20) timedelta_restriction = fields.TimeDeltaField(null=True) comment = fields.TextField(null=True) class Meta: table = 'moderator_events' def __repr__(self): # noinspection PyUnresolvedReferences return ( f"ModeratorEvent {self.id_} from moderator {self.moderator_id} to {self.user_id}, date {self.date}, " f"type_restriction {self.type_restriction} timedelta_restriction {self.timedelta_restriction}" ) @classmethod async def save_new_action( cls, moderator: User, user: User, chat: Chat, type_restriction: str, duration: timedelta = None, comment: str = "", using_db=None, ): moderator_event = ModeratorEvent(moderator=moderator, user=user, chat=chat, type_restriction=type_restriction, timedelta_restriction=duration, comment=comment) await moderator_event.save(using_db=using_db) return moderator_event @classmethod async def get_last_by_user(cls, user: User, chat: Chat, limit: int = 10): return await cls.filter(user=user, chat=chat).order_by('-date').limit( limit).prefetch_related('moderator').all() def format_event(self) -> str: rez = f"{self.date.date().strftime(config.DATE_FORMAT)} {self.type_restriction} " if self.timedelta_restriction: rez += f"{format_timedelta(self.timedelta_restriction)} " rez += f"от {self.moderator.mention_no_link}" if self.comment: rez += f" \"{quote_html(self.comment)}\"" return rez __str__ = format_event