Add more Ruff rules (#891)

* ruff: apply rule F

* ruff: apply rule E

* ruff: apply rule SIM

* ruff: apply rule TCH

* ruff: apply rule ERA

* ruff: apply rule PLW

* ruff: apply rule FLY

* ruff: apply rule PERF

* ruff: apply rules FURB & RUF
This commit is contained in:
thomas girod
2024-10-15 11:36:26 +02:00
committed by GitHub
parent d114b01bcc
commit d16a207a83
82 changed files with 836 additions and 748 deletions

View File

@ -16,7 +16,7 @@
from django.contrib import admin
from haystack.admin import SearchModelAdmin
from forum.models import *
from forum.models import Forum, ForumMessage, ForumTopic
@admin.register(Forum)

View File

@ -25,6 +25,7 @@ from __future__ import annotations
from datetime import datetime
from datetime import timezone as tz
from itertools import chain
from typing import Self
from django.conf import settings
from django.core.exceptions import ValidationError
@ -207,12 +208,12 @@ class Forum(models.Model):
return self.get_parent_list()
def get_parent_list(self):
l = []
p = self.parent
while p is not None:
l.append(p)
p = p.parent
return l
parents = []
current = self.parent
while current is not None:
parents.append(current)
current = current.parent
return parents
@property
def topic_number(self):
@ -228,12 +229,12 @@ class Forum(models.Model):
def last_message(self):
return self._last_message
def get_children_list(self):
l = [self.id]
def get_children_list(self) -> list[Self]:
children = [self.id]
for c in self.children.all():
l.append(c.id)
l += c.get_children_list()
return l
children.append(c.id)
children.extend(c.get_children_list())
return children
class ForumTopic(models.Model):

View File

@ -23,7 +23,26 @@
from django.urls import path
from forum.views import *
from forum.views import (
ForumCreateView,
ForumDeleteView,
ForumDetailView,
ForumEditView,
ForumFavoriteTopics,
ForumLastUnread,
ForumMainView,
ForumMarkAllAsRead,
ForumMessageCreateView,
ForumMessageDeleteView,
ForumMessageEditView,
ForumMessageUndeleteView,
ForumMessageView,
ForumSearchView,
ForumTopicCreateView,
ForumTopicDetailView,
ForumTopicEditView,
ForumTopicSubscribeView,
)
urlpatterns = [
path("", ForumMainView.as_view(), name="main"),
@ -35,21 +54,9 @@ urlpatterns = [
path("<int:forum_id>/", ForumDetailView.as_view(), name="view_forum"),
path("<int:forum_id>/edit/", ForumEditView.as_view(), name="edit_forum"),
path("<int:forum_id>/delete/", ForumDeleteView.as_view(), name="delete_forum"),
path(
"<int:forum_id>/new_topic/",
ForumTopicCreateView.as_view(),
name="new_topic",
),
path(
"topic/<int:topic_id>/",
ForumTopicDetailView.as_view(),
name="view_topic",
),
path(
"topic/<int:topic_id>/edit/",
ForumTopicEditView.as_view(),
name="edit_topic",
),
path("<int:forum_id>/new_topic/", ForumTopicCreateView.as_view(), name="new_topic"),
path("topic/<int:topic_id>/", ForumTopicDetailView.as_view(), name="view_topic"),
path("topic/<int:topic_id>/edit/", ForumTopicEditView.as_view(), name="edit_topic"),
path(
"topic/<int:topic_id>/new_message/",
ForumMessageCreateView.as_view(),
@ -60,11 +67,7 @@ urlpatterns = [
ForumTopicSubscribeView.as_view(),
name="toggle_subscribe_topic",
),
path(
"message/<int:message_id>/",
ForumMessageView.as_view(),
name="view_message",
),
path("message/<int:message_id>/", ForumMessageView.as_view(), name="view_message"),
path(
"message/<int:message_id>/edit/",
ForumMessageEditView.as_view(),