From 171a1cb8760a5bbd31d33ecdd32b9d7519316c1d Mon Sep 17 00:00:00 2001 From: thomas girod Date: Thu, 27 Jun 2024 14:57:40 +0200 Subject: [PATCH] ruff rule FBT --- core/management/commands/install_xapian.py | 2 +- core/models.py | 4 ++-- core/views/forms.py | 2 +- core/views/site.py | 10 +++++----- counter/models.py | 4 ++-- counter/views.py | 4 ++-- pedagogy/tests.py | 16 ++++++++-------- .../commands/delete_all_forum_user_messages.py | 2 +- rootplace/views.py | 2 +- sas/models.py | 2 +- sas/views.py | 4 ++-- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/core/management/commands/install_xapian.py b/core/management/commands/install_xapian.py index 04a1cc2e..e91491be 100644 --- a/core/management/commands/install_xapian.py +++ b/core/management/commands/install_xapian.py @@ -46,7 +46,7 @@ class Command(BaseCommand): pyproject = tomli.load(f) return pyproject["tool"]["xapian"]["version"] - def handle(self, force: bool, *args, **options): + def handle(self, *args, force: bool, **options): if not os.environ.get("VIRTUAL_ENV", None): print("No virtual environment detected, this command can't be used") return diff --git a/core/models.py b/core/models.py index b26f894d..0d5e1013 100644 --- a/core/models.py +++ b/core/models.py @@ -1055,13 +1055,13 @@ class SithFile(models.Model): param="1", ).save() - def apply_rights_recursively(self, only_folders=False): + def apply_rights_recursively(self, *, only_folders=False): children = self.children.all() if only_folders: children = children.filter(is_folder=True) for c in children: c.copy_rights() - c.apply_rights_recursively(only_folders) + c.apply_rights_recursively(only_folders=only_folders) def copy_rights(self): """Copy, if possible, the rights of the parent folder""" diff --git a/core/views/forms.py b/core/views/forms.py index 7ee321a0..1ee9bda2 100644 --- a/core/views/forms.py +++ b/core/views/forms.py @@ -194,7 +194,7 @@ class RegisteringForm(UserCreationForm): model = User fields = ("first_name", "last_name", "email") - def save(self, commit=True): + def save(self, *, commit=True): user = super().save(commit=False) user.set_password(self.cleaned_data["password1"]) user.generate_username() diff --git a/core/views/site.py b/core/views/site.py index 54229cd1..b0aeb3e7 100644 --- a/core/views/site.py +++ b/core/views/site.py @@ -74,7 +74,7 @@ def notification(request, notif_id): return redirect("/") -def search_user(query, as_json=False): +def search_user(query): try: # slugify turns everything into ascii and every whitespace into - # it ends by removing duplicate - (so ' - ' will turn into '-') @@ -93,7 +93,7 @@ def search_user(query, as_json=False): return [] -def search_club(query, as_json=False): +def search_club(query,* , as_json=False): clubs = [] if query: clubs = Club.objects.filter(name__icontains=query).all() @@ -117,15 +117,15 @@ def search_view(request): @login_required def search_user_json(request): - result = {"users": search_user(request.GET.get("query", ""), True)} + result = {"users": search_user(request.GET.get("query", ""))} return JsonResponse(result) @login_required def search_json(request): result = { - "users": search_user(request.GET.get("query", ""), True), - "clubs": search_club(request.GET.get("query", ""), True), + "users": search_user(request.GET.get("query", "")), + "clubs": search_club(request.GET.get("query", ""), as_json=True), } return JsonResponse(result) diff --git a/counter/models.py b/counter/models.py index 97382735..dd7a9989 100644 --- a/counter/models.py +++ b/counter/models.py @@ -128,7 +128,7 @@ class Customer(models.Model): account = cls.objects.create(user=user, account_id=account_id) return account, True - def save(self, allow_negative=False, is_selling=False, *args, **kwargs): + def save(self, *args, allow_negative=False, is_selling=False, **kwargs): """ is_selling : tell if the current action is a selling allow_negative : ignored if not a selling. Allow a selling to put the account in negative @@ -776,7 +776,7 @@ class Selling(models.Model): } self.customer.user.email_user(subject, message_txt, html_message=message_html) - def save(self, allow_negative=False, *args, **kwargs): + def save(self, *args, allow_negative=False, **kwargs): """ allow_negative : Allow this selling to use more money than available for this user """ diff --git a/counter/views.py b/counter/views.py index 29d7c017..08b88c00 100644 --- a/counter/views.py +++ b/counter/views.py @@ -1695,7 +1695,7 @@ class StudentCardFormView(FormView): ) -def __manage_billing_info_req(request, user_id, delete_if_fail=False): +def __manage_billing_info_req(request, user_id, *, delete_if_fail=False): data = json.loads(request.body) form = BillingInfoForm(data) if not form.is_valid(): @@ -1725,7 +1725,7 @@ def create_billing_info(request, user_id): user = get_object_or_404(User, pk=user_id) customer, _ = Customer.get_or_create(user) BillingInfo.objects.create(customer=customer) - return __manage_billing_info_req(request, user_id, True) + return __manage_billing_info_req(request, user_id, delete_if_fail=True) @login_required diff --git a/pedagogy/tests.py b/pedagogy/tests.py index 36356270..f630ff15 100644 --- a/pedagogy/tests.py +++ b/pedagogy/tests.py @@ -983,7 +983,7 @@ class UVCommentReportCreateTest(TestCase): self.comment = UVComment(**comment_kwargs) self.comment.save() - def create_report_test(self, username, success): + def create_report_test(self, username: str, *, success: bool): self.client.login(username=username, password="plop") response = self.client.post( reverse("pedagogy:comment_report", kwargs={"comment_id": self.comment.id}), @@ -1000,16 +1000,16 @@ class UVCommentReportCreateTest(TestCase): self.assertEqual(UVCommentReport.objects.all().exists(), success) def test_create_report_root_success(self): - self.create_report_test("root", True) + self.create_report_test("root", success=True) def test_create_report_pedagogy_admin_success(self): - self.create_report_test("tutu", True) + self.create_report_test("tutu", success=True) def test_create_report_subscriber_success(self): - self.create_report_test("sli", True) + self.create_report_test("sli", success=True) def test_create_report_unsubscribed_fail(self): - self.create_report_test("guy", False) + self.create_report_test("guy", success=False) def test_create_report_anonymous_fail(self): response = self.client.post( @@ -1022,7 +1022,7 @@ class UVCommentReportCreateTest(TestCase): def test_notifications(self): assert not self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").exists() # Create a comment report - self.create_report_test("tutu", True) + self.create_report_test("tutu", success=True) # Check that a notification has been created for pedagogy admins assert self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").exists() @@ -1032,7 +1032,7 @@ class UVCommentReportCreateTest(TestCase): assert notif.user.is_in_group(pk=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID) # Check that notifications are not duplicated if not viewed - self.create_report_test("tutu", True) + self.create_report_test("tutu", success=True) assert self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").count() == 1 # Check that a new notification is created when the old one has been viewed @@ -1040,6 +1040,6 @@ class UVCommentReportCreateTest(TestCase): notif.viewed = True notif.save() - self.create_report_test("tutu", True) + self.create_report_test("tutu", success=True) assert self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").count() == 2 diff --git a/rootplace/management/commands/delete_all_forum_user_messages.py b/rootplace/management/commands/delete_all_forum_user_messages.py index 0d0811ca..90e9433c 100644 --- a/rootplace/management/commands/delete_all_forum_user_messages.py +++ b/rootplace/management/commands/delete_all_forum_user_messages.py @@ -54,4 +54,4 @@ class Command(BaseCommand): print("Operation aborted") exit(1) - delete_all_forum_user_messages(user, User.objects.get(id=0), True) + delete_all_forum_user_messages(user, User.objects.get(id=0), verbose=True) diff --git a/rootplace/views.py b/rootplace/views.py index 0b103485..aae90e77 100644 --- a/rootplace/views.py +++ b/rootplace/views.py @@ -133,7 +133,7 @@ def merge_users(u1: User, u2: User) -> User: return u1 -def delete_all_forum_user_messages(user, moderator, verbose=False): +def delete_all_forum_user_messages(user, moderator, *, verbose=False): """ Create a ForumMessageMeta that says a forum message is deleted on every forum message of an user diff --git a/sas/models.py b/sas/models.py index 78c3cd5b..ee9d5e40 100644 --- a/sas/models.py +++ b/sas/models.py @@ -88,7 +88,7 @@ class Picture(SithFile): def get_absolute_url(self): return reverse("sas:picture", kwargs={"picture_id": self.id}) - def generate_thumbnails(self, overwrite=False): + def generate_thumbnails(self, *, overwrite=False): im = Image.open(BytesIO(self.file.read())) try: im = exif_auto_rotate(im) diff --git a/sas/views.py b/sas/views.py index f48db755..367771dc 100644 --- a/sas/views.py +++ b/sas/views.py @@ -42,7 +42,7 @@ class SASForm(forms.Form): required=False, ) - def process(self, parent, owner, files, automodere=False): + def process(self, parent, owner, files, *, automodere=False): try: if self.cleaned_data["album_name"] != "": album = Album( @@ -376,5 +376,5 @@ class AlbumEditView(CanEditMixin, UpdateView): def form_valid(self, form): ret = super().form_valid(form) if form.cleaned_data["recursive"]: - self.object.apply_rights_recursively(True) + self.object.apply_rights_recursively(only_folders=True) return ret