photo-objects 0.5.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {photo_objects-0.5.0 → photo_objects-0.6.0}/PKG-INFO +1 -1
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/conf.py +10 -5
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/objsto.py +26 -2
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/api/photo.py +13 -4
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/img.py +7 -3
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects.egg-info/PKG-INFO +1 -1
- {photo_objects-0.5.0 → photo_objects-0.6.0}/pyproject.toml +1 -1
- {photo_objects-0.5.0 → photo_objects-0.6.0}/LICENSE +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/README.md +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/config.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/admin.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/api/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/api/album.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/api/auth.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/api/photo.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/api/utils.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/apps.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/context_processors.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/forms.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/management/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/management/commands/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/management/commands/clean-scaled-photos.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/management/commands/create-initial-admin-account.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/migrations/0001_initial.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/migrations/0002_created_at_updated_at.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/migrations/0003_admin_visibility.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/migrations/0004_camera_setup_and_settings.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/migrations/0005_sitesettings.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/migrations/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/models.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/signals.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/templatetags/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/templatetags/photo_objects_extras.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/tests/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/tests/test_album.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/tests/test_auth.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/tests/test_commands.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/tests/test_img.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/tests/test_photo.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/tests/test_utils.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/tests/utils.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/urls.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/api/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/api/album.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/api/auth.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/api/utils.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/ui/__init__.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/ui/album.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/ui/configuration.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/ui/photo.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/ui/users.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/ui/utils.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/views/utils.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/error.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/utils.py +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects.egg-info/SOURCES.txt +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects.egg-info/dependency_links.txt +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects.egg-info/requires.txt +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects.egg-info/top_level.txt +0 -0
- {photo_objects-0.5.0 → photo_objects-0.6.0}/setup.cfg +0 -0
|
@@ -30,20 +30,25 @@ class PhotoSizeDimensions:
|
|
|
30
30
|
max_width: int = None
|
|
31
31
|
max_height: int = None
|
|
32
32
|
max_aspect_ratio: float = None
|
|
33
|
+
image_format: str = None
|
|
33
34
|
|
|
34
35
|
|
|
35
36
|
DEFAULT_SM = dict(
|
|
36
37
|
max_width=512,
|
|
37
38
|
max_height=512,
|
|
38
|
-
max_aspect_ratio=1.5
|
|
39
|
+
max_aspect_ratio=1.5,
|
|
40
|
+
image_format='WEBP'
|
|
39
41
|
)
|
|
40
42
|
DEFAULT_MD = dict(
|
|
41
|
-
max_width=
|
|
42
|
-
max_height=
|
|
43
|
+
max_width=1024,
|
|
44
|
+
max_height=1024,
|
|
45
|
+
max_aspect_ratio=1.5,
|
|
46
|
+
image_format="JPEG"
|
|
43
47
|
)
|
|
44
48
|
DEFAULT_LG = dict(
|
|
45
|
-
max_width=
|
|
46
|
-
max_height=
|
|
49
|
+
max_width=2048,
|
|
50
|
+
max_height=2048,
|
|
51
|
+
image_format='WEBP'
|
|
47
52
|
)
|
|
48
53
|
|
|
49
54
|
|
|
@@ -2,6 +2,7 @@ from dataclasses import asdict
|
|
|
2
2
|
from io import BytesIO
|
|
3
3
|
import json
|
|
4
4
|
import mimetypes
|
|
5
|
+
import re
|
|
5
6
|
import urllib3
|
|
6
7
|
|
|
7
8
|
from minio import Minio, S3Error
|
|
@@ -60,8 +61,30 @@ def photo_path(album_key, photo_key, size_key):
|
|
|
60
61
|
return f"{size_key}/{album_key}/{photo_key}"
|
|
61
62
|
|
|
62
63
|
|
|
63
|
-
def
|
|
64
|
-
|
|
64
|
+
def _photo_filename(photo_key: str, image_format: str = None) -> str:
|
|
65
|
+
if image_format:
|
|
66
|
+
filename = re.sub(r'\.[^.]+$', '', photo_key)
|
|
67
|
+
return f"{filename}.{image_format.lower()}"
|
|
68
|
+
|
|
69
|
+
return photo_key
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def photo_content_headers(
|
|
73
|
+
photo_key: str,
|
|
74
|
+
image_format: str = None,
|
|
75
|
+
) -> tuple[str, dict[str, str]]:
|
|
76
|
+
filename = _photo_filename(photo_key, image_format)
|
|
77
|
+
|
|
78
|
+
content_type = mimetypes.guess_type(filename, strict=False)[0]
|
|
79
|
+
headers = {
|
|
80
|
+
"Content-Disposition": f"inline; filename={filename}"
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return content_type, headers
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def put_photo(album_key, photo_key, size_key, photo_file, image_format=None):
|
|
87
|
+
content_type, headers = photo_content_headers(photo_key, image_format)
|
|
65
88
|
|
|
66
89
|
client, bucket = _objsto_access()
|
|
67
90
|
return client.put_object(
|
|
@@ -71,6 +94,7 @@ def put_photo(album_key, photo_key, size_key, photo_file):
|
|
|
71
94
|
length=-1,
|
|
72
95
|
part_size=10 * MEGABYTE,
|
|
73
96
|
content_type=content_type,
|
|
97
|
+
metadata=headers
|
|
74
98
|
)
|
|
75
99
|
|
|
76
100
|
|
|
@@ -91,14 +91,23 @@ def get_img(request: HttpRequest, album_key: str, photo_key: str):
|
|
|
91
91
|
404 if code == "NoSuchKey" else 500,
|
|
92
92
|
).json_response
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
size_params = getattr(photo_sizes(), size)
|
|
95
95
|
# TODO: handle error
|
|
96
96
|
scaled_photo = scale_photo(
|
|
97
|
-
original_photo, photo_key, **asdict(
|
|
97
|
+
original_photo, photo_key, **asdict(size_params))
|
|
98
98
|
|
|
99
99
|
# TODO: handle error
|
|
100
100
|
scaled_photo.seek(0)
|
|
101
|
-
objsto.put_photo(
|
|
101
|
+
objsto.put_photo(
|
|
102
|
+
album_key,
|
|
103
|
+
photo_key,
|
|
104
|
+
size,
|
|
105
|
+
scaled_photo,
|
|
106
|
+
size_params.image_format)
|
|
107
|
+
|
|
108
|
+
content_type, headers = objsto.photo_content_headers(
|
|
109
|
+
photo_key, size_params.image_format)
|
|
102
110
|
|
|
103
111
|
scaled_photo.seek(0)
|
|
104
|
-
return HttpResponse(
|
|
112
|
+
return HttpResponse(
|
|
113
|
+
scaled_photo.read(), content_type=content_type, headers=headers)
|
|
@@ -66,7 +66,10 @@ def _read_camera_setup_and_settings(image: Image) -> dict:
|
|
|
66
66
|
raise e
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
def _image_format(filename):
|
|
69
|
+
def _image_format(image_format, filename):
|
|
70
|
+
if image_format:
|
|
71
|
+
return image_format
|
|
72
|
+
|
|
70
73
|
image_format = filename.split('.')[-1].upper()
|
|
71
74
|
|
|
72
75
|
if image_format == "JPG":
|
|
@@ -131,7 +134,8 @@ def scale_photo(
|
|
|
131
134
|
filename,
|
|
132
135
|
max_width=None,
|
|
133
136
|
max_height=None,
|
|
134
|
-
max_aspect_ratio=None
|
|
137
|
+
max_aspect_ratio=None,
|
|
138
|
+
image_format=None):
|
|
135
139
|
image = Image.open(photo_file)
|
|
136
140
|
width, height = image.size
|
|
137
141
|
|
|
@@ -164,5 +168,5 @@ def scale_photo(
|
|
|
164
168
|
resized = image.resize(new_size, Image.Resampling.LANCZOS)
|
|
165
169
|
|
|
166
170
|
b = BytesIO()
|
|
167
|
-
resized.save(b, _image_format(filename))
|
|
171
|
+
resized.save(b, _image_format(image_format, filename))
|
|
168
172
|
return b
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/management/commands/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/migrations/0003_admin_visibility.py
RENAMED
|
File without changes
|
|
File without changes
|
{photo_objects-0.5.0 → photo_objects-0.6.0}/photo_objects/django/migrations/0005_sitesettings.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|