aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Xithrius <[email protected]>2023-05-11 22:32:56 -0700
committerGravatar GitHub <[email protected]>2023-05-11 22:32:56 -0700
commite8b63ab623613e290849c36bb97efa2943e1cf33 (patch)
treec592334d85dea868ca725e57b30bc221cb1e16b5
parentSwitch to psycopg 3 (diff)
parentMerge pull request #970 from python-discord/django-rules-ruff (diff)
Merge branch 'main' into psycopg3
-rw-r--r--pydis_site/apps/api/models/bot/documentation_link.py8
-rw-r--r--pydis_site/apps/api/models/bot/filters.py6
-rw-r--r--pydis_site/apps/api/models/bot/infraction.py18
-rw-r--r--pydis_site/apps/api/models/bot/message.py10
-rw-r--r--pydis_site/apps/api/models/bot/message_deletion_context.py10
-rw-r--r--pydis_site/apps/api/models/bot/nomination.py10
-rw-r--r--pydis_site/apps/api/models/bot/role.py10
-rw-r--r--pydis_site/apps/content/tests/test_views.py8
-rw-r--r--pydis_site/templates/content/base.html2
-rw-r--r--pyproject.toml3
10 files changed, 47 insertions, 38 deletions
diff --git a/pydis_site/apps/api/models/bot/documentation_link.py b/pydis_site/apps/api/models/bot/documentation_link.py
index 9941907c..7f3b4ca5 100644
--- a/pydis_site/apps/api/models/bot/documentation_link.py
+++ b/pydis_site/apps/api/models/bot/documentation_link.py
@@ -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}"
diff --git a/pydis_site/apps/api/models/bot/filters.py b/pydis_site/apps/api/models/bot/filters.py
index 620031dc..6d5188e4 100644
--- a/pydis_site/apps/api/models/bot/filters.py
+++ b/pydis_site/apps/api/models/bot/filters.py
@@ -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):
"""
diff --git a/pydis_site/apps/api/models/bot/infraction.py b/pydis_site/apps/api/models/bot/infraction.py
index 381b5b9d..b304c6d4 100644
--- a/pydis_site/apps/api/models/bot/infraction.py
+++ b/pydis_site/apps/api/models/bot/infraction.py
@@ -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."""
@@ -98,3 +89,12 @@ class Infraction(ModelReprMixin, models.Model):
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
diff --git a/pydis_site/apps/api/models/bot/message.py b/pydis_site/apps/api/models/bot/message.py
index d8147cd4..fb3c47fc 100644
--- a/pydis_site/apps/api/models/bot/message.py
+++ b/pydis_site/apps/api/models/bot/message.py
@@ -58,6 +58,11 @@ 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."""
@@ -65,8 +70,3 @@ class Message(ModelReprMixin, models.Model):
((self.id >> 22) + 1420070400000) / 1000,
tz=datetime.timezone.utc,
)
-
- class Meta:
- """Metadata provided for Django's ORM."""
-
- abstract = True
diff --git a/pydis_site/apps/api/models/bot/message_deletion_context.py b/pydis_site/apps/api/models/bot/message_deletion_context.py
index 25741266..207bc4bc 100644
--- a/pydis_site/apps/api/models/bot/message_deletion_context.py
+++ b/pydis_site/apps/api/models/bot/message_deletion_context.py
@@ -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,))
diff --git a/pydis_site/apps/api/models/bot/nomination.py b/pydis_site/apps/api/models/bot/nomination.py
index 58e70a83..2f8e305c 100644
--- a/pydis_site/apps/api/models/bot/nomination.py
+++ b/pydis_site/apps/api/models/bot/nomination.py
@@ -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."""
diff --git a/pydis_site/apps/api/models/bot/role.py b/pydis_site/apps/api/models/bot/role.py
index 733a8e08..e37f3ccd 100644
--- a/pydis_site/apps/api/models/bot/role.py
+++ b/pydis_site/apps/api/models/bot/role.py
@@ -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
@@ -62,8 +67,3 @@ class Role(ModelReprMixin, models.Model):
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",)
diff --git a/pydis_site/apps/content/tests/test_views.py b/pydis_site/apps/content/tests/test_views.py
index e4f898ef..cfc580c0 100644
--- a/pydis_site/apps/content/tests/test_views.py
+++ b/pydis_site/apps/content/tests/test_views.py
@@ -387,6 +387,14 @@ class TagViewTests(django.test.TestCase):
response.context.get("page")
)
+ def test_tags_have_no_edit_on_github_link(self):
+ """Tags should not have the standard edit on GitHub link."""
+ # The standard "Edit on GitHub" link should not be displayed on tags
+ # because they have their own GitHub icon that links there.
+ Tag.objects.create(name="example", body="Joe William Banks", last_commit=self.commit)
+ response = self.client.get("/pages/tags/example/")
+ self.assertNotContains(response, "Edit on GitHub")
+
def test_tag_root_page(self):
"""Test the root tag page which lists all tags."""
Tag.objects.create(name="tag-1", last_commit=self.commit)
diff --git a/pydis_site/templates/content/base.html b/pydis_site/templates/content/base.html
index b04c7efa..bda6d954 100644
--- a/pydis_site/templates/content/base.html
+++ b/pydis_site/templates/content/base.html
@@ -37,7 +37,7 @@
{% include "content/dropdown.html" %}
{% endif %}
{# Edit on GitHub for content articles #}
- {% if page %}
+ {% if page and not tag %}
<div id="edit-on-github">
<a href="{{ request.path | page_src_url }}">
<i class="fa-solid fa-pencil"></i>
diff --git a/pyproject.toml b/pyproject.toml
index 6374be54..0e7c2834 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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"]