Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pydis_site/apps/api/models/bot/documentation_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ class DocumentationLink(ModelReprMixin, models.Model):
help_text="The URL at which the Sphinx inventory is available for this package."
)

def __str__(self):
"""Returns the package and URL for the current documentation link, for display purposes."""
return f"{self.package} - {self.base_url}"

class Meta:
"""Defines the meta options for the documentation link model."""

ordering = ['package']

def __str__(self):
"""Returns the package and URL for the current documentation link, for display purposes."""
return f"{self.package} - {self.base_url}"
6 changes: 3 additions & 3 deletions pydis_site/apps/api/models/bot/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ class FilterBase(ModelTimestampMixin, ModelReprMixin, models.Model):
null=True
)

def __str__(self) -> str:
return f"Filter {self.content!r}"

class Meta:
"""Metaclass for FilterBase to make it abstract model."""

abstract = True

def __str__(self) -> str:
return f"Filter {self.content!r}"


class Filter(FilterBase):
"""
Expand Down
18 changes: 9 additions & 9 deletions pydis_site/apps/api/models/bot/infraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,6 @@ class Infraction(ModelReprMixin, models.Model):
)
)

def __str__(self):
"""Returns some info on the current infraction, for display purposes."""
s = f"#{self.id}: {self.type} on {self.user_id}"
if self.expires_at:
s += f" until {self.expires_at}"
if self.hidden:
s += " (hidden)"
return s

class Meta:
"""Defines the meta options for the infraction model."""

Expand All @@ -98,3 +89,12 @@ class Meta:
name="unique_active_infraction_per_type_per_user"
),
)

def __str__(self):
"""Returns some info on the current infraction, for display purposes."""
s = f"#{self.id}: {self.type} on {self.user_id}"
if self.expires_at:
s += f" until {self.expires_at}"
if self.hidden:
s += " (hidden)"
return s
10 changes: 5 additions & 5 deletions pydis_site/apps/api/models/bot/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class Message(ModelReprMixin, models.Model):
help_text="Attachments attached to this message."
)

class Meta:
"""Metadata provided for Django's ORM."""

abstract = True

@property
def timestamp(self) -> datetime.datetime:
"""Attribute that represents the message timestamp as derived from the snowflake id."""
return datetime.datetime.fromtimestamp(
((self.id >> 22) + 1420070400000) / 1000,
tz=datetime.timezone.utc,
)

class Meta:
"""Metadata provided for Django's ORM."""

abstract = True
10 changes: 5 additions & 5 deletions pydis_site/apps/api/models/bot/message_deletion_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class MessageDeletionContext(ModelReprMixin, models.Model):
help_text="When this deletion took place."
)

@property
def log_url(self) -> str:
"""Create the url for the deleted message logs."""
return reverse('staff:logs', args=(self.id,))

class Meta:
"""Set the ordering for list views to newest first."""

ordering = ("-creation",)

@property
def log_url(self) -> str:
"""Create the url for the deleted message logs."""
return reverse('staff:logs', args=(self.id,))
10 changes: 5 additions & 5 deletions pydis_site/apps/api/models/bot/nomination.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ class Nomination(ModelReprMixin, models.Model):
null=True,
)

def __str__(self):
"""Representation that makes the target and state of the nomination immediately evident."""
status = "active" if self.active else "ended"
return f"Nomination of {self.user} ({status})"

class Meta:
"""Set the ordering of nominations to most recent first."""

ordering = ("-inserted_at",)

def __str__(self):
"""Representation that makes the target and state of the nomination immediately evident."""
status = "active" if self.active else "ended"
return f"Nomination of {self.user} ({status})"


class NominationEntry(ModelReprMixin, models.Model):
"""A nomination entry created by a single staff member."""
Expand Down
10 changes: 5 additions & 5 deletions pydis_site/apps/api/models/bot/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class Role(ModelReprMixin, models.Model):
help_text="The position of the role in the role hierarchy of the Discord Guild."
)

class Meta:
"""Set role ordering from highest to lowest position."""

ordering = ("-position",)

def __str__(self) -> str:
"""Returns the name of the current role, for display purposes."""
return self.name
Expand All @@ -62,8 +67,3 @@ def __lt__(self, other: Role) -> bool:
def __le__(self, other: Role) -> bool:
"""Compares the roles based on their position in the role hierarchy of the guild."""
return self.position <= other.position

class Meta:
"""Set role ordering from highest to lowest position."""

ordering = ("-position",)
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ ignore = [
"D100", "D104", "D105", "D107", "D203", "D212", "D214", "D215", "D301",
"D400", "D401", "D402", "D404", "D405", "D406", "D407", "D408", "D409", "D410", "D411", "D412", "D413", "D414", "D416", "D417",
"E731",
"DJ001", "DJ008",
"RET504",
"RUF005",
"S311",
"SIM102", "SIM108",
]
line-length = 120
select = ["ANN", "B", "C4", "D", "DTZ", "E", "F", "ISC", "INT", "N", "PGH", "PIE", "RET", "RSE", "RUF", "S", "SIM", "T20", "TID", "UP", "W"]
select = ["ANN", "B", "C4", "D", "DJ", "DTZ", "E", "F", "ISC", "INT", "N", "PGH", "PIE", "RET", "RSE", "RUF", "S", "SIM", "T20", "TID", "UP", "W"]

[tool.ruff.per-file-ignores]
"pydis_site/apps/**/migrations/*.py" = ["ALL"]
Expand Down