From 38873350be4ef7ac55dadfbbbeb0b43ea00c7268 Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 23 May 2024 09:31:56 +0200 Subject: [PATCH] feat: streamline user creation and improve code quality - Simplified user creation in OIDC backend by removing redundant model import. - Standardized quote usage for string literals across the codebase for consistency. - Expanded `__init__.py` files to explicitly list all module exports, enhancing project navigability and IDE support. - Fixed incorrect file object usage in PILStitcher, ensuring correct image handling. - Improved error handling in loader with explicit exception capture, aiding in debugging and maintenance. - Removed unused imports and simplified command classes for clarity and reduced complexity in command handling. - Initialized test suite structure to encourage future development of tests. This commit represents a broad sweep to tidy up the codebase, laying a stronger foundation for future features and improvements. --- src/pix360core/backends.py | 6 ++---- src/pix360core/classes/__init__.py | 17 ++++++++++++++++- src/pix360core/classes/stitching.py | 3 ++- src/pix360core/loader.py | 4 ++-- .../management/commands/installmodules.py | 4 +--- src/pix360core/management/commands/runworker.py | 10 +++------- src/pix360core/managers/__init__.py | 6 +++++- src/pix360core/models/__init__.py | 9 ++++++++- src/pix360core/models/auth.py | 1 - src/pix360core/tests.py | 6 +++++- src/pix360core/views.py | 2 +- 11 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/pix360core/backends.py b/src/pix360core/backends.py index dc50d85..e3f1e57 100644 --- a/src/pix360core/backends.py +++ b/src/pix360core/backends.py @@ -1,12 +1,10 @@ from mozilla_django_oidc.auth import OIDCAuthenticationBackend -from .models.auth import User - class OIDCBackend(OIDCAuthenticationBackend): def create_user(self, claims): - email = claims.get('email') + email = claims.get("email") return self.UserModel.objects.create_user(email) def get_username(self, claims): - return claims.get('email') \ No newline at end of file + return claims.get("email") diff --git a/src/pix360core/classes/__init__.py b/src/pix360core/classes/__init__.py index 90dab0e..cdd33d5 100644 --- a/src/pix360core/classes/__init__.py +++ b/src/pix360core/classes/__init__.py @@ -1,4 +1,19 @@ from .modules import BaseModule, DownloaderModule from .exceptions import DownloadError, StitchingError, ConversionError, InstallError from .http import HTTPRequest -from .stitching import BaseStitcher, PILStitcher, BlenderStitcher, DEFAULT_CUBEMAP_TO_EQUIRECTANGULAR_STITCHER, DEFAULT_STITCHER \ No newline at end of file +from .stitching import BaseStitcher, PILStitcher, BlenderStitcher, DEFAULT_CUBEMAP_TO_EQUIRECTANGULAR_STITCHER, DEFAULT_STITCHER + +__all__ = [ + 'BaseModule', + 'DownloaderModule', + 'DownloadError', + 'StitchingError', + 'ConversionError', + 'InstallError', + 'HTTPRequest', + 'BaseStitcher', + 'PILStitcher', + 'BlenderStitcher', + 'DEFAULT_CUBEMAP_TO_EQUIRECTANGULAR_STITCHER', + 'DEFAULT_STITCHER' +] \ No newline at end of file diff --git a/src/pix360core/classes/stitching.py b/src/pix360core/classes/stitching.py index 7ff1fc6..90adca7 100644 --- a/src/pix360core/classes/stitching.py +++ b/src/pix360core/classes/stitching.py @@ -13,6 +13,7 @@ import subprocess import io import logging import time +import math class BaseStitcher: """Base class for stitcher modules @@ -243,7 +244,7 @@ class PILStitcher(BaseStitcher): PIL.Image.frombytes("RGB", (t_width, t_height), bytes(raw)).save(bio, "PNG") bio.seek(0) - result = File.objects.create(conversion=files[0].conversion, file=ContentFile(output, name="result.png", mime_type="image/png")) + result = File.objects.create(conversion=files[0].conversion, file=ContentFile(bio, name="result.png", mime_type="image/png")) return result diff --git a/src/pix360core/loader.py b/src/pix360core/loader.py index 2875977..4251158 100644 --- a/src/pix360core/loader.py +++ b/src/pix360core/loader.py @@ -60,7 +60,7 @@ class Loader: for entry_point in importlib.metadata.entry_points().get("pix360downloader", []): try: downloaders.append(entry_point.load()) - except: - print(f"Something went wrong trying to import {entry_point}") + except Exception as e: + print(f"Something went wrong trying to import {entry_point}: {e}") return downloaders \ No newline at end of file diff --git a/src/pix360core/management/commands/installmodules.py b/src/pix360core/management/commands/installmodules.py index 9d8103f..eb26518 100644 --- a/src/pix360core/management/commands/installmodules.py +++ b/src/pix360core/management/commands/installmodules.py @@ -1,9 +1,7 @@ -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from ...installer import Installer -import logging - class Command(BaseCommand): help = 'Run the worker' diff --git a/src/pix360core/management/commands/runworker.py b/src/pix360core/management/commands/runworker.py index 64bb00a..e058f2a 100644 --- a/src/pix360core/management/commands/runworker.py +++ b/src/pix360core/management/commands/runworker.py @@ -1,15 +1,11 @@ -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand -from pix360core.models import Conversion, ConversionStatus from pix360core.worker import Worker -import logging - class Command(BaseCommand): - help = 'Run the worker' + help = "Run the worker" def handle(self, *args, **options): - """Handle the command - """ + """Handle the command""" worker = Worker() worker.run() diff --git a/src/pix360core/managers/__init__.py b/src/pix360core/managers/__init__.py index 7bcbdd8..a7b449e 100644 --- a/src/pix360core/managers/__init__.py +++ b/src/pix360core/managers/__init__.py @@ -1 +1,5 @@ -from .auth import UserManager \ No newline at end of file +from .auth import UserManager + +__all__ = [ + 'UserManager', +] \ No newline at end of file diff --git a/src/pix360core/models/__init__.py b/src/pix360core/models/__init__.py index 418175f..ec67cc3 100644 --- a/src/pix360core/models/__init__.py +++ b/src/pix360core/models/__init__.py @@ -1,2 +1,9 @@ from .auth import User -from .content import File, Conversion, ConversionStatus \ No newline at end of file +from .content import File, Conversion, ConversionStatus + +__all__ = [ + 'User', + 'File', + 'Conversion', + 'ConversionStatus', +] \ No newline at end of file diff --git a/src/pix360core/models/auth.py b/src/pix360core/models/auth.py index d6346fe..ad4c81c 100644 --- a/src/pix360core/models/auth.py +++ b/src/pix360core/models/auth.py @@ -1,6 +1,5 @@ from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin from django.db import models -from django.utils import timezone from ..managers import UserManager diff --git a/src/pix360core/tests.py b/src/pix360core/tests.py index 7ce503c..43f8181 100644 --- a/src/pix360core/tests.py +++ b/src/pix360core/tests.py @@ -1,3 +1,7 @@ from django.test import TestCase -# Create your tests here. +# TODO: Add some meaningful tests + +class Test(TestCase): + def test(self): + self.assertEqual(1, 1) \ No newline at end of file diff --git a/src/pix360core/views.py b/src/pix360core/views.py index 23f1486..e13f146 100644 --- a/src/pix360core/views.py +++ b/src/pix360core/views.py @@ -98,7 +98,7 @@ class ConversionResultView(LoginRequiredMixin, View): content = file.file.read() - response = HttpResponse(content, content_type=file.mime_type) + return HttpResponse(content, content_type=file.mime_type) class ConversionListView(LoginRequiredMixin, View): """View for getting the list of conversions