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
cdaf12da44
commit
0a3dc8a944
|
@ -186,12 +186,12 @@ class Confirmation(models.Model):
|
||||||
REALM_REACTIVATION = 8
|
REALM_REACTIVATION = 8
|
||||||
type = models.PositiveSmallIntegerField()
|
type = models.PositiveSmallIntegerField()
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return f"{self.content_object!r}"
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("type", "confirmation_key")
|
unique_together = ("type", "confirmation_key")
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.content_object!r}"
|
||||||
|
|
||||||
|
|
||||||
class ConfirmationType:
|
class ConfirmationType:
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
|
@ -28,6 +28,9 @@ class Customer(models.Model):
|
||||||
# they purchased.
|
# they purchased.
|
||||||
exempt_from_from_license_number_check = models.BooleanField(default=False)
|
exempt_from_from_license_number_check = models.BooleanField(default=False)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.realm!r} {self.stripe_customer_id}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_self_hosted(self) -> bool:
|
def is_self_hosted(self) -> bool:
|
||||||
is_self_hosted = self.remote_server is not None
|
is_self_hosted = self.remote_server is not None
|
||||||
|
@ -42,9 +45,6 @@ class Customer(models.Model):
|
||||||
assert self.remote_server is None
|
assert self.remote_server is None
|
||||||
return is_cloud
|
return is_cloud
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return f"{self.realm!r} {self.stripe_customer_id}"
|
|
||||||
|
|
||||||
|
|
||||||
def get_customer_by_realm(realm: Realm) -> Optional[Customer]:
|
def get_customer_by_realm(realm: Realm) -> Optional[Customer]:
|
||||||
return Customer.objects.filter(realm=realm).first()
|
return Customer.objects.filter(realm=realm).first()
|
||||||
|
|
|
@ -692,14 +692,6 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_giphy_rating_options(self) -> Dict[str, Dict[str, object]]:
|
|
||||||
"""Wrapper function for GIPHY_RATING_OPTIONS that ensures evaluation
|
|
||||||
of the lazily evaluated `name` field without modifying the original."""
|
|
||||||
return {
|
|
||||||
rating_type: {"name": str(rating["name"]), "id": rating["id"]}
|
|
||||||
for rating_type, rating in self.GIPHY_RATING_OPTIONS.items()
|
|
||||||
}
|
|
||||||
|
|
||||||
# maximum rating of the GIFs that will be retrieved from GIPHY
|
# maximum rating of the GIFs that will be retrieved from GIPHY
|
||||||
giphy_rating = models.PositiveSmallIntegerField(default=GIPHY_RATING_OPTIONS["g"]["id"])
|
giphy_rating = models.PositiveSmallIntegerField(default=GIPHY_RATING_OPTIONS["g"]["id"])
|
||||||
|
|
||||||
|
@ -793,6 +785,17 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
|
||||||
)
|
)
|
||||||
night_logo_version = models.PositiveSmallIntegerField(default=1)
|
night_logo_version = models.PositiveSmallIntegerField(default=1)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.string_id} {self.id}"
|
||||||
|
|
||||||
|
def get_giphy_rating_options(self) -> Dict[str, Dict[str, object]]:
|
||||||
|
"""Wrapper function for GIPHY_RATING_OPTIONS that ensures evaluation
|
||||||
|
of the lazily evaluated `name` field without modifying the original."""
|
||||||
|
return {
|
||||||
|
rating_type: {"name": str(rating["name"]), "id": rating["id"]}
|
||||||
|
for rating_type, rating in self.GIPHY_RATING_OPTIONS.items()
|
||||||
|
}
|
||||||
|
|
||||||
def authentication_methods_dict(self) -> Dict[str, bool]:
|
def authentication_methods_dict(self) -> Dict[str, bool]:
|
||||||
"""Returns the mapping from authentication flags to their status,
|
"""Returns the mapping from authentication flags to their status,
|
||||||
showing only those authentication flags that are supported on
|
showing only those authentication flags that are supported on
|
||||||
|
@ -813,9 +816,6 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
|
||||||
ret[k] = v
|
ret[k] = v
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return f"{self.string_id} {self.id}"
|
|
||||||
|
|
||||||
# `realm` instead of `self` here to make sure the parameters of the cache key
|
# `realm` instead of `self` here to make sure the parameters of the cache key
|
||||||
# function matches the original method.
|
# function matches the original method.
|
||||||
@cache_with_key(get_realm_emoji_cache_key, timeout=3600 * 24 * 7)
|
@cache_with_key(get_realm_emoji_cache_key, timeout=3600 * 24 * 7)
|
||||||
|
@ -1125,9 +1125,6 @@ class RealmEmoji(models.Model):
|
||||||
PATH_ID_TEMPLATE = "{realm_id}/emoji/images/{emoji_file_name}"
|
PATH_ID_TEMPLATE = "{realm_id}/emoji/images/{emoji_file_name}"
|
||||||
STILL_PATH_ID_TEMPLATE = "{realm_id}/emoji/images/still/{emoji_filename_without_extension}.png"
|
STILL_PATH_ID_TEMPLATE = "{realm_id}/emoji/images/still/{emoji_filename_without_extension}.png"
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return f"{self.realm.string_id}: {self.id} {self.name} {self.deactivated} {self.file_name}"
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
constraints = [
|
constraints = [
|
||||||
models.UniqueConstraint(
|
models.UniqueConstraint(
|
||||||
|
@ -1137,6 +1134,9 @@ class RealmEmoji(models.Model):
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.realm.string_id}: {self.id} {self.name} {self.deactivated} {self.file_name}"
|
||||||
|
|
||||||
|
|
||||||
def get_realm_emoji_dicts(realm: Realm, only_active_emojis: bool = False) -> Dict[str, EmojiInfo]:
|
def get_realm_emoji_dicts(realm: Realm, only_active_emojis: bool = False) -> Dict[str, EmojiInfo]:
|
||||||
# RealmEmoji objects with file_name=None are still in the process
|
# RealmEmoji objects with file_name=None are still in the process
|
||||||
|
@ -1286,6 +1286,9 @@ class RealmFilter(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("realm", "pattern")
|
unique_together = ("realm", "pattern")
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.realm.string_id}: {self.pattern} {self.url_format_string}"
|
||||||
|
|
||||||
def clean(self) -> None:
|
def clean(self) -> None:
|
||||||
"""Validate whether the set of parameters in the URL Format string
|
"""Validate whether the set of parameters in the URL Format string
|
||||||
match the set of parameters in the regular expression.
|
match the set of parameters in the regular expression.
|
||||||
|
@ -1328,9 +1331,6 @@ class RealmFilter(models.Model):
|
||||||
params={"name": name},
|
params={"name": name},
|
||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return f"{self.realm.string_id}: {self.pattern} {self.url_format_string}"
|
|
||||||
|
|
||||||
|
|
||||||
def get_linkifiers_cache_key(realm_id: int) -> str:
|
def get_linkifiers_cache_key(realm_id: int) -> str:
|
||||||
return f"{cache.KEY_PREFIX}:all_linkifiers_for_realm:{realm_id}"
|
return f"{cache.KEY_PREFIX}:all_linkifiers_for_realm:{realm_id}"
|
||||||
|
@ -1486,14 +1486,14 @@ class Recipient(models.Model):
|
||||||
# N.B. If we used Django's choice=... we would get this for free (kinda)
|
# N.B. If we used Django's choice=... we would get this for free (kinda)
|
||||||
_type_names = {PERSONAL: "personal", STREAM: "stream", HUDDLE: "huddle"}
|
_type_names = {PERSONAL: "personal", STREAM: "stream", HUDDLE: "huddle"}
|
||||||
|
|
||||||
def type_name(self) -> str:
|
|
||||||
# Raises KeyError if invalid
|
|
||||||
return self._type_names[self.type]
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
display_recipient = get_display_recipient(self)
|
display_recipient = get_display_recipient(self)
|
||||||
return f"{display_recipient} ({self.type_id}, {self.type})"
|
return f"{display_recipient} ({self.type_id}, {self.type})"
|
||||||
|
|
||||||
|
def type_name(self) -> str:
|
||||||
|
# Raises KeyError if invalid
|
||||||
|
return self._type_names[self.type]
|
||||||
|
|
||||||
|
|
||||||
class UserBaseSettings(models.Model):
|
class UserBaseSettings(models.Model):
|
||||||
"""This abstract class is the container for all preferences/personal
|
"""This abstract class is the container for all preferences/personal
|
||||||
|
@ -2623,6 +2623,11 @@ class Stream(models.Model):
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
indexes = [
|
||||||
|
models.Index(Upper("name"), name="upper_stream_name_idx"),
|
||||||
|
]
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@ -2680,11 +2685,6 @@ class Stream(models.Model):
|
||||||
is_announcement_only=self.stream_post_policy == Stream.STREAM_POST_POLICY_ADMINS,
|
is_announcement_only=self.stream_post_policy == Stream.STREAM_POST_POLICY_ADMINS,
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
|
||||||
indexes = [
|
|
||||||
models.Index(Upper("name"), name="upper_stream_name_idx"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
post_save.connect(flush_stream, sender=Stream)
|
post_save.connect(flush_stream, sender=Stream)
|
||||||
post_delete.connect(flush_stream, sender=Stream)
|
post_delete.connect(flush_stream, sender=Stream)
|
||||||
|
@ -4115,12 +4115,6 @@ class UserPresence(models.Model):
|
||||||
https://zulip.readthedocs.io/en/latest/subsystems/presence.html
|
https://zulip.readthedocs.io/en/latest/subsystems/presence.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Meta:
|
|
||||||
unique_together = ("user_profile", "client")
|
|
||||||
index_together = [
|
|
||||||
("realm", "timestamp"),
|
|
||||||
]
|
|
||||||
|
|
||||||
user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE)
|
user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE)
|
||||||
realm = models.ForeignKey(Realm, on_delete=CASCADE)
|
realm = models.ForeignKey(Realm, on_delete=CASCADE)
|
||||||
client = models.ForeignKey(Client, on_delete=CASCADE)
|
client = models.ForeignKey(Client, on_delete=CASCADE)
|
||||||
|
@ -4146,6 +4140,12 @@ class UserPresence(models.Model):
|
||||||
# timestamp being old.
|
# timestamp being old.
|
||||||
status = models.PositiveSmallIntegerField(default=ACTIVE)
|
status = models.PositiveSmallIntegerField(default=ACTIVE)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ("user_profile", "client")
|
||||||
|
index_together = [
|
||||||
|
("realm", "timestamp"),
|
||||||
|
]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def status_to_string(status: int) -> str:
|
def status_to_string(status: int) -> str:
|
||||||
if status == UserPresence.ACTIVE:
|
if status == UserPresence.ACTIVE:
|
||||||
|
@ -4345,16 +4345,16 @@ class ScheduledMessage(models.Model):
|
||||||
default=SEND_LATER,
|
default=SEND_LATER,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
display_recipient = get_display_recipient(self.recipient)
|
||||||
|
return f"{display_recipient} {self.subject} {self.sender!r} {self.scheduled_timestamp}"
|
||||||
|
|
||||||
def topic_name(self) -> str:
|
def topic_name(self) -> str:
|
||||||
return self.subject
|
return self.subject
|
||||||
|
|
||||||
def set_topic_name(self, topic_name: str) -> None:
|
def set_topic_name(self, topic_name: str) -> None:
|
||||||
self.subject = topic_name
|
self.subject = topic_name
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
display_recipient = get_display_recipient(self.recipient)
|
|
||||||
return f"{display_recipient} {self.subject} {self.sender!r} {self.scheduled_timestamp}"
|
|
||||||
|
|
||||||
|
|
||||||
EMAIL_TYPES = {
|
EMAIL_TYPES = {
|
||||||
"followup_day1": ScheduledEmail.WELCOME,
|
"followup_day1": ScheduledEmail.WELCOME,
|
||||||
|
@ -4662,6 +4662,9 @@ class CustomProfileField(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ("realm", "name")
|
unique_together = ("realm", "name")
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"{self.realm!r} {self.name} {self.field_type} {self.order}"
|
||||||
|
|
||||||
def as_dict(self) -> ProfileDataElementBase:
|
def as_dict(self) -> ProfileDataElementBase:
|
||||||
data_as_dict: ProfileDataElementBase = {
|
data_as_dict: ProfileDataElementBase = {
|
||||||
"id": self.id,
|
"id": self.id,
|
||||||
|
@ -4681,9 +4684,6 @@ class CustomProfileField(models.Model):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return f"{self.realm!r} {self.name} {self.field_type} {self.order}"
|
|
||||||
|
|
||||||
|
|
||||||
def custom_profile_fields_for_realm(realm_id: int) -> QuerySet[CustomProfileField]:
|
def custom_profile_fields_for_realm(realm_id: int) -> QuerySet[CustomProfileField]:
|
||||||
return CustomProfileField.objects.filter(realm=realm_id).order_by("order")
|
return CustomProfileField.objects.filter(realm=realm_id).order_by("order")
|
||||||
|
|
Loading…
Reference in New Issue