mirror of https://github.com/zulip/zulip.git
ruff: Fix DJ012 Order of model's inner classes, methods, and fields.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
ab25ebd5ce
commit
e56863fa85
|
@ -135,54 +135,6 @@ class Message(AbstractMessage):
|
|||
|
||||
DEFAULT_SELECT_RELATED = ["sender", "realm", "recipient", "sending_client"]
|
||||
|
||||
def topic_name(self) -> str:
|
||||
"""
|
||||
Please start using this helper to facilitate an
|
||||
eventual switch over to a separate topic table.
|
||||
"""
|
||||
return self.subject
|
||||
|
||||
def set_topic_name(self, topic_name: str) -> None:
|
||||
self.subject = topic_name
|
||||
|
||||
def is_stream_message(self) -> bool:
|
||||
"""
|
||||
Find out whether a message is a stream message by
|
||||
looking up its recipient.type. TODO: Make this
|
||||
an easier operation by denormalizing the message
|
||||
type onto Message, either explicitly (message.type)
|
||||
or implicitly (message.stream_id is not None).
|
||||
"""
|
||||
return self.recipient.type == Recipient.STREAM
|
||||
|
||||
def get_realm(self) -> Realm:
|
||||
return self.realm
|
||||
|
||||
def save_rendered_content(self) -> None:
|
||||
self.save(update_fields=["rendered_content", "rendered_content_version"])
|
||||
|
||||
@staticmethod
|
||||
def need_to_render_content(
|
||||
rendered_content: Optional[str],
|
||||
rendered_content_version: Optional[int],
|
||||
markdown_version: int,
|
||||
) -> bool:
|
||||
return (
|
||||
rendered_content is None
|
||||
or rendered_content_version is None
|
||||
or rendered_content_version < markdown_version
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def is_status_message(content: str, rendered_content: str) -> bool:
|
||||
"""
|
||||
"status messages" start with /me and have special rendering:
|
||||
/me loves chocolate -> Full Name loves chocolate
|
||||
"""
|
||||
if content.startswith("/me "):
|
||||
return True
|
||||
return False
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
GinIndex("search_tsvector", fastupdate=False, name="zerver_message_search_tsvector"),
|
||||
|
@ -257,6 +209,54 @@ class Message(AbstractMessage):
|
|||
),
|
||||
]
|
||||
|
||||
def topic_name(self) -> str:
|
||||
"""
|
||||
Please start using this helper to facilitate an
|
||||
eventual switch over to a separate topic table.
|
||||
"""
|
||||
return self.subject
|
||||
|
||||
def set_topic_name(self, topic_name: str) -> None:
|
||||
self.subject = topic_name
|
||||
|
||||
def is_stream_message(self) -> bool:
|
||||
"""
|
||||
Find out whether a message is a stream message by
|
||||
looking up its recipient.type. TODO: Make this
|
||||
an easier operation by denormalizing the message
|
||||
type onto Message, either explicitly (message.type)
|
||||
or implicitly (message.stream_id is not None).
|
||||
"""
|
||||
return self.recipient.type == Recipient.STREAM
|
||||
|
||||
def get_realm(self) -> Realm:
|
||||
return self.realm
|
||||
|
||||
def save_rendered_content(self) -> None:
|
||||
self.save(update_fields=["rendered_content", "rendered_content_version"])
|
||||
|
||||
@staticmethod
|
||||
def need_to_render_content(
|
||||
rendered_content: Optional[str],
|
||||
rendered_content_version: Optional[int],
|
||||
markdown_version: int,
|
||||
) -> bool:
|
||||
return (
|
||||
rendered_content is None
|
||||
or rendered_content_version is None
|
||||
or rendered_content_version < markdown_version
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def is_status_message(content: str, rendered_content: str) -> bool:
|
||||
"""
|
||||
"status messages" start with /me and have special rendering:
|
||||
/me loves chocolate -> Full Name loves chocolate
|
||||
"""
|
||||
if content.startswith("/me "):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_context_for_message(message: Message) -> QuerySet[Message]:
|
||||
return Message.objects.filter(
|
||||
|
@ -364,6 +364,10 @@ class AbstractReaction(AbstractEmoji):
|
|||
class Reaction(AbstractReaction):
|
||||
message = models.ForeignKey(Message, on_delete=CASCADE)
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"{self.user_profile.email} / {self.message.id} / {self.emoji_name}"
|
||||
|
||||
@staticmethod
|
||||
def get_raw_db_rows(needed_ids: List[int]) -> List[Dict[str, Any]]:
|
||||
fields = [
|
||||
|
@ -380,10 +384,6 @@ class Reaction(AbstractReaction):
|
|||
# client-side sorting code.
|
||||
return Reaction.objects.filter(message_id__in=needed_ids).values(*fields).order_by("id")
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"{self.user_profile.email} / {self.message.id} / {self.emoji_name}"
|
||||
|
||||
|
||||
class ArchivedReaction(AbstractReaction):
|
||||
message = models.ForeignKey(ArchivedMessage, on_delete=CASCADE)
|
||||
|
|
|
@ -211,16 +211,6 @@ class RealmAuditLog(AbstractRealmAuditLog):
|
|||
)
|
||||
event_last_message_id = models.IntegerField(null=True)
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
if self.modified_user is not None:
|
||||
return f"{self.modified_user!r} {self.event_type} {self.event_time} {self.id}"
|
||||
if self.modified_stream is not None:
|
||||
return f"{self.modified_stream!r} {self.event_type} {self.event_time} {self.id}"
|
||||
if self.modified_user_group is not None:
|
||||
return f"{self.modified_user_group!r} {self.event_type} {self.event_time} {self.id}"
|
||||
return f"{self.realm!r} {self.event_type} {self.event_time} {self.id}"
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(
|
||||
|
@ -235,3 +225,13 @@ class RealmAuditLog(AbstractRealmAuditLog):
|
|||
),
|
||||
)
|
||||
]
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
if self.modified_user is not None:
|
||||
return f"{self.modified_user!r} {self.event_type} {self.event_time} {self.id}"
|
||||
if self.modified_stream is not None:
|
||||
return f"{self.modified_stream!r} {self.event_type} {self.event_time} {self.id}"
|
||||
if self.modified_user_group is not None:
|
||||
return f"{self.modified_user_group!r} {self.event_type} {self.event_time} {self.id}"
|
||||
return f"{self.realm!r} {self.event_type} {self.event_time} {self.id}"
|
||||
|
|
|
@ -579,6 +579,15 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):
|
|||
ROLE_GUEST: gettext_lazy("Guest"),
|
||||
}
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(Upper("email"), name="upper_userprofile_email_idx"),
|
||||
]
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"{self.email} {self.realm!r}"
|
||||
|
||||
def get_role_name(self) -> str:
|
||||
return str(self.ROLE_ID_TO_NAME_MAP[self.role])
|
||||
|
||||
|
@ -629,10 +638,6 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):
|
|||
else:
|
||||
return False
|
||||
|
||||
@override
|
||||
def __str__(self) -> str:
|
||||
return f"{self.email} {self.realm!r}"
|
||||
|
||||
@property
|
||||
def is_provisional_member(self) -> bool:
|
||||
if self.is_moderator:
|
||||
|
@ -843,11 +848,6 @@ class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):
|
|||
|
||||
super().set_password(password)
|
||||
|
||||
class Meta:
|
||||
indexes = [
|
||||
models.Index(Upper("email"), name="upper_userprofile_email_idx"),
|
||||
]
|
||||
|
||||
|
||||
class PasswordTooWeakError(Exception):
|
||||
pass
|
||||
|
|
Loading…
Reference in New Issue