mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
ruff rule A
This commit is contained in:
@ -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:
|
||||
|
@ -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 []
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 (
|
||||
|
Reference in New Issue
Block a user