Skip to content

Commit

Permalink
🚨 fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
krmax44 committed Sep 16, 2024
1 parent 609bd04 commit b458f10
Show file tree
Hide file tree
Showing 85 changed files with 356 additions and 365 deletions.
2 changes: 1 addition & 1 deletion froide/account/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Meta:
def get_full_name(self, obj: Union[User, SimpleLazyObject]) -> str:
return obj.get_full_name()

def profile_photo(self, obj):
def get_profile_photo(self, obj):
if obj.profile_photo:
return obj.profile_photo.url
return None
Expand Down
8 changes: 3 additions & 5 deletions froide/account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _create_user(
password: str,
is_staff: bool,
is_superuser: bool,
**extra_fields
**extra_fields,
):
"""
Creates and saves a User with the given email and password.
Expand All @@ -89,7 +89,7 @@ def _create_user(
is_superuser=is_superuser,
last_login=None,
date_joined=now,
**extra_fields
**extra_fields,
)
user.set_password(password)
user.save(using=self._db)
Expand Down Expand Up @@ -356,9 +356,7 @@ class Application(AbstractApplication):
def allows_grant_type(self, *grant_types):
# only allow GRANT_AUTHORIZATION_CODE
# regardless of application setting
return bool(
set([AbstractApplication.GRANT_AUTHORIZATION_CODE]) & set(grant_types)
)
return bool({AbstractApplication.GRANT_AUTHORIZATION_CODE} & set(grant_types))

def can_auto_approve(self, scopes):
"""
Expand Down
53 changes: 26 additions & 27 deletions froide/account/templates/account/admin_send_mail.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,30 @@
<form action="" method="post">
{% csrf_token %}
<div>
<label>
{% trans "Subject" %}:
<input type="text" name="subject" value="" />
</label>
<textarea name="body" rows="8" style="width: 100%">{% include "emails/footer.txt" %}</textarea>
<br />
<small>{% trans "You can use the following placeholders:" %} <code>{name}, {first_name}, {last_name}, {url}</code></small>
<input type="hidden" name="action" value="send_mail" />
<p>
<label>
{% trans "Subject" %}:
<input type="text" name="subject" value="" />
</p>
<textarea name="body" rows="8" style="width: 100%">{% include "emails/footer.txt" %}</textarea>
<br />
<small>{% trans "You can use the following placeholders:" %} <code>{name}, {first_name}, {last_name}, {url}</code></small>
<input type="hidden" name="action" value="send_mail" />
<p>
<input type="submit"
value="{% blocktrans count count=queryset.count %}Send mail to one user{% plural %}Send mail to {{ count }} users{% endblocktrans %}" />
</p>
</div>
<input type="hidden" name="action" value="{{ action_name }}" />
{% if select_across %}
<input type="hidden" name="select_across" value="1" />
{# set invalid selected, so confirmation action path is chosen in admin #}
<input type="hidden" name="{{ action_checkbox_name }}" value="_" />
{% else %}
{% for obj in queryset %}
<input type="hidden"
name="{{ action_checkbox_name }}"
value="{{ obj.pk|unlocalize }}" />
{% endfor %}
{% endif %}
</form>
{% endblock %}
<input type="submit"
value="{% blocktrans count count=queryset.count %}Send mail to one user{% plural %}Send mail to {{ count }} users{% endblocktrans %}" />
</p>
</div>
<input type="hidden" name="action" value="{{ action_name }}" />
{% if select_across %}
<input type="hidden" name="select_across" value="1" />
{# set invalid selected, so confirmation action path is chosen in admin #}
<input type="hidden" name="{{ action_checkbox_name }}" value="_" />
{% else %}
{% for obj in queryset %}
<input type="hidden"
name="{{ action_checkbox_name }}"
value="{{ obj.pk|unlocalize }}" />
{% endfor %}
{% endif %}
</form>
{% endblock %}
1 change: 1 addition & 0 deletions froide/account/templates/account/includes/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<nav class="container" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
{# djlint:off D018 #}
<a href="/">
<i class="fa fa-home"></i>
<span class="sr-only">{% trans "Home Page" %}</span>
Expand Down
17 changes: 9 additions & 8 deletions froide/account/templates/account/reauth.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ <h5>{% translate "Use your password" %}</h5>
</form>
</li>
{% endif %}
</div>
</ul>
</div>
</div>
</div>
{% endblock body %}
{% block scripts %}
{{ block.super }}
<script src="{% static 'account/cbor.js' %}"></script>
<script src="{% static 'mfa/fido2.js' %}"></script>
<script async src="{% static 'account/mfa.js' %}"></script>
{% endblock %}
</div>
{% endblock body %}
{% block scripts %}
{{ block.super }}
<script src="{% static 'account/cbor.js' %}"></script>
<script src="{% static 'mfa/fido2.js' %}"></script>
<script async src="{% static 'account/mfa.js' %}"></script>
{% endblock %}
4 changes: 2 additions & 2 deletions froide/account/tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ def test_go(world, client):

# Try logging in via link: wrong user id
autologin = reverse(
"account-go", kwargs=dict(user_id="80000", token="a" * 32, url=test_url)
"account-go", kwargs={"user_id": "80000", "token": "a" * 32, "url": test_url}
)
response = client.post(autologin)
assert response.status_code == 302
Expand All @@ -552,7 +552,7 @@ def test_go(world, client):
# Try logging in via link: wrong secret
autologin = reverse(
"account-go",
kwargs=dict(user_id=str(user.id), token="a" * 32, url=test_url),
kwargs={"user_id": str(user.id), "token": "a" * 32, "url": test_url},
)
response = client.post(autologin)
assert response.status_code == 302
Expand Down
4 changes: 2 additions & 2 deletions froide/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ def dispatch(self, *args, **kwargs):
def get_form_kwargs(self) -> Dict[str, Any]:
kwargs = super().get_form_kwargs()
kwargs["request"] = self.request
self.mfa_methods = set(
self.mfa_methods = {
x["method"] for x in list_mfa_methods(self.request.user)
) - {"recovery"}
} - {"recovery"}
kwargs["mfa_methods"] = self.mfa_methods
return kwargs

Expand Down
5 changes: 3 additions & 2 deletions froide/bounce/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
https://en.wikipedia.org/wiki/Variable_envelope_return_path
"""

import base64
import datetime
import time
Expand Down Expand Up @@ -206,7 +207,7 @@ def process_unsubscribe_mail(mail_bytes):
with closing(BytesIO(mail_bytes)) as stream:
email = parse_email(stream)
recipient_list = list(
set([get_recipient_address_from_unsubscribe(x.email) for x in email.to])
{get_recipient_address_from_unsubscribe(x.email) for x in email.to}
)
if len(recipient_list) != 1:
return
Expand Down Expand Up @@ -234,7 +235,7 @@ def process_bounce_mail(mail_bytes):


def add_bounce_mail(email):
recipient_list = set([get_recipient_address_from_bounce(x.email) for x in email.to])
recipient_list = {get_recipient_address_from_bounce(x.email) for x in email.to}
for recipient, status in recipient_list:
if status:
update_bounce(email, recipient)
Expand Down
14 changes: 7 additions & 7 deletions froide/comments/templates/froide_comments/comment.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
<a href="#more-commenttext-{{ comment.id }}"
class="hideparent"
data-bs-toggle="collapse">{% trans "Read all" %}</a></span>
<span id="more-commenttext-{{ comment.id }}" class="collapse">{{ comment.comment|urlizetrunc:40|linebreaksbr }}</span>
{% else %}
{{ comment.comment|urlizetrunc:40|linebreaksbr }}
{% endif %}
<span id="more-commenttext-{{ comment.id }}" class="collapse">{{ comment.comment|urlizetrunc:40|linebreaksbr }}</span>
{% else %}
{{ comment.comment|urlizetrunc:40|linebreaksbr }}
{% endif %}
</div>
{% endif %}
</div>
{% endif %}
</div>
{% endif %}
</div>
11 changes: 6 additions & 5 deletions froide/comments/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def test_constructor(self):
# Check if signals are called once with correct parameters
def test_ready(self):
comment_config = apps.get_app_config("comments")
with patch(
"froide.account.account_canceled.connect"
) as account_canceled_connect, patch(
"froide.account.account_merged.connect"
) as account_merged_connect:
with (
patch(
"froide.account.account_canceled.connect"
) as account_canceled_connect,
patch("froide.account.account_merged.connect") as account_merged_connect,
):
comment_config.ready()
account_canceled_connect.assert_called_once_with(cancel_user)
account_merged_connect.assert_called_once_with(merge_user)
3 changes: 2 additions & 1 deletion froide/document/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
AbstractDocument,
AbstractDocumentCollection,
CollectionDocument,
Page,
get_page_image_filename,
)
from filingcabinet.models import (
DocumentCollectionManager as FCDocumentCollectionManager,
)
from filingcabinet.models import DocumentManager as FCDocumentManager
from filingcabinet.models import Page, get_page_image_filename

from froide.helper.auth import (
can_read_object_authenticated,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<textarea rows="8" class="form-control mb-3" name="description">{{ object.description }}</textarea>
{% endblock %}
{% block saveurl %}
{% url 'document-set_description' pk=object.pk %}{% endblock %}
{% block autofocus %}[name='description']{% endblock %}
{% url 'document-set_description' pk=object.pk %}
{% endblock %}
{% block autofocus %}[name='description']{% endblock %}
7 changes: 4 additions & 3 deletions froide/document/templates/filingcabinet/_set_title_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
value="{{ object.title }}">
{% endblock %}
{% block fromclasses %}{{ block.super }} d-flex{% endblock %}
{% block saveurl %}
{% url 'document-set_title' pk=object.pk %}{% endblock %}
{% block autofocus %}[name='title']{% endblock %}
{% block saveurl %}
{% url 'document-set_title' pk=object.pk %}
{% endblock %}
{% block autofocus %}[name='title']{% endblock %}
6 changes: 3 additions & 3 deletions froide/foirequest/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,9 @@ def download_eml(self, request, pk):
message.as_mime_message().as_bytes(),
content_type="application/octet-stream",
)
response[
"Content-Disposition"
] = 'attachment; filename="message-{}.eml"'.format(message.id)
response["Content-Disposition"] = (
'attachment; filename="message-{}.eml"'.format(message.id)
)
return response

@admin.action(description=_("Mark as not sent"))
Expand Down
2 changes: 1 addition & 1 deletion froide/foirequest/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def make_filter(slug, url_part, filter_func, key):
]

FOIREQUEST_FILTER_CHOICES = [(x.slug, x.label) for x in FOIREQUEST_FILTERS]
REVERSE_FILTER_DICT = dict([(str(x.key), x) for x in FOIREQUEST_FILTERS])
REVERSE_FILTER_DICT = {str(x.key): x for x in FOIREQUEST_FILTERS}

FOIREQUEST_LIST_FILTER_CHOICES = [
x
Expand Down
6 changes: 3 additions & 3 deletions froide/foirequest/forms/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def get_send_message_form(*args, **kwargs):
foirequest=foirequest,
prefix="sendmessage",
initial={"subject": subject, "message": message},
**kwargs
**kwargs,
)


Expand Down Expand Up @@ -420,7 +420,7 @@ def get_escalation_message_form(*args, **kwargs):
"name": foirequest.user.get_full_name(),
},
),
}
},
)


Expand Down Expand Up @@ -807,7 +807,7 @@ def clean_field(self, field):
try:
val = [int(x) for x in val.split(",")]
except ValueError:
raise forms.ValidationError("Bad value")
raise forms.ValidationError("Bad value") from None
return val

def clean_subject(self):
Expand Down
2 changes: 1 addition & 1 deletion froide/foirequest/forms/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, *args, **kwargs):
# Skip super class
super(FoiRequestStatusForm, self).__init__(*args, **kwargs)
refusal_choices = []
same_law = len(set(f.law_id for f in self.foirequests)) == 1
same_law = len({f.law_id for f in self.foirequests}) == 1
# Get prototypical requests
foirequest = self.foirequests[0]
if same_law and foirequest.law:
Expand Down
6 changes: 3 additions & 3 deletions froide/foirequest/forms/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def clean_suggestion(self):
try:
self.publicbody = PublicBody.objects.get(pk=pb_pk)
except PublicBody.DoesNotExist:
raise forms.ValidationError(_("Missing or invalid input!"))
raise forms.ValidationError(_("Missing or invalid input!")) from None
return pb_pk

def clean(self):
Expand Down Expand Up @@ -389,7 +389,7 @@ def __init__(self, *args, **kwargs):
)

def clean(self):
indexed_laws = dict([(law.pk, law) for law in self.possible_laws])
indexed_laws = {law.pk: law for law in self.possible_laws}
if "law" not in self.cleaned_data:
return
if self.cleaned_data["law"]:
Expand Down Expand Up @@ -464,7 +464,7 @@ def clean_description(self):
try:
val = [int(x) for x in val.split(",")]
except ValueError:
raise forms.ValidationError("Bad value")
raise forms.ValidationError("Bad value") from None
return val

def save(self, request: HttpRequest, foirequest: FoiRequest):
Expand Down
2 changes: 1 addition & 1 deletion froide/foirequest/management/commands/fetch_foi_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def handle(self, *args, **options):
try:
count = fetch_and_process()
except Exception as e:
raise CommandError("Fetch raised an error: %s" % e)
raise CommandError("Fetch raised an error: %s" % e) from e
self.stdout.write(
"Successfully fetched and processed %(count)d mails\n" % {"count": count}
)
10 changes: 5 additions & 5 deletions froide/foirequest/message_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ def run_send(self, **kwargs):
from_addr,
[message.recipient_email.strip()],
attachments=attachments,
**extra_kwargs
**extra_kwargs,
)

message.sent = True
message.save()

DeliveryStatus.objects.update_or_create(
message=message,
defaults=dict(
status=DeliveryStatus.Delivery.STATUS_SENDING,
last_update=timezone.now(),
),
defaults={
"status": DeliveryStatus.Delivery.STATUS_SENDING,
"last_update": timezone.now(),
},
)
Loading

0 comments on commit b458f10

Please sign in to comment.