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( for sat in [None] + list(
SimplifiedAccountingType.objects.order_by("label").all() SimplifiedAccountingType.objects.order_by("label").all()
): ):
sum = queryset.filter( amount = queryset.filter(
accounting_type__movement_type=movement_type, simpleaccounting_type=sat accounting_type__movement_type=movement_type, simpleaccounting_type=sat
).aggregate(amount_sum=Sum("amount"))["amount_sum"] ).aggregate(amount_sum=Sum("amount"))["amount_sum"]
if sat: if sat:
sat = sat.label sat = sat.label
else: else:
sat = "" sat = ""
if sum: if amount:
total_sum += sum total_sum += amount
statement[sat] = sum statement[sat] = amount
ret[movement_type] = statement ret[movement_type] = statement
ret[movement_type + "_sum"] = total_sum ret[movement_type + "_sum"] = total_sum
return ret return ret

View File

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

View File

@ -48,7 +48,7 @@ class ScssFinder(FileSystemFinder):
filesystem_storage.prefix = self.locations[0][0] filesystem_storage.prefix = self.locations[0][0]
self.storages[location] = filesystem_storage 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"): if path.endswith(".css"):
return super(ScssFinder, self).find(path, all) return super(ScssFinder, self).find(path, all)
return [] return []

View File

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

View File

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

View File

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

View File

@ -23,10 +23,10 @@ django.setup()
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = "Sith AE UTBM" project = "Sith AE UTBM"
copyright = ( copyright = ( # noqa A001
"2019, Bartuccio Antoine (Sli), Brunet Pierre (Krohpil), Jacquet Florent (Skia)" "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 --------------------------------------------------- # -- General configuration ---------------------------------------------------

View File

@ -116,13 +116,13 @@ class LaunderetteBookView(CanViewMixin, DetailView):
).save() ).save()
return super(LaunderetteBookView, self).get(request, *args, **kwargs) 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: if date is None:
date = self.date 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() slot = Slot.objects.filter(start_date=date, machine=m).first()
if slot is None: if slot is None:
self.machines[type] = m self.machines[machine_type] = m
return True return True
return False return False

View File

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