photo-objects 0.9.0__tar.gz → 0.9.1__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.
Files changed (71) hide show
  1. {photo_objects-0.9.0 → photo_objects-0.9.1}/PKG-INFO +1 -1
  2. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/api/backup.py +54 -1
  3. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/management/commands/restore-backup.py +23 -1
  4. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/objsto.py +8 -0
  5. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/test_utils.py +3 -0
  6. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/utils.py +5 -2
  7. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects.egg-info/PKG-INFO +1 -1
  8. {photo_objects-0.9.0 → photo_objects-0.9.1}/pyproject.toml +1 -1
  9. {photo_objects-0.9.0 → photo_objects-0.9.1}/LICENSE +0 -0
  10. {photo_objects-0.9.0 → photo_objects-0.9.1}/README.md +0 -0
  11. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/__init__.py +0 -0
  12. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/config.py +0 -0
  13. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/__init__.py +0 -0
  14. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/admin.py +0 -0
  15. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/api/__init__.py +0 -0
  16. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/api/album.py +0 -0
  17. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/api/auth.py +0 -0
  18. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/api/photo.py +0 -0
  19. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/api/photo_change_request.py +0 -0
  20. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/api/utils.py +0 -0
  21. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/apps.py +0 -0
  22. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/conf.py +0 -0
  23. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/context_processors.py +0 -0
  24. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/forms.py +0 -0
  25. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/management/__init__.py +0 -0
  26. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/management/commands/__init__.py +0 -0
  27. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/management/commands/clean-scaled-photos.py +0 -0
  28. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/management/commands/create-initial-admin-account.py +0 -0
  29. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/migrations/0001_initial.py +0 -0
  30. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/migrations/0002_created_at_updated_at.py +0 -0
  31. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/migrations/0003_admin_visibility.py +0 -0
  32. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/migrations/0004_camera_setup_and_settings.py +0 -0
  33. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/migrations/0005_sitesettings.py +0 -0
  34. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/migrations/0006_photo_alt_text.py +0 -0
  35. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/migrations/0007_backup.py +0 -0
  36. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/migrations/__init__.py +0 -0
  37. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/models.py +0 -0
  38. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/signals.py +0 -0
  39. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/templatetags/__init__.py +0 -0
  40. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/templatetags/photo_objects_extras.py +0 -0
  41. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/__init__.py +0 -0
  42. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/test_album.py +0 -0
  43. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/test_auth.py +0 -0
  44. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/test_commands.py +0 -0
  45. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/test_img.py +0 -0
  46. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/test_og_meta.py +0 -0
  47. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/test_photo.py +0 -0
  48. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/test_photo_change_requests.py +0 -0
  49. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/tests/utils.py +0 -0
  50. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/urls.py +0 -0
  51. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/__init__.py +0 -0
  52. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/api/__init__.py +0 -0
  53. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/api/album.py +0 -0
  54. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/api/auth.py +0 -0
  55. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/api/photo.py +0 -0
  56. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/api/utils.py +0 -0
  57. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/ui/__init__.py +0 -0
  58. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/ui/album.py +0 -0
  59. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/ui/configuration.py +0 -0
  60. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/ui/photo.py +0 -0
  61. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/ui/photo_change_request.py +0 -0
  62. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/ui/users.py +0 -0
  63. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/ui/utils.py +0 -0
  64. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/django/views/utils.py +0 -0
  65. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/error.py +0 -0
  66. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects/img.py +0 -0
  67. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects.egg-info/SOURCES.txt +0 -0
  68. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects.egg-info/dependency_links.txt +0 -0
  69. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects.egg-info/requires.txt +0 -0
  70. {photo_objects-0.9.0 → photo_objects-0.9.1}/photo_objects.egg-info/top_level.txt +0 -0
  71. {photo_objects-0.9.0 → photo_objects-0.9.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: photo-objects
3
- Version: 0.9.0
3
+ Version: 0.9.1
4
4
  Summary: Application for storing photos in S3 compatible object-storage.
5
5
  Author: Toni Kangas
6
6
  License: MIT License
@@ -1,13 +1,15 @@
1
1
  from django.contrib.auth import get_user_model
2
2
  from django.contrib.auth.models import Group, Permission
3
+ from django.contrib.sites.models import Site
3
4
  from django.db import transaction
4
5
 
5
- from photo_objects.django.models import Album, Backup, Photo
6
+ from photo_objects.django.models import Album, Backup, Photo, SiteSettings
6
7
  from photo_objects.django.objsto import (
7
8
  backup_data_key,
8
9
  backup_info_key,
9
10
  delete_backup_objects,
10
11
  get_backup_data,
12
+ get_backup_object,
11
13
  get_backup_objects,
12
14
  put_backup_json,
13
15
  )
@@ -55,6 +57,12 @@ def _group_dict(group: Group):
55
57
 
56
58
 
57
59
  def create_backup(backup: Backup):
60
+ # Check if backup already exists
61
+ if get_backup_object(backup.id):
62
+ backup.status = "ready"
63
+ backup.save()
64
+ return
65
+
58
66
  user_model = get_user_model()
59
67
 
60
68
  backup.status = "pending"
@@ -99,10 +107,34 @@ def create_backup(backup: Backup):
99
107
  user.username),
100
108
  _user_dict(user))
101
109
 
110
+ sites = Site.objects.all()
111
+ for site in sites:
112
+ put_backup_json(
113
+ backup_data_key(backup.id, 'site', site.id),
114
+ {
115
+ "id": site.id,
116
+ "domain": site.domain,
117
+ "name": site.name,
118
+ }
119
+ )
120
+
121
+ site_settings = SiteSettings.objects.all()
122
+ for settings in site_settings:
123
+ put_backup_json(
124
+ backup_data_key(backup.id, 'settings', settings.site.id),
125
+ {
126
+ "site_id": settings.site.id,
127
+ "description": settings.description,
128
+ "preview_image_key": settings.preview_image.key
129
+ if settings.preview_image else None,
130
+ }
131
+ )
132
+
102
133
  put_backup_json(backup_info_key(backup.id), backup.to_json())
103
134
  except Exception:
104
135
  backup.status = "create_failed"
105
136
  backup.save()
137
+ raise
106
138
 
107
139
  backup.status = "ready"
108
140
  backup.save()
@@ -160,3 +192,24 @@ def restore_backup(backup_id: int):
160
192
  if cover_photo == filename:
161
193
  album.cover_photo = photo
162
194
  album.save()
195
+
196
+ for i in get_backup_data(backup_id, "site"):
197
+ site, _ = Site.objects.get_or_create(id=i.get("id"))
198
+ site.domain = i.get("domain")
199
+ site.name = i.get("name")
200
+ site.save()
201
+
202
+ for i in get_backup_data(backup_id, "settings"):
203
+ site = Site.objects.get(id=i.get("site_id"))
204
+
205
+ preview_image = None
206
+ if key := i.get("preview_image_key"):
207
+ preview_image = Photo.objects.get(key=key)
208
+
209
+ settings = SiteSettings.objects.create(
210
+ site=site,
211
+ description=i.get("description"),
212
+ preview_image=preview_image
213
+ if i.get("preview_image_key") else None
214
+ )
215
+ settings.save()
@@ -1,7 +1,11 @@
1
1
  # pylint: disable=invalid-name
2
+ from io import StringIO
3
+
4
+ from django.core.management import call_command
2
5
  from django.core.management.base import BaseCommand
3
6
  from django.contrib.auth import get_user_model
4
7
  from django.contrib.auth.models import Group
8
+ from django.db import connection
5
9
 
6
10
  from photo_objects.django.api.backup import get_backups, restore_backup
7
11
  from photo_objects.django.models import Album, Photo
@@ -28,6 +32,23 @@ class DatabaseStatus:
28
32
  )
29
33
 
30
34
 
35
+ def reset_sequences():
36
+ output = StringIO()
37
+ call_command(
38
+ 'sqlsequencereset',
39
+ 'photo_objects',
40
+ 'auth',
41
+ 'sites',
42
+ stdout=output,
43
+ no_color=True)
44
+
45
+ sql = output.getvalue()
46
+ with connection.cursor() as cursor:
47
+ cursor.execute(sql)
48
+
49
+ output.close()
50
+
51
+
31
52
  class Command(BaseCommand):
32
53
  help = "Restore latest backup if database is empty."
33
54
 
@@ -59,6 +80,7 @@ class Command(BaseCommand):
59
80
  )
60
81
  )
61
82
  restore_backup(id_)
83
+ reset_sequences()
62
84
  status = DatabaseStatus()
63
85
  self.stdout.write(
64
86
  self.style.SUCCESS(
@@ -71,4 +93,4 @@ class Command(BaseCommand):
71
93
  f'Failed to restore backup: {e}'
72
94
  )
73
95
  )
74
- exit(1)
96
+ raise
@@ -137,6 +137,14 @@ def put_backup_json(key: str, data: dict):
137
137
  return _put_json(key, data, _backup_access)
138
138
 
139
139
 
140
+ def get_backup_object(backup_id: int):
141
+ client, bucket = _backup_access()
142
+ return json.loads(
143
+ client.get_object(
144
+ bucket,
145
+ backup_info_key(backup_id)).read())
146
+
147
+
140
148
  def get_backup_objects():
141
149
  client, bucket = _backup_access()
142
150
  return [json.loads(i.read()) for i in _get_all(client, bucket, 'info_')]
@@ -25,6 +25,9 @@ class TestUtils(TestCase):
25
25
  def test_slugify_lower(self):
26
26
  self.assertEqual(slugify("QwErTy!", True), "qwerty-")
27
27
 
28
+ def test_slugify_number(self):
29
+ self.assertEqual(slugify(123), "123")
30
+
28
31
  def test_slugify_replace_leading_underscores(self):
29
32
  self.assertEqual(
30
33
  slugify(
@@ -31,9 +31,12 @@ def timestamp_str(timestamp: datetime):
31
31
  return timestamp.isoformat() if timestamp else None
32
32
 
33
33
 
34
- def slugify(title: str, lower=False, replace_leading_underscores=False) -> str:
34
+ def slugify(
35
+ title: str | int,
36
+ lower=False,
37
+ replace_leading_underscores=False) -> str:
35
38
  key = unicodedata.normalize(
36
- 'NFKD', title).encode(
39
+ 'NFKD', str(title)).encode(
37
40
  'ascii', 'ignore').decode('ascii')
38
41
  if lower:
39
42
  key = key.lower()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: photo-objects
3
- Version: 0.9.0
3
+ Version: 0.9.1
4
4
  Summary: Application for storing photos in S3 compatible object-storage.
5
5
  Author: Toni Kangas
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "photo-objects"
7
- version = "0.9.0"
7
+ version = "0.9.1"
8
8
  dependencies = [
9
9
  "markdown~=3.7",
10
10
  "minio~=7.2",
File without changes
File without changes
File without changes