Skip to content

Commit a970a83

Browse files
committed
🚨(backend) fix linting issues after upgrading
The last upgrades introduced some linting issues. This commit fixes them.
1 parent 7babc46 commit a970a83

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+93
-41
lines changed

src/backend/core/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Admin classes and registrations for core app."""
2+
23
from django.contrib import admin
34
from django.contrib.auth import admin as auth_admin
45
from django.utils.translation import gettext_lazy as _

src/backend/core/api/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Impress core API endpoints"""
2+
23
from django.conf import settings
34
from django.core.exceptions import ValidationError
45

@@ -16,9 +17,9 @@ def exception_handler(exc, context):
1617
https://gist.github.com/twidi/9d55486c36b6a51bdcb05ce3a763e79f
1718
"""
1819
if isinstance(exc, ValidationError):
19-
if hasattr(exc, "message_dict"):
20-
detail = exc.message_dict
21-
elif hasattr(exc, "message"):
20+
detail = exc.message_dict
21+
22+
if hasattr(exc, "message"):
2223
detail = exc.message
2324
elif hasattr(exc, "messages"):
2425
detail = exc.messages

src/backend/core/api/fields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""A JSONField for DRF to handle serialization/deserialization."""
2+
23
import json
34

45
from rest_framework import serializers

src/backend/core/api/permissions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Permission handlers for the impress core app."""
2+
23
from django.core import exceptions
34

45
from rest_framework import permissions

src/backend/core/api/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Client serializers for the impress core app."""
2+
23
from django.db.models import Q
34
from django.utils.translation import gettext_lazy as _
45

src/backend/core/api/viewsets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""API endpoints"""
2+
23
from django.contrib.postgres.aggregates import ArrayAgg
34
from django.db.models import (
45
OuterRef,

src/backend/core/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Core application enums declaration
33
"""
4+
45
from django.conf import global_settings, settings
56
from django.utils.translation import gettext_lazy as _
67

src/backend/core/factories.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"""
33
Core application factories
44
"""
5+
56
from django.conf import settings
67
from django.contrib.auth.hashers import make_password
78

src/backend/core/models.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Declare and configure the models for the impress core application
33
"""
4+
45
import hashlib
56
import os
67
import tempfile
@@ -316,6 +317,29 @@ class Meta:
316317
def __str__(self):
317318
return self.title
318319

320+
def save(self, *args, **kwargs):
321+
"""Write content to object storage only if _content has changed."""
322+
super().save(*args, **kwargs)
323+
324+
if self._content:
325+
file_key = self.file_key
326+
bytes_content = self._content.encode("utf-8")
327+
328+
if default_storage.exists(file_key):
329+
response = default_storage.connection.meta.client.head_object(
330+
Bucket=default_storage.bucket_name, Key=file_key
331+
)
332+
has_changed = (
333+
response["ETag"].strip('"')
334+
!= hashlib.md5(bytes_content).hexdigest() # noqa
335+
)
336+
else:
337+
has_changed = True
338+
339+
if has_changed:
340+
content_file = ContentFile(bytes_content)
341+
default_storage.save(file_key, content_file)
342+
319343
@property
320344
def key_base(self):
321345
"""Key base of the location where the document is stored in object storage."""
@@ -356,28 +380,6 @@ def get_content_response(self, version_id=""):
356380
Bucket=default_storage.bucket_name, Key=self.file_key, VersionId=version_id
357381
)
358382

359-
def save(self, *args, **kwargs):
360-
"""Write content to object storage only if _content has changed."""
361-
super().save(*args, **kwargs)
362-
363-
if self._content:
364-
file_key = self.file_key
365-
bytes_content = self._content.encode("utf-8")
366-
367-
if default_storage.exists(file_key):
368-
response = default_storage.connection.meta.client.head_object(
369-
Bucket=default_storage.bucket_name, Key=file_key
370-
)
371-
has_changed = (
372-
response["ETag"].strip('"')
373-
!= hashlib.md5(bytes_content).hexdigest() # noqa
374-
)
375-
else:
376-
has_changed = True
377-
if has_changed:
378-
content_file = ContentFile(bytes_content)
379-
default_storage.save(file_key, content_file)
380-
381383
def get_versions_slice(
382384
self, from_version_id="", from_datetime=None, page_size=None
383385
):

src/backend/core/tests/authentication/test_backends.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ def get_userinfo_mocked(*args):
9292

9393
monkeypatch.setattr(OIDCAuthenticationBackend, "get_userinfo", get_userinfo_mocked)
9494

95-
with django_assert_num_queries(0), pytest.raises(
96-
SuspiciousOperation,
97-
match="User info contained no recognizable user identification",
95+
with (
96+
django_assert_num_queries(0),
97+
pytest.raises(
98+
SuspiciousOperation,
99+
match="User info contained no recognizable user identification",
100+
),
98101
):
99102
klass.get_or_create_user(access_token="test-token", id_token=None, payload=None)
100103

0 commit comments

Comments
 (0)