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.
This commit is contained in:
Kumi 2024-05-23 09:31:56 +02:00
parent 2acf8501b4
commit 38873350be
Signed by: kumi
GPG key ID: ECBCC9082395383F
11 changed files with 45 additions and 23 deletions

View file

@ -1,12 +1,10 @@
from mozilla_django_oidc.auth import OIDCAuthenticationBackend from mozilla_django_oidc.auth import OIDCAuthenticationBackend
from .models.auth import User
class OIDCBackend(OIDCAuthenticationBackend): class OIDCBackend(OIDCAuthenticationBackend):
def create_user(self, claims): def create_user(self, claims):
email = claims.get('email') email = claims.get("email")
return self.UserModel.objects.create_user(email) return self.UserModel.objects.create_user(email)
def get_username(self, claims): def get_username(self, claims):
return claims.get('email') return claims.get("email")

View file

@ -2,3 +2,18 @@ from .modules import BaseModule, DownloaderModule
from .exceptions import DownloadError, StitchingError, ConversionError, InstallError from .exceptions import DownloadError, StitchingError, ConversionError, InstallError
from .http import HTTPRequest from .http import HTTPRequest
from .stitching import BaseStitcher, PILStitcher, BlenderStitcher, DEFAULT_CUBEMAP_TO_EQUIRECTANGULAR_STITCHER, DEFAULT_STITCHER 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'
]

View file

@ -13,6 +13,7 @@ import subprocess
import io import io
import logging import logging
import time import time
import math
class BaseStitcher: class BaseStitcher:
"""Base class for stitcher modules """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") PIL.Image.frombytes("RGB", (t_width, t_height), bytes(raw)).save(bio, "PNG")
bio.seek(0) 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 return result

View file

@ -60,7 +60,7 @@ class Loader:
for entry_point in importlib.metadata.entry_points().get("pix360downloader", []): for entry_point in importlib.metadata.entry_points().get("pix360downloader", []):
try: try:
downloaders.append(entry_point.load()) downloaders.append(entry_point.load())
except: except Exception as e:
print(f"Something went wrong trying to import {entry_point}") print(f"Something went wrong trying to import {entry_point}: {e}")
return downloaders return downloaders

View file

@ -1,9 +1,7 @@
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand
from ...installer import Installer from ...installer import Installer
import logging
class Command(BaseCommand): class Command(BaseCommand):
help = 'Run the worker' help = 'Run the worker'

View file

@ -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 from pix360core.worker import Worker
import logging
class Command(BaseCommand): class Command(BaseCommand):
help = 'Run the worker' help = "Run the worker"
def handle(self, *args, **options): def handle(self, *args, **options):
"""Handle the command """Handle the command"""
"""
worker = Worker() worker = Worker()
worker.run() worker.run()

View file

@ -1 +1,5 @@
from .auth import UserManager from .auth import UserManager
__all__ = [
'UserManager',
]

View file

@ -1,2 +1,9 @@
from .auth import User from .auth import User
from .content import File, Conversion, ConversionStatus from .content import File, Conversion, ConversionStatus
__all__ = [
'User',
'File',
'Conversion',
'ConversionStatus',
]

View file

@ -1,6 +1,5 @@
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.db import models from django.db import models
from django.utils import timezone
from ..managers import UserManager from ..managers import UserManager

View file

@ -1,3 +1,7 @@
from django.test import TestCase from django.test import TestCase
# Create your tests here. # TODO: Add some meaningful tests
class Test(TestCase):
def test(self):
self.assertEqual(1, 1)

View file

@ -98,7 +98,7 @@ class ConversionResultView(LoginRequiredMixin, View):
content = file.file.read() content = file.file.read()
response = HttpResponse(content, content_type=file.mime_type) return HttpResponse(content, content_type=file.mime_type)
class ConversionListView(LoginRequiredMixin, View): class ConversionListView(LoginRequiredMixin, View):
"""View for getting the list of conversions """View for getting the list of conversions