photo-objects 0.9.4__py3-none-any.whl → 0.9.6__py3-none-any.whl

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.
@@ -50,7 +50,7 @@ class JsonProblem(PhotoObjectsError):
50
50
  return render(request, "photo_objects/problem.html", {
51
51
  "title": "Error",
52
52
  "back": BackLink(
53
- 'Back to albums',
53
+ 'Albums',
54
54
  reverse_lazy('photo_objects:list_albums')),
55
55
  "problem_title": self.title,
56
56
  "status": self.status
@@ -56,8 +56,9 @@ class TestUtils(TestCase):
56
56
  "Plain text description"),
57
57
  (md_multi_p,
58
58
  "Description with bold and italics..."),
59
- (None,
60
- "A simple self-hosted photo server."),
59
+ # TODO: Test default description and description from site-settings
60
+ # (None,
61
+ # "A simple self-hosted photo server."),
61
62
  ]
62
63
 
63
64
  for description, expected in testdata:
@@ -9,11 +9,12 @@ from photo_objects.django.forms import CreateAlbumForm, ModifyAlbumForm
9
9
  from photo_objects.django.models import Album
10
10
  from photo_objects.django.views.utils import (
11
11
  BackLink,
12
+ Preview,
12
13
  meta_description,
13
14
  )
14
15
  from photo_objects.utils import render_markdown
15
16
 
16
- from .utils import json_problem_as_html
17
+ from .utils import json_problem_as_html, preview_helptext
17
18
 
18
19
 
19
20
  @json_problem_as_html
@@ -40,12 +41,13 @@ def new_album(request: HttpRequest):
40
41
  else:
41
42
  form = CreateAlbumForm(initial={"key": "_new"}, user=request.user)
42
43
 
43
- back = BackLink("Back to albums", reverse('photo_objects:list_albums'))
44
+ back = BackLink("Albums", reverse('photo_objects:list_albums'))
44
45
 
45
46
  return render(request, 'photo_objects/form.html', {
46
47
  "form": form,
47
48
  "title": "Create album",
48
49
  "back": back,
50
+ "width": "narrow",
49
51
  })
50
52
 
51
53
 
@@ -59,7 +61,7 @@ def show_album(request: HttpRequest, album_key: str):
59
61
  album = api.check_album_access(request, album_key)
60
62
  photos = album.photo_set.all()
61
63
 
62
- back = BackLink("Back to albums", reverse('photo_objects:list_albums'))
64
+ back = BackLink("Albums", reverse('photo_objects:list_albums'))
63
65
  details = {
64
66
  "Description": render_markdown(album.description),
65
67
  "Visibility": Album.Visibility(album.visibility).label,
@@ -102,18 +104,24 @@ def edit_album(request: HttpRequest, album_key: str):
102
104
 
103
105
  target = album.title or album.key
104
106
  back = BackLink(
105
- f'Back to {target}',
107
+ target,
106
108
  reverse(
107
109
  'photo_objects:show_album',
108
110
  kwargs={"album_key": album_key}))
109
111
 
110
- return render(request, 'photo_objects/form.html', {
111
- "form": form,
112
- "title": "Edit album",
113
- "back": back,
114
- "photo": album.cover_photo,
115
- "info": get_info(request, album_key),
116
- })
112
+ return render(
113
+ request,
114
+ 'photo_objects/form.html',
115
+ {
116
+ "form": form,
117
+ "title": "Edit album",
118
+ "back": back,
119
+ "info": get_info(
120
+ request,
121
+ album_key),
122
+ "width": "narrow",
123
+ "preview": Preview(request, album, preview_helptext("album")),
124
+ })
117
125
 
118
126
 
119
127
  @json_problem_as_html
@@ -125,7 +133,7 @@ def delete_album(request: HttpRequest, album_key: str):
125
133
  album = api.check_album_access(request, album_key)
126
134
  target = album.title or album.key
127
135
  back = BackLink(
128
- f'Back to {target}',
136
+ target,
129
137
  reverse(
130
138
  'photo_objects:show_album',
131
139
  kwargs={
@@ -145,5 +153,7 @@ def delete_album(request: HttpRequest, album_key: str):
145
153
  "back": back,
146
154
  "photo": album.cover_photo,
147
155
  "resource": target,
156
+ "width": "narrow",
157
+ "preview": Preview(request, album, preview_helptext("album")),
148
158
  **error,
149
159
  })
@@ -6,7 +6,7 @@ from django.urls import reverse
6
6
  from django.utils.translation import gettext_lazy as _
7
7
 
8
8
  from photo_objects.django.api.utils import JsonProblem
9
- from photo_objects.django.views.utils import BackLink
9
+ from photo_objects.django.views.utils import BackLink, Preview
10
10
  from photo_objects.utils import render_markdown
11
11
 
12
12
  from .utils import json_problem_as_html
@@ -167,10 +167,20 @@ def configuration(request: HttpRequest):
167
167
  site_description_configured(request),
168
168
  ]
169
169
 
170
- back = BackLink("Back to albums", reverse('photo_objects:list_albums'))
171
-
172
- return render(request, "photo_objects/configuration.html", {
173
- "title": "Configuration",
174
- "validations": validations,
175
- "back": back,
176
- })
170
+ back = BackLink("Albums", reverse('photo_objects:list_albums'))
171
+
172
+ return render(
173
+ request,
174
+ "photo_objects/configuration.html",
175
+ {
176
+ "title": "Configuration",
177
+ "validations": validations,
178
+ "back": back,
179
+ "width": "narrow",
180
+ "preview": Preview(
181
+ request,
182
+ None,
183
+ "This is an example on how the site will appear by default "
184
+ "when sharing in social media. Note that individual albums "
185
+ "and photos override this default preview."),
186
+ })
@@ -12,11 +12,12 @@ from photo_objects.django.forms import ModifyPhotoForm, UploadPhotosForm
12
12
  from photo_objects.django.models import Photo
13
13
  from photo_objects.django.views.utils import (
14
14
  BackLink,
15
+ Preview,
15
16
  meta_description,
16
17
  )
17
18
  from photo_objects.utils import render_markdown
18
19
 
19
- from .utils import json_problem_as_html
20
+ from .utils import json_problem_as_html, preview_helptext
20
21
 
21
22
 
22
23
  @json_problem_as_html
@@ -43,7 +44,7 @@ def upload_photos(request: HttpRequest, album_key: str):
43
44
  album = api.check_album_access(request, album_key)
44
45
  target = album.title or album.key
45
46
  back = BackLink(
46
- f"Back to {target}", reverse(
47
+ target, reverse(
47
48
  'photo_objects:show_album', kwargs={
48
49
  "album_key": album_key}))
49
50
 
@@ -53,6 +54,8 @@ def upload_photos(request: HttpRequest, album_key: str):
53
54
  "title": "Upload photos",
54
55
  "back": back,
55
56
  "photo": album.cover_photo,
57
+ "width": "narrow",
58
+ "preview": Preview(request, album, preview_helptext("album")),
56
59
  })
57
60
 
58
61
 
@@ -109,7 +112,7 @@ def show_photo(request: HttpRequest, album_key: str, photo_key: str):
109
112
 
110
113
  previous_filename = photo.key.split("/")[-1]
111
114
  next_filename = previous_filename
112
- back = BackLink("Back to albums", reverse('photo_objects:list_albums'))
115
+ back = BackLink("Albums", reverse('photo_objects:list_albums'))
113
116
 
114
117
  try:
115
118
  api.check_album_access(request, photo.album.key)
@@ -125,7 +128,7 @@ def show_photo(request: HttpRequest, album_key: str, photo_key: str):
125
128
 
126
129
  target = photo.album.title or photo.album.key
127
130
  back = BackLink(
128
- f"Back to {target}", reverse(
131
+ target, reverse(
129
132
  'photo_objects:show_album', kwargs={
130
133
  "album_key": album_key}))
131
134
  except AlbumNotFound:
@@ -170,19 +173,23 @@ def edit_photo(request: HttpRequest, album_key: str, photo_key: str):
170
173
 
171
174
  target = photo.title or photo.filename
172
175
  back = BackLink(
173
- f'Back to {target}',
176
+ target,
174
177
  reverse(
175
178
  'photo_objects:show_photo',
176
179
  kwargs={
177
180
  "album_key": album_key,
178
181
  "photo_key": photo_key}))
179
182
 
180
- return render(request, 'photo_objects/form.html', {
181
- "form": form,
182
- "title": "Edit photo",
183
- "back": back,
184
- "photo": photo,
185
- })
183
+ return render(
184
+ request,
185
+ 'photo_objects/form.html',
186
+ {
187
+ "form": form,
188
+ "title": "Edit photo",
189
+ "back": back,
190
+ "width": "narrow",
191
+ "preview": Preview(request, photo, preview_helptext("photo")),
192
+ })
186
193
 
187
194
 
188
195
  @json_problem_as_html
@@ -197,7 +204,7 @@ def delete_photo(request: HttpRequest, album_key: str, photo_key: str):
197
204
  photo = api.check_photo_access(request, album_key, photo_key, "xs")
198
205
  target = photo.title or photo.filename
199
206
  back = BackLink(
200
- f'Back to {target}',
207
+ target,
201
208
  reverse(
202
209
  'photo_objects:show_photo',
203
210
  kwargs={
@@ -208,4 +215,6 @@ def delete_photo(request: HttpRequest, album_key: str, photo_key: str):
208
215
  "back": back,
209
216
  "photo": photo,
210
217
  "resource": target,
218
+ "width": "narrow",
219
+ "preview": Preview(request, photo, preview_helptext("photo")),
211
220
  })
@@ -47,15 +47,15 @@ def review_photo_change_request(request: HttpRequest, cr_id: str):
47
47
  else:
48
48
  info = f"There are {count} change requests in the review queue."
49
49
 
50
- back = BackLink("Back to albums", reverse('photo_objects:list_albums'))
50
+ back = BackLink("Albums", reverse('photo_objects:list_albums'))
51
51
 
52
52
  return render(request, 'photo_objects/form.html', {
53
53
  "form": form,
54
54
  "title": "Review photo change request",
55
55
  "back": back,
56
- "photo": photo,
57
56
  "info": info,
58
57
  "instructions": render_markdown(
59
58
  f'The current alt text for `{photo.key}` is: '
60
59
  f'_"{photo.alt_text}"_.'),
60
+ "width": "narrow",
61
61
  })
@@ -2,22 +2,20 @@ from django.contrib.auth import views as auth_views
2
2
  from django.http import HttpRequest
3
3
  from django.urls import reverse_lazy
4
4
 
5
- from photo_objects.django.models import SiteSettings
6
- from photo_objects.django.views.utils import BackLink
5
+ from photo_objects.django.views.utils import BackLink, Preview
7
6
 
8
7
 
9
8
  def login(request: HttpRequest):
10
- settings = SiteSettings.objects.get(request.site)
11
-
12
9
  return auth_views.LoginView.as_view(
13
10
  template_name="photo_objects/form.html",
14
11
  extra_context={
15
12
  "title": "Login",
16
- "photo": settings.preview_image,
17
13
  "action": "Login",
18
14
  "back": BackLink(
19
- 'Back to albums',
15
+ 'Albums',
20
16
  reverse_lazy('photo_objects:list_albums')),
21
- "class": "login"
17
+ "class": "login",
18
+ "width": "narrow",
19
+ "preview": Preview(request, None),
22
20
  },
23
21
  )(request)
@@ -8,3 +8,10 @@ def json_problem_as_html(func):
8
8
  except JsonProblem as e:
9
9
  return e.html_response(args[0])
10
10
  return wrapper
11
+
12
+
13
+ def preview_helptext(resource_type: str) -> str:
14
+ return (
15
+ f"This is an example on how the {resource_type} will currently appear "
16
+ "when sharing on social media."
17
+ )
@@ -1,16 +1,29 @@
1
1
  from django.http import HttpRequest
2
2
  from django.utils.dateformat import format as format_date
3
3
 
4
- from photo_objects.django.models import Album, Photo
4
+ from photo_objects.django.models import Album, Photo, SiteSettings
5
5
  from photo_objects.utils import first_paragraph_textcontent
6
6
 
7
7
 
8
8
  class BackLink:
9
- def __init__(self, text, url):
9
+ def __init__(self, text: str, url: str):
10
10
  self.text = text
11
11
  self.url = url
12
12
 
13
13
 
14
+ # TODO: Use this also for meta-og tags
15
+ class Preview:
16
+ def __init__(
17
+ self,
18
+ request: HttpRequest,
19
+ resource: Album | Photo = None,
20
+ helptext: str = None):
21
+ self.description = meta_description(request, resource)
22
+ self.photo = meta_photo(request, resource)
23
+ self.title = meta_title(request, resource)
24
+ self.helptext = helptext
25
+
26
+
14
27
  def _default_album_description(request: HttpRequest, album: Album) -> str:
15
28
  count = album.photo_set.count()
16
29
  plural = 's' if count != 1 else ''
@@ -24,19 +37,50 @@ def _default_photo_description(photo: Photo) -> str:
24
37
 
25
38
  def meta_description(
26
39
  request: HttpRequest,
27
- resource: Album | Photo | str | None) -> str:
40
+ resource: Album | Photo | str = None) -> str:
28
41
  text = None
29
42
  if isinstance(resource, Album):
30
- text = (
43
+ return (
31
44
  first_paragraph_textcontent(resource.description) or
32
45
  _default_album_description(request, resource))
33
46
 
34
47
  if isinstance(resource, Photo):
35
- text = (
48
+ return (
36
49
  first_paragraph_textcontent(resource.description) or
37
50
  _default_photo_description(resource))
38
51
 
39
52
  if isinstance(resource, str):
40
- text = first_paragraph_textcontent(resource)
53
+ return first_paragraph_textcontent(resource)
41
54
 
55
+ settings = SiteSettings.objects.get(request.site)
56
+ text = first_paragraph_textcontent(settings.description)
42
57
  return text or "A simple self-hosted photo server."
58
+
59
+
60
+ def meta_photo(
61
+ request: HttpRequest,
62
+ resource: Album | Photo = None) -> Photo:
63
+ if isinstance(resource, Photo):
64
+ return resource
65
+
66
+ if isinstance(resource, Album):
67
+ return resource.cover_photo
68
+
69
+ settings = SiteSettings.objects.get(request.site)
70
+ return settings.preview_image
71
+
72
+
73
+ def meta_title(
74
+ request: HttpRequest,
75
+ resource: Album | Photo | str = None) -> str:
76
+ text = None
77
+ if isinstance(resource, Album):
78
+ text = resource.title
79
+
80
+ if isinstance(resource, Photo):
81
+ text = resource.title or resource.filename
82
+
83
+ if isinstance(resource, str):
84
+ text = resource
85
+
86
+ return text or request.site.name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: photo-objects
3
- Version: 0.9.4
3
+ Version: 0.9.6
4
4
  Summary: Application for storing photos in S3 compatible object-storage.
5
5
  Author: Toni Kangas
6
6
  License: MIT License
@@ -19,7 +19,7 @@ photo_objects/django/api/auth.py,sha256=lS0S1tMVH2uN30g4jlixklv3eMnQ2FbQVQvuRXeM
19
19
  photo_objects/django/api/backup.py,sha256=lu-lDSGpEV9ASCIA5o0kNOZcg6_cmkVPCy1TFRvYyyY,6344
20
20
  photo_objects/django/api/photo.py,sha256=-lo1g6jfBr884wy-WV2DAEPxzH9V-tFUTRtitmA6i28,4471
21
21
  photo_objects/django/api/photo_change_request.py,sha256=v94RA7SUM60tC9mIZdz8HppbNKfHWeTFNPr_BPw3pys,3075
22
- photo_objects/django/api/utils.py,sha256=8r51YgFgKPD05Zjzhstl4jlQ4JM8DtsxUyAzhjXi5Pk,5567
22
+ photo_objects/django/api/utils.py,sha256=M7GdTZAkeAWSRjZeI51dlv8qaw2CjX3ruKsa1amc1Es,5559
23
23
  photo_objects/django/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  photo_objects/django/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  photo_objects/django/management/commands/clean-scaled-photos.py,sha256=KJY6phgTCxcmbMUsUfCRQjatvCmKyFninM8zT-tB3Kc,2008
@@ -43,24 +43,24 @@ photo_objects/django/tests/test_img.py,sha256=HEAWcr5fpTkzePkhoQ4YrWsDO9TvFOr7my
43
43
  photo_objects/django/tests/test_og_meta.py,sha256=Kk5a9KvE88KZ60gLqXSe6rTz5YU-gdjteksYolHd-nw,1804
44
44
  photo_objects/django/tests/test_photo.py,sha256=JWXN3fF2VtuByMKm2o5b19HnxwDr6ecRwuGzgc5RsBw,13471
45
45
  photo_objects/django/tests/test_photo_change_requests.py,sha256=Ld5ytqxxZiEWrqfX8htJ6-5ARU7tqTYD-iUhb7EMcnU,3078
46
- photo_objects/django/tests/test_utils.py,sha256=0Xl0ReS2X9GsEH-jmLg8xC79hJ4nhbfULo0BOVjiykQ,2089
46
+ photo_objects/django/tests/test_utils.py,sha256=kJKjKltbc-qj53BXc9UoQR6ABMMN_gNTQ3cUj3V41Dw,2173
47
47
  photo_objects/django/tests/utils.py,sha256=LiObyRARkmO4arnY2gXNi_T8XxT9eSKKszENMo2UIh8,4639
48
48
  photo_objects/django/views/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
- photo_objects/django/views/utils.py,sha256=AjJK5r5HmTF63E9Q4W3pKggDESuhNXUvbROpS8m70KM,1319
49
+ photo_objects/django/views/utils.py,sha256=19FO5LpZFVX9i01B_RvmV7b5zhJsQk8ZDVJzTgeD7SQ,2550
50
50
  photo_objects/django/views/api/__init__.py,sha256=GgywMJMSFmP5aoMEaYut5V666zachd5YFQIDBMr5znU,188
51
51
  photo_objects/django/views/api/album.py,sha256=EZMOkxYzLSWr9wwXnd4yAO64JtXZq2k3FYohiNMFbGQ,1602
52
52
  photo_objects/django/views/api/auth.py,sha256=EN_ExegzmLN-bhSzu3L9-6UE9qodPd7_ZRLilzrvc8Y,819
53
53
  photo_objects/django/views/api/photo.py,sha256=WHSayWTi_wG6otq6Rz1IKqJ5ik5riclR3AWB15ge5RU,4613
54
54
  photo_objects/django/views/api/utils.py,sha256=uQzKdSKHRAux5OZzqgWQr0gsK_FeweQP0cg_67OWA_Y,264
55
55
  photo_objects/django/views/ui/__init__.py,sha256=Y3XrckZExbHpWVNwDUGLfb99_midb8-5j6Ouf_Yu_G4,128
56
- photo_objects/django/views/ui/album.py,sha256=WmWrbY3nPCK7NIZYE9rJPzC39HjwN-TW8fN4gxIC3Yk,4765
57
- photo_objects/django/views/ui/configuration.py,sha256=jyZT3ZAzKa7RnzhED5anDShRCBiCHxOU81Cddt10-4Q,5096
58
- photo_objects/django/views/ui/photo.py,sha256=flwcET5nSChzfyAEWRTUlklTW2o64przNXSdWn-jxLw,6676
59
- photo_objects/django/views/ui/photo_change_request.py,sha256=eaYGXFqtHj8qonDAmPyn4nrEHkL13EBD-1s8Phs0XP4,2098
60
- photo_objects/django/views/ui/users.py,sha256=nb73cnzuV98QkJb0j8F2hqPgOGFIWpUFTFu6dXMeVwM,722
61
- photo_objects/django/views/ui/utils.py,sha256=YV_YcUbX-zUkdFnBlezPChR6aPDhZJ9loSOHBSzF6Cc,273
62
- photo_objects-0.9.4.dist-info/licenses/LICENSE,sha256=V3w6hTjXfP65F4r_mejveHcV5igHrblxao3-2RlfVlA,1068
63
- photo_objects-0.9.4.dist-info/METADATA,sha256=cxbWcwtdRd9pS958tcPZrH5pOUbvcnMsYGxrBAeLwTs,3615
64
- photo_objects-0.9.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
- photo_objects-0.9.4.dist-info/top_level.txt,sha256=SZeL8mhf-WMGdhRtTGFvZc3aIRBboQls9O0cFDMGdQ0,14
66
- photo_objects-0.9.4.dist-info/RECORD,,
56
+ photo_objects/django/views/ui/album.py,sha256=EQleU9ZyF3T0OABer3YMJbUNU4Vw9q-iY3WBPN872e8,5027
57
+ photo_objects/django/views/ui/configuration.py,sha256=miEJTm_cRANu9Wt3SCcU-tYUwM7WLKgQm8zgApmKMxE,5464
58
+ photo_objects/django/views/ui/photo.py,sha256=o7U0KimIWhreKSwIdVot1laEqqXprqvdbDZbRIvkJic,6966
59
+ photo_objects/django/views/ui/photo_change_request.py,sha256=KAfk69RbDTdN3I4fMUx6j7idqZ6IHZ4li6KKVS3yAYM,2093
60
+ photo_objects/django/views/ui/users.py,sha256=ABAtKwNoViYy2ht6X313BSm6wgvL302LVUNimp43gxc,649
61
+ photo_objects/django/views/ui/utils.py,sha256=65hSFZ_rlWWprE5kJdqwL9P-Lwlin9qvO8GjFuajdnM,463
62
+ photo_objects-0.9.6.dist-info/licenses/LICENSE,sha256=V3w6hTjXfP65F4r_mejveHcV5igHrblxao3-2RlfVlA,1068
63
+ photo_objects-0.9.6.dist-info/METADATA,sha256=onytwijT-TLdeooruS21ZT_E7q7GOoOwJPv5wm1kCzc,3615
64
+ photo_objects-0.9.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
65
+ photo_objects-0.9.6.dist-info/top_level.txt,sha256=SZeL8mhf-WMGdhRtTGFvZc3aIRBboQls9O0cFDMGdQ0,14
66
+ photo_objects-0.9.6.dist-info/RECORD,,