diff --git a/CHANGES b/CHANGES index a8809f3..f15930b 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,8 @@ ================== * Refactored upload logic out of view code * Added .avif image format. +* Clean up SignS3View method signatures +* Use timezone-aware datetime object in SignS3View 0.4.1 (2025-01-10) ================== diff --git a/s3sign/views.py b/s3sign/views.py index 1c03283..443b7e0 100644 --- a/s3sign/views.py +++ b/s3sign/views.py @@ -6,11 +6,10 @@ import boto3 -from datetime import datetime - from django.conf import settings from django.http import HttpResponse from django.views.generic import View +from django.utils import timezone from s3sign.utils import s3_config, upload_file @@ -59,34 +58,37 @@ def dispatch(self, request, *args, **kwargs): ) return super().dispatch(request, *args, **kwargs) - def get_name_field(self): + def get_name_field(self) -> str: return self.name_field - def get_type_field(self): + def get_type_field(self) -> str: return self.type_field def get_expiration_time(self): return self.expiration_time - def get_mime_type_extensions(self): + def get_mime_type_extensions(self) -> list: return self.mime_type_extensions - def get_default_extension(self): + def get_default_extension(self) -> str: return self.default_extension - def get_root(self): + def get_root(self) -> str: return self.root - def get_path_string(self): + def get_path_string(self) -> str: return self.path_string - def get_aws_access_key(self): + @staticmethod + def get_aws_access_key() -> str: return settings.AWS_ACCESS_KEY - def get_aws_secret_key(self): + @staticmethod + def get_aws_secret_key() -> str: return settings.AWS_SECRET_KEY - def get_bucket(self): + @staticmethod + def get_bucket() -> str: return settings.AWS_UPLOAD_BUCKET def get_mimetype(self, request): @@ -98,13 +100,16 @@ def extension_from_mimetype(self, mime_type): return ext return self.get_default_extension() - def now(self): - return datetime.now() + @staticmethod + def now(): + return timezone.now() - def now_time(self): + @staticmethod + def now_time(): return time.time() - def basename(self, request): + @staticmethod + def basename(): return str(uuid.uuid4()) def extension(self, request): @@ -112,7 +117,7 @@ def extension(self, request): def get_object_name(self, request): now = self.now() - basename = self.basename(request) + basename = self.basename() extension = self.extension(request) return self.get_path_string().format( now=now, basename=basename, extension=extension,