Skip to content

Commit

Permalink
🚨 fix linter warnings, reformat with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
krmax44 committed Sep 16, 2024
1 parent 04cd50d commit 98b1280
Show file tree
Hide file tree
Showing 21 changed files with 283 additions and 315 deletions.
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

Expand Down
1 change: 0 additions & 1 deletion src/fc_project/templates/_frontend.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{% load static %}

<script type="module" src="{% static 'entry.js' %}"></script>
<link rel="stylesheet" href="{% static 'css/entry.css' %}">
29 changes: 16 additions & 13 deletions src/fc_project/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{% endblock %}</title>
{% block css %}{% endblock %}
</head>
<body>
<main>{% block body %}{% endblock %}</main>

{% block scripts %}
{% include "_frontend.html" with entry_point="filingcabinet.js" %}
{% endblock %}
</body>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
{% block title %}{% endblock %}
</title>
{% block css %}{% endblock %}
</head>
<body>
<main>
{% block body %}{% endblock %}
</main>
{% block scripts %}
{% include "_frontend.html" with entry_point="filingcabinet.js" %}
{% endblock %}
</body>
</html>
6 changes: 4 additions & 2 deletions src/filingcabinet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def get_model(model_name):
try:
return django_apps.get_model(model_name, require_ready=False)
except ValueError:
raise ImproperlyConfigured("setting must be of the form 'app_label.model_name'")
raise ImproperlyConfigured(
"setting must be of the form 'app_label.model_name'"
) from None
except LookupError:
raise ImproperlyConfigured(
"setting refers to model '%s' that has not been installed" % (model_name)
)
) from None
4 changes: 1 addition & 3 deletions src/filingcabinet/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def make_oembed_response(request, model):
"html": """
<iframe style="width:{width};border:0;height:{height}"
src="{url}?maxHeight={height}"></iframe>
""".format(
url=iframe_url, height=height, width=width
).strip(),
""".format(url=iframe_url, height=height, width=width).strip(),
}
)

Expand Down
16 changes: 8 additions & 8 deletions src/filingcabinet/pdf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ def try_reading_pdf(pdf_file, password=None):
try:
pdf_reader = PdfReader(pdf_file, strict=False)
except (PdfReadError, ValueError, OSError) as e:
raise PDFException(e, "rewrite")
raise PDFException(e, "rewrite") from None

if pdf_reader.is_encrypted:
raise PDFException(None, "decrypt")
raise PDFException(None, "decrypt") from None

try:
# Try reading number of pages
len(pdf_reader.pages)
except KeyError as e: # catch KeyError '/Pages'
raise PDFException(e, "rewrite")
raise PDFException(e, "rewrite") from None
except ValueError as e: # catch invalid literal for int() with base 10
raise PDFException(e, "rewrite")
raise PDFException(e, "rewrite") from None
except RecursionError as e: # catch RecursionError in pypdf
raise PDFException(e, "rewrite")
raise PDFException(e, "rewrite") from None
except PdfReadError as e:
raise PDFException(e, "decrypt")
raise PDFException(e, "decrypt") from None
return pdf_reader


Expand All @@ -98,7 +98,7 @@ def get_readable_pdf(pdf_file, copy_func, password=None):
pdf_file = copy_func(pdf_file)
tries += 1
if tries > 2:
raise Exception("PDF Redaction Error")
raise Exception("PDF Redaction Error") from None
if e.reason == "rewrite":
next_pdf_file = rewrite_pdf_in_place(
pdf_file, password=password, timeout=timeout
Expand All @@ -112,7 +112,7 @@ def get_readable_pdf(pdf_file, copy_func, password=None):
pdf_file, password=password, timeout=timeout
)
if next_pdf_file is None:
raise Exception("PDF Rewrite Error")
raise Exception("PDF Rewrite Error") from None
pdf_file = next_pdf_file


Expand Down
2 changes: 1 addition & 1 deletion src/filingcabinet/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def trigger():


class DocumentStorer:
ZIP_BLOCK_LIST = set(["__MACOSX"])
ZIP_BLOCK_LIST = {"__MACOSX"}

def __init__(self, user, public=False, collection=None, tags=None):
self.user = user
Expand Down
4 changes: 3 additions & 1 deletion src/filingcabinet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
)

FILINGCABINET_PAGE_PROCESSING_TIMEOUT = getattr(
settings, "FILINGCABINET_PAGE_PROCESSING_TIMEOUT", 4 * 60 # 4 minutes
settings,
"FILINGCABINET_PAGE_PROCESSING_TIMEOUT",
4 * 60, # 4 minutes
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{% extends "admin/change_list.html" %}
{% load i18n %}

{% block content %}
{{ block.super }}
<div>
<form enctype="multipart/form-data" method="post" action="{% url 'admin:filingcabinet-document-upload' %}">
{% csrf_token %}
<input type="file" name="file" accept="application/pdf" multiple/>
<input type="submit" value="{% blocktrans with cl.opts.verbose_name_plural as name %}Import {{ name }}{% endblocktrans %}"/>
</form>
</div>
{{ block.super }}
<div>
<form enctype="multipart/form-data"
method="post"
action="{% url 'admin:filingcabinet-document-upload' %}">
{% csrf_token %}
<input type="file" name="file" accept="application/pdf" multiple />
<input type="submit"
value="{% blocktrans with cl.opts.verbose_name_plural as name %}Import {{ name }}{% endblocktrans %}" />
</form>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
{% extends "admin/change_form.html" %}

{% load static %}
{% load i18n %}

{% block extrahead %}{{ block.super }}
{% block extrahead %}
{{ block.super }}
<script src="{% static 'filingcabinet/admin/pageannotation.js' %}"></script>
{% endblock %}

{% block after_field_sets %}
{% if original.image %}
<img src="{{ original.image.url }}" style="max-width: 100%">
<img alt="" src="{{ original.image.url }}" style="max-width: 100%">
{% endif %}
{% if original and original.page and original.image %}
<h3>{% trans "Annotation" %}</h3>
<input type="color" id="annotationcolor" value="#ffff88"/>
<input type="color" id="annotationcolor" value="#ffff88" />
<div style="position:relative; width: 100%">
<img src="{{ original.image.url }}" id="annotation_image" style="outline: 1px solid #000; width: 100%;">
<img src="{{ original.image.url }}"
alt=""
id="annotation_image"
style="outline: 1px solid #000;
width: 100%">
</div>
{% endif %}

{% if original and original.page %}
<h3>{% trans "Make annotation" %}</h3>
<div style="position:relative; width: 100%">
<img src="{{ original.page.image.url }}" id="page_image" style="outline: 1px solid #000; width: 100%;">
<div id="page_rect" style="outline: 1px solid #f00; position: absolute; pointer-events: none;"></div>
<img src="{{ original.page.image.url }}"
alt=""
id="page_image"
style="outline: 1px solid #000;
width: 100%">
<div id="page_rect"
style="outline: 1px solid #f00;
position: absolute;
pointer-events: none"></div>
</div>
{% endif %}
{% endblock %}
Loading

0 comments on commit 98b1280

Please sign in to comment.