ruff rule A

This commit is contained in:
thomas girod 2024-06-27 14:30:58 +02:00
parent 3014d8cead
commit 688871a680
9 changed files with 35 additions and 34 deletions

View File

@ -683,16 +683,16 @@ class JournalNatureStatementView(JournalTabsMixin, CanViewMixin, DetailView):
for sat in [None] + list(
SimplifiedAccountingType.objects.order_by("label").all()
):
sum = queryset.filter(
amount = queryset.filter(
accounting_type__movement_type=movement_type, simpleaccounting_type=sat
).aggregate(amount_sum=Sum("amount"))["amount_sum"]
if sat:
sat = sat.label
else:
sat = ""
if sum:
total_sum += sum
statement[sat] = sum
if amount:
total_sum += amount
statement[sat] = amount
ret[movement_type] = statement
ret[movement_type + "_sum"] = total_sum
return ret

View File

@ -22,8 +22,8 @@ from mistune import InlineGrammar, InlineLexer, Markdown, Renderer, escape, esca
class SithRenderer(Renderer):
def file_link(self, id, suffix):
return reverse("core:file_detail", kwargs={"file_id": id}) + suffix
def file_link(self, pk, suffix):
return reverse("core:file_detail", kwargs={"file_id": pk}) + suffix
def exposant(self, text):
return """<sup>%s</sup>""" % text
@ -158,7 +158,7 @@ class SithInlineLexer(InlineLexer):
try: # Add file:// support for links
file_link = re.compile(r"^file://(\d*)/?(\S*)?") # file://4000/download
match = file_link.search(link)
id = match.group(1)
pk = match.group(1)
suffix = match.group(2) or ""
link = reverse("core:file_detail", kwargs={"file_id": id}) + suffix
except:

View File

@ -48,7 +48,7 @@ class ScssFinder(FileSystemFinder):
filesystem_storage.prefix = self.locations[0][0]
self.storages[location] = filesystem_storage
def find(self, path, all=False):
def find(self, path, all=False): # noqa A002 (shadows the builtin `all` function)
if path.endswith(".css"):
return super(ScssFinder, self).find(path, all)
return []

View File

@ -44,14 +44,14 @@ def markdown(text):
@register.filter(name="phonenumber")
def phonenumber(value, country="FR", format=phonenumbers.PhoneNumberFormat.NATIONAL):
def phonenumber(value, country="FR", number_format=phonenumbers.PhoneNumberFormat.NATIONAL):
"""
This filter is kindly borrowed from https://github.com/foundertherapy/django-phonenumber-filter
"""
value = str(value)
try:
parsed = phonenumbers.parse(value, country)
return phonenumbers.format_number(parsed, format)
return phonenumbers.format_number(parsed, number_format)
except phonenumbers.NumberParseException as e:
return value

View File

@ -106,7 +106,7 @@ def scale_dimension(width, height, long_edge):
return int(width * ratio), int(height * ratio)
def resize_image(im, edge, format):
def resize_image(im, edge, img_format):
(w, h) = im.size
(width, height) = scale_dimension(w, h, long_edge=edge)
content = BytesIO()
@ -115,7 +115,7 @@ def resize_image(im, edge, format):
try:
im.save(
fp=content,
format=format.upper(),
format=img_format.upper(),
quality=90,
optimize=True,
progressive=True,
@ -124,7 +124,7 @@ def resize_image(im, edge, format):
PIL.ImageFile.MAXBLOCK = im.size[0] * im.size[1]
im.save(
fp=content,
format=format.upper(),
format=img_format.upper(),
quality=90,
optimize=True,
progressive=True,
@ -203,14 +203,14 @@ def doku_to_markdown(text):
quote_level = 0
for line in text.splitlines(): # Tables and quotes
enter = re.finditer(r"\[quote(=(.+?))?\]", line)
quit = re.finditer(r"\[/quote\]", line)
quit_ = re.finditer(r"\[/quote\]", line)
if re.search(r"\A\s*\^(([^\^]*?)\^)*", line): # Table part
line = line.replace("^", "|")
new_text.append("> " * quote_level + line)
new_text.append(
"> " * quote_level + "|---|"
) # Don't keep the text alignement in tables it's really too complex for what it's worth
elif enter or quit: # Quote part
elif enter or quit_: # Quote part
for quote in enter: # Enter quotes (support multiple at a time)
quote_level += 1
try:
@ -218,9 +218,9 @@ def doku_to_markdown(text):
except:
new_text.append("> " * quote_level)
line = line.replace(quote.group(0), "")
final_quote_level = quote_level # Store quote_level to use at the end, since it will be modified during quit iteration
final_quote_level = quote_level # Store quote_level to use at the end, since it will be modified during quit_ iteration
final_newline = False
for quote in quit: # Quit quotes (support multiple at a time)
for quote in quit_: # Quit quotes (support multiple at a time)
line = line.replace(quote.group(0), "")
quote_level -= 1
final_newline = True
@ -258,8 +258,8 @@ def bbcode_to_markdown(text):
quote_level = 0
for line in text.splitlines(): # Tables and quotes
enter = re.finditer(r"\[quote(=(.+?))?\]", line)
quit = re.finditer(r"\[/quote\]", line)
if enter or quit: # Quote part
quit_ = re.finditer(r"\[/quote\]", line)
if enter or quit_: # Quote part
for quote in enter: # Enter quotes (support multiple at a time)
quote_level += 1
try:
@ -267,9 +267,9 @@ def bbcode_to_markdown(text):
except:
new_text.append("> " * quote_level)
line = line.replace(quote.group(0), "")
final_quote_level = quote_level # Store quote_level to use at the end, since it will be modified during quit iteration
final_quote_level = quote_level # Store quote_level to use at the end, since it will be modified during quit_ iteration
final_newline = False
for quote in quit: # Quit quotes (support multiple at a time)
for quote in quit_: # Quit quotes (support multiple at a time)
line = line.replace(quote.group(0), "")
quote_level -= 1
final_newline = True

View File

@ -277,7 +277,8 @@ class FileView(CanViewMixin, DetailView, FormMixin):
context_object_name = "file"
form_class = AddFilesForm
def handle_clipboard(request, object):
@staticmethod
def handle_clipboard(request, obj):
"""
This method handles the clipboard in the view.
This method can fail, since it does not catch the exceptions coming from
@ -286,8 +287,8 @@ class FileView(CanViewMixin, DetailView, FormMixin):
FileView.handle_clipboard(request, self.object)
`request` is usually the self.request object in your view
`object` is the SithFile object you want to put in the clipboard, or
`request` is usually the self.request obj in your view
`obj` is the SithFile object you want to put in the clipboard, or
where you want to paste the clipboard
"""
if "delete" in request.POST.keys():
@ -301,7 +302,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
for f_id in request.POST.getlist("file_list"):
f_id = int(f_id)
if (
f_id in [c.id for c in object.children.all()]
f_id in [c.id for c in obj.children.all()]
and f_id not in request.session["clipboard"]
):
request.session["clipboard"].append(f_id)
@ -309,7 +310,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
for f_id in request.session["clipboard"]:
sf = SithFile.objects.filter(id=f_id).first()
if sf:
sf.move_to(object)
sf.move_to(obj)
request.session["clipboard"] = []
request.session.modified = True
@ -328,7 +329,7 @@ class FileView(CanViewMixin, DetailView, FormMixin):
request.session["clipboard"] = []
if request.user.can_edit(self.object):
# XXX this call can fail!
FileView.handle_clipboard(request, self.object)
self.handle_clipboard(request, self.object)
self.form = self.get_form() # The form handle only the file upload
files = request.FILES.getlist("file_field")
if (

View File

@ -23,10 +23,10 @@ django.setup()
# -- Project information -----------------------------------------------------
project = "Sith AE UTBM"
copyright = (
"2019, Bartuccio Antoine (Sli), Brunet Pierre (Krohpil), Jacquet Florent (Skia)"
copyright = ( # noqa A001
"2019, Bartuccio Antoine (Sli), Brunet Pierre (Krophil), Jacquet Florent (Skia)"
)
author = "Bartuccio Antoine (Sli), Brunet Pierre (Krohpil), Jacquet Florent (Skia)"
author = "Bartuccio Antoine (Sli), Brunet Pierre (Krophil), Jacquet Florent (Skia)"
# -- General configuration ---------------------------------------------------

View File

@ -116,13 +116,13 @@ class LaunderetteBookView(CanViewMixin, DetailView):
).save()
return super(LaunderetteBookView, self).get(request, *args, **kwargs)
def check_slot(self, type, date=None):
def check_slot(self, machine_type, date=None):
if date is None:
date = self.date
for m in self.object.machines.filter(is_working=True, type=type).all():
for m in self.object.machines.filter(is_working=True, type=machine_type):
slot = Slot.objects.filter(start_date=date, machine=m).first()
if slot is None:
self.machines[type] = m
self.machines[machine_type] = m
return True
return False

View File

@ -70,7 +70,7 @@ optional = true
version = "1.4.25"
[tool.ruff.lint]
select = ["I", "F401"]
select = ["I", "A", "F401", "E722"]
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "sith.settings"