ruff rule FBT

This commit is contained in:
thomas girod 2024-06-27 14:57:40 +02:00
parent cfc19434d0
commit 171a1cb876
11 changed files with 26 additions and 26 deletions

View File

@ -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

View File

@ -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"""

View File

@ -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()

View File

@ -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)

View File

@ -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
"""

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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