mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 10:34:21 +00:00
ruff rule FBT
This commit is contained in:
parent
cfc19434d0
commit
171a1cb876
@ -46,7 +46,7 @@ class Command(BaseCommand):
|
|||||||
pyproject = tomli.load(f)
|
pyproject = tomli.load(f)
|
||||||
return pyproject["tool"]["xapian"]["version"]
|
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):
|
if not os.environ.get("VIRTUAL_ENV", None):
|
||||||
print("No virtual environment detected, this command can't be used")
|
print("No virtual environment detected, this command can't be used")
|
||||||
return
|
return
|
||||||
|
@ -1055,13 +1055,13 @@ class SithFile(models.Model):
|
|||||||
param="1",
|
param="1",
|
||||||
).save()
|
).save()
|
||||||
|
|
||||||
def apply_rights_recursively(self, only_folders=False):
|
def apply_rights_recursively(self, *, only_folders=False):
|
||||||
children = self.children.all()
|
children = self.children.all()
|
||||||
if only_folders:
|
if only_folders:
|
||||||
children = children.filter(is_folder=True)
|
children = children.filter(is_folder=True)
|
||||||
for c in children:
|
for c in children:
|
||||||
c.copy_rights()
|
c.copy_rights()
|
||||||
c.apply_rights_recursively(only_folders)
|
c.apply_rights_recursively(only_folders=only_folders)
|
||||||
|
|
||||||
def copy_rights(self):
|
def copy_rights(self):
|
||||||
"""Copy, if possible, the rights of the parent folder"""
|
"""Copy, if possible, the rights of the parent folder"""
|
||||||
|
@ -194,7 +194,7 @@ class RegisteringForm(UserCreationForm):
|
|||||||
model = User
|
model = User
|
||||||
fields = ("first_name", "last_name", "email")
|
fields = ("first_name", "last_name", "email")
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, *, commit=True):
|
||||||
user = super().save(commit=False)
|
user = super().save(commit=False)
|
||||||
user.set_password(self.cleaned_data["password1"])
|
user.set_password(self.cleaned_data["password1"])
|
||||||
user.generate_username()
|
user.generate_username()
|
||||||
|
@ -74,7 +74,7 @@ def notification(request, notif_id):
|
|||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
|
|
||||||
def search_user(query, as_json=False):
|
def search_user(query):
|
||||||
try:
|
try:
|
||||||
# slugify turns everything into ascii and every whitespace into -
|
# slugify turns everything into ascii and every whitespace into -
|
||||||
# it ends by removing duplicate - (so ' - ' will turn into '-')
|
# it ends by removing duplicate - (so ' - ' will turn into '-')
|
||||||
@ -93,7 +93,7 @@ def search_user(query, as_json=False):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def search_club(query, as_json=False):
|
def search_club(query,* , as_json=False):
|
||||||
clubs = []
|
clubs = []
|
||||||
if query:
|
if query:
|
||||||
clubs = Club.objects.filter(name__icontains=query).all()
|
clubs = Club.objects.filter(name__icontains=query).all()
|
||||||
@ -117,15 +117,15 @@ def search_view(request):
|
|||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def search_user_json(request):
|
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)
|
return JsonResponse(result)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def search_json(request):
|
def search_json(request):
|
||||||
result = {
|
result = {
|
||||||
"users": search_user(request.GET.get("query", ""), True),
|
"users": search_user(request.GET.get("query", "")),
|
||||||
"clubs": search_club(request.GET.get("query", ""), True),
|
"clubs": search_club(request.GET.get("query", ""), as_json=True),
|
||||||
}
|
}
|
||||||
return JsonResponse(result)
|
return JsonResponse(result)
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ class Customer(models.Model):
|
|||||||
account = cls.objects.create(user=user, account_id=account_id)
|
account = cls.objects.create(user=user, account_id=account_id)
|
||||||
return account, True
|
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
|
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
|
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)
|
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
|
allow_negative : Allow this selling to use more money than available for this user
|
||||||
"""
|
"""
|
||||||
|
@ -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)
|
data = json.loads(request.body)
|
||||||
form = BillingInfoForm(data)
|
form = BillingInfoForm(data)
|
||||||
if not form.is_valid():
|
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)
|
user = get_object_or_404(User, pk=user_id)
|
||||||
customer, _ = Customer.get_or_create(user)
|
customer, _ = Customer.get_or_create(user)
|
||||||
BillingInfo.objects.create(customer=customer)
|
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
|
@login_required
|
||||||
|
@ -983,7 +983,7 @@ class UVCommentReportCreateTest(TestCase):
|
|||||||
self.comment = UVComment(**comment_kwargs)
|
self.comment = UVComment(**comment_kwargs)
|
||||||
self.comment.save()
|
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")
|
self.client.login(username=username, password="plop")
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
reverse("pedagogy:comment_report", kwargs={"comment_id": self.comment.id}),
|
reverse("pedagogy:comment_report", kwargs={"comment_id": self.comment.id}),
|
||||||
@ -1000,16 +1000,16 @@ class UVCommentReportCreateTest(TestCase):
|
|||||||
self.assertEqual(UVCommentReport.objects.all().exists(), success)
|
self.assertEqual(UVCommentReport.objects.all().exists(), success)
|
||||||
|
|
||||||
def test_create_report_root_success(self):
|
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):
|
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):
|
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):
|
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):
|
def test_create_report_anonymous_fail(self):
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
@ -1022,7 +1022,7 @@ class UVCommentReportCreateTest(TestCase):
|
|||||||
def test_notifications(self):
|
def test_notifications(self):
|
||||||
assert not self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").exists()
|
assert not self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").exists()
|
||||||
# Create a comment report
|
# 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
|
# Check that a notification has been created for pedagogy admins
|
||||||
assert self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").exists()
|
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)
|
assert notif.user.is_in_group(pk=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
|
||||||
|
|
||||||
# Check that notifications are not duplicated if not viewed
|
# 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
|
assert self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").count() == 1
|
||||||
|
|
||||||
# Check that a new notification is created when the old one has been viewed
|
# 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.viewed = True
|
||||||
notif.save()
|
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
|
assert self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").count() == 2
|
||||||
|
@ -54,4 +54,4 @@ class Command(BaseCommand):
|
|||||||
print("Operation aborted")
|
print("Operation aborted")
|
||||||
exit(1)
|
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)
|
||||||
|
@ -133,7 +133,7 @@ def merge_users(u1: User, u2: User) -> User:
|
|||||||
return u1
|
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
|
Create a ForumMessageMeta that says a forum
|
||||||
message is deleted on every forum message of an user
|
message is deleted on every forum message of an user
|
||||||
|
@ -88,7 +88,7 @@ class Picture(SithFile):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("sas:picture", kwargs={"picture_id": self.id})
|
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()))
|
im = Image.open(BytesIO(self.file.read()))
|
||||||
try:
|
try:
|
||||||
im = exif_auto_rotate(im)
|
im = exif_auto_rotate(im)
|
||||||
|
@ -42,7 +42,7 @@ class SASForm(forms.Form):
|
|||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
def process(self, parent, owner, files, automodere=False):
|
def process(self, parent, owner, files, *, automodere=False):
|
||||||
try:
|
try:
|
||||||
if self.cleaned_data["album_name"] != "":
|
if self.cleaned_data["album_name"] != "":
|
||||||
album = Album(
|
album = Album(
|
||||||
@ -376,5 +376,5 @@ class AlbumEditView(CanEditMixin, UpdateView):
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
ret = super().form_valid(form)
|
ret = super().form_valid(form)
|
||||||
if form.cleaned_data["recursive"]:
|
if form.cleaned_data["recursive"]:
|
||||||
self.object.apply_rights_recursively(True)
|
self.object.apply_rights_recursively(only_folders=True)
|
||||||
return ret
|
return ret
|
||||||
|
Loading…
Reference in New Issue
Block a user