drf-appkit 0.9.1__tar.gz → 1.1.2__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.
- {drf-appkit-0.9.1/drf_appkit.egg-info → drf-appkit-1.1.2}/PKG-INFO +1 -1
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/filters.py +1 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/mixins.py +16 -41
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/serializers.py +95 -87
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/views.py +13 -7
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/fields.py +26 -12
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/serializers.py +1 -1
- drf-appkit-1.1.2/appkit/email.py +48 -0
- drf-appkit-1.1.2/appkit/migrations/0014_remove_note_notes_note_content_type_note_object_id.py +29 -0
- drf-appkit-1.1.2/appkit/migrations/0015_alter_note_content_type_alter_note_object_id.py +27 -0
- drf-appkit-1.1.2/appkit/migrations/0016_alter_arrangementitem_unique_together_and_more.py +29 -0
- drf-appkit-1.1.2/appkit/migrations/0017_alter_imageattachment_image.py +21 -0
- drf-appkit-1.1.2/appkit/migrations/0018_place_geoposition.py +33 -0
- drf-appkit-1.1.2/appkit/migrations/0019_alter_place_geoposition.py +19 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/models.py +11 -13
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/shortcuts.py +9 -4
- drf-appkit-1.1.2/appkit/storages.py +11 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/util.py +5 -9
- {drf-appkit-0.9.1 → drf-appkit-1.1.2/drf_appkit.egg-info}/PKG-INFO +1 -1
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/drf_appkit.egg-info/SOURCES.txt +7 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/setup.cfg +1 -1
- drf-appkit-0.9.1/appkit/email.py +0 -45
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/LICENSE +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/README.md +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/__init__.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/__init__.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/metadata.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/pagination.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/relations.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/renderers.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/api/tests.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/auth/__init__.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/auth/backends.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/auth/decorators.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/auth/email.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/auth/permissions.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/debug.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/__init__.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/authentication.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/backends.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/exceptions.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/filters.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/metadata.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/mixins.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/drf/permissions.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/managers.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0001_initial.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0002_arrangement_tags.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0003_auto_20210221_0852.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0004_auto_20210309_0655.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0005_auto_20210324_1046.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0006_sitealias.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0007_auto_20211021_1901.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0008_update_autofields.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0009_alter_arrangement_unique_together_and_more.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0010_arrangement_name.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0011_alter_sitealias_options.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0012_alter_sitealias_site.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/0013_usergroup.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/migrations/__init__.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/settings.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/appkit/views.py +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/drf_appkit.egg-info/dependency_links.txt +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/drf_appkit.egg-info/top_level.txt +0 -0
- {drf-appkit-0.9.1 → drf-appkit-1.1.2}/setup.py +0 -0
|
@@ -10,7 +10,7 @@ from django.contrib.contenttypes.models import ContentType
|
|
|
10
10
|
from django.core.files.uploadedfile import InMemoryUploadedFile
|
|
11
11
|
from django.db import transaction
|
|
12
12
|
|
|
13
|
-
from rest_framework import status
|
|
13
|
+
from rest_framework import status, serializers
|
|
14
14
|
from rest_framework.decorators import action
|
|
15
15
|
from rest_framework.response import Response
|
|
16
16
|
from rest_framework.serializers import ValidationError
|
|
@@ -19,12 +19,11 @@ from filedepot.mixins import FlowFileUploadMixin
|
|
|
19
19
|
|
|
20
20
|
from ..models import (
|
|
21
21
|
Attachment,
|
|
22
|
-
ImageAttachment,
|
|
23
22
|
Tag,
|
|
24
23
|
)
|
|
25
24
|
from ..util import hashed_filename
|
|
26
25
|
from ..settings import appkit_settings
|
|
27
|
-
from .
|
|
26
|
+
from . import serializers
|
|
28
27
|
|
|
29
28
|
User = get_user_model()
|
|
30
29
|
get_current_site = appkit_settings.CURRENT_SITE_ACCESSOR
|
|
@@ -40,21 +39,6 @@ class DocumentViewSetMixin(object):
|
|
|
40
39
|
return queryset.filter(site=current_site)
|
|
41
40
|
|
|
42
41
|
|
|
43
|
-
class ImageAttachmentViewSetMixin(object):
|
|
44
|
-
@action(detail=False, methods=['patch'])
|
|
45
|
-
@transaction.atomic()
|
|
46
|
-
def bulk_reposition(self, request, **kwargs):
|
|
47
|
-
serializer = ImageAttachmentBulkRepositionSerializer(data=request.data)
|
|
48
|
-
serializer.is_valid(raise_exception=True)
|
|
49
|
-
validated_data = serializer.validated_data
|
|
50
|
-
for position_index, uuid in enumerate(validated_data['image_attachment_uuids']):
|
|
51
|
-
image_attachment = ImageAttachment.objects.get(uuid=uuid)
|
|
52
|
-
image_attachment.position = validated_data['positions'][position_index]
|
|
53
|
-
image_attachment.save()
|
|
54
|
-
|
|
55
|
-
return Response(status=status.HTTP_204_NO_CONTENT)
|
|
56
|
-
|
|
57
|
-
|
|
58
42
|
class AttachmentMixin(FlowFileUploadMixin):
|
|
59
43
|
@action(detail=True, methods=['delete'])
|
|
60
44
|
def delete_attachment(self, request, uuid, **kwargs):
|
|
@@ -64,7 +48,6 @@ class AttachmentMixin(FlowFileUploadMixin):
|
|
|
64
48
|
serializer = self.get_serializer(self.get_object())
|
|
65
49
|
return Response(serializer.data)
|
|
66
50
|
|
|
67
|
-
|
|
68
51
|
@action(detail=True, methods=['get', 'post'])
|
|
69
52
|
def add_attachment(self, request, uuid, **kwargs):
|
|
70
53
|
result = self.handle_flow_request(request)
|
|
@@ -92,6 +75,7 @@ class AttachmentMixin(FlowFileUploadMixin):
|
|
|
92
75
|
|
|
93
76
|
return Response(response_data, status=result['status'])
|
|
94
77
|
|
|
78
|
+
"""
|
|
95
79
|
@action(detail=True, methods=['delete'])
|
|
96
80
|
def delete_image(self, request, uuid, **kwargs):
|
|
97
81
|
image_attachment = ImageAttachment.objects.get(uuid=request.data['item_uuid'])
|
|
@@ -103,22 +87,8 @@ class AttachmentMixin(FlowFileUploadMixin):
|
|
|
103
87
|
@action(detail=True, methods=['post'])
|
|
104
88
|
def add_image(self, request, uuid, **kwargs):
|
|
105
89
|
obj = self.get_object()
|
|
106
|
-
request_params = self.get_request_params(request)
|
|
107
|
-
|
|
108
|
-
# Distinguish if request was issued by flow.js.
|
|
109
|
-
# If it was, and if it is finished, process the file.
|
|
110
|
-
flow_file = None
|
|
111
|
-
flow_identifier = request_params.get('flowIdentifier')
|
|
112
|
-
if flow_identifier:
|
|
113
|
-
result = self.handle_flow_request(request)
|
|
114
|
-
if not result['finished']:
|
|
115
|
-
return Response({}, status=result['status'])
|
|
116
|
-
|
|
117
|
-
flow_file = result['file']
|
|
118
|
-
image_file = flow_file.django_file()
|
|
119
|
-
else:
|
|
120
|
-
image_file = request.FILES['image']
|
|
121
90
|
|
|
91
|
+
image_file = request.FILES['image']
|
|
122
92
|
with image_file.open() as image_stream:
|
|
123
93
|
# First off, verify that the uploaded file is in fact an image
|
|
124
94
|
try:
|
|
@@ -129,7 +99,6 @@ class AttachmentMixin(FlowFileUploadMixin):
|
|
|
129
99
|
# Let the final image filename be determined as a hash the bytes
|
|
130
100
|
# of the originally uploaded image file
|
|
131
101
|
image_hash = hashed_filename(image_file)
|
|
132
|
-
image_filename = '{}.jpg'.format(image_hash)
|
|
133
102
|
|
|
134
103
|
# Since we're always writing out to JPEG, discard alpha channel, if any (ex: PNG images)
|
|
135
104
|
if not image.mode == 'RGB':
|
|
@@ -151,7 +120,7 @@ class AttachmentMixin(FlowFileUploadMixin):
|
|
|
151
120
|
resized_image_file = InMemoryUploadedFile(
|
|
152
121
|
file=image_bytes,
|
|
153
122
|
field_name='image',
|
|
154
|
-
name=
|
|
123
|
+
name=f'{image_hash}.jpg',
|
|
155
124
|
content_type='image/jpeg',
|
|
156
125
|
size=sys.getsizeof(image_bytes),
|
|
157
126
|
charset=None
|
|
@@ -180,16 +149,22 @@ class AttachmentMixin(FlowFileUploadMixin):
|
|
|
180
149
|
obj.feature_image = image_attachment
|
|
181
150
|
obj.save()
|
|
182
151
|
|
|
183
|
-
# An image attachment has been generated from the constructed file
|
|
184
|
-
# so the flow_file can be safely be discarded
|
|
185
|
-
if flow_file:
|
|
186
|
-
flow_file.delete()
|
|
187
|
-
|
|
188
152
|
serializer = self.get_serializer(obj)
|
|
189
153
|
serialized_data = serializer.data
|
|
190
154
|
serialized_data['image_attachment_uuid'] = image_attachment.uuid
|
|
191
155
|
|
|
192
156
|
return Response(serialized_data, status=status.HTTP_201_CREATED)
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
# ------------------------------------------------------------------------------
|
|
161
|
+
class NoteMixin(object):
|
|
162
|
+
@action(detail=True, methods=['get'])
|
|
163
|
+
def notes(self, request, **kwargs):
|
|
164
|
+
item = self.get_object()
|
|
165
|
+
|
|
166
|
+
serializer = self.get_serializer(item.notes.all(), many=True)
|
|
167
|
+
return Response(serializer.data)
|
|
193
168
|
|
|
194
169
|
|
|
195
170
|
# ------------------------------------------------------------------------------
|
|
@@ -19,7 +19,6 @@ from rest_framework import exceptions
|
|
|
19
19
|
from rest_framework_recursive.fields import RecursiveField
|
|
20
20
|
|
|
21
21
|
from djoser.conf import settings as djoser_settings
|
|
22
|
-
|
|
23
22
|
from djoser.serializers import (
|
|
24
23
|
ActivationSerializer as DjoserActivationSerializer,
|
|
25
24
|
UserCreateSerializer as DjoserUserCreateSerializer,
|
|
@@ -31,9 +30,8 @@ from versatileimagefield.serializers import VersatileImageFieldSerializer
|
|
|
31
30
|
|
|
32
31
|
from ..auth import get_userprofile_model
|
|
33
32
|
|
|
34
|
-
from ..drf.
|
|
35
|
-
|
|
36
|
-
StringListField,
|
|
33
|
+
from ..drf.fields import (
|
|
34
|
+
UUIDListField,
|
|
37
35
|
)
|
|
38
36
|
|
|
39
37
|
from ..drf.fields import (
|
|
@@ -43,6 +41,7 @@ from ..drf.fields import (
|
|
|
43
41
|
)
|
|
44
42
|
|
|
45
43
|
from ..models import (
|
|
44
|
+
ArrangementItem,
|
|
46
45
|
Attachment,
|
|
47
46
|
ImageAttachment,
|
|
48
47
|
Note,
|
|
@@ -126,69 +125,6 @@ class SiteSerializer(serializers.ModelSerializer):
|
|
|
126
125
|
return f'{request.scheme}://{domain}'
|
|
127
126
|
|
|
128
127
|
|
|
129
|
-
class DocumentSerializer(serializers.HyperlinkedModelSerializer):
|
|
130
|
-
"""
|
|
131
|
-
Override the create method to automatically set the created_by field to the
|
|
132
|
-
authenticated user who issued the request
|
|
133
|
-
"""
|
|
134
|
-
content_type = ContentTypeField(read_only=True)
|
|
135
|
-
path = DocumentPathField(max_length=100, read_only=True)
|
|
136
|
-
|
|
137
|
-
class Meta:
|
|
138
|
-
fields = (
|
|
139
|
-
'id', 'uuid', 'url',
|
|
140
|
-
'date_created', 'content_type', 'path',
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
def create(self, validated_data):
|
|
144
|
-
"""
|
|
145
|
-
Override the create method to automatically set the created_by field to the
|
|
146
|
-
authenticated user who issued the request
|
|
147
|
-
"""
|
|
148
|
-
request = self.context.get('request')
|
|
149
|
-
if not request.user.is_authenticated:
|
|
150
|
-
raise exceptions.NotAuthenticated('Documents can only be created by an authenticated user')
|
|
151
|
-
|
|
152
|
-
validated_data['created_by_id'] = request.user.pk
|
|
153
|
-
validated_data['site'] = get_current_site(request)
|
|
154
|
-
|
|
155
|
-
return super().create(validated_data)
|
|
156
|
-
|
|
157
|
-
def save(self, **kwargs):
|
|
158
|
-
"""
|
|
159
|
-
Override the save method to create a new revision whenever a document
|
|
160
|
-
is created or updated
|
|
161
|
-
"""
|
|
162
|
-
with reversion.create_revision():
|
|
163
|
-
instance = super().save(**kwargs)
|
|
164
|
-
|
|
165
|
-
request = self.context.get('request')
|
|
166
|
-
if request:
|
|
167
|
-
reversion.set_user(request.user)
|
|
168
|
-
|
|
169
|
-
if request.method == 'POST':
|
|
170
|
-
reversion.set_comment('Initial version.')
|
|
171
|
-
|
|
172
|
-
if request.method == 'PATCH':
|
|
173
|
-
reversion.set_comment(','.join(self.validated_data.keys()))
|
|
174
|
-
|
|
175
|
-
return instance
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
class AttachmentSerializer(DocumentSerializer):
|
|
179
|
-
content_type = serializers.PrimaryKeyRelatedField(
|
|
180
|
-
queryset=ContentType.objects.all()
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
media_url = AttachmentFileField(read_only=True)
|
|
184
|
-
|
|
185
|
-
class Meta(DocumentSerializer.Meta):
|
|
186
|
-
model = Attachment
|
|
187
|
-
fields = DocumentSerializer.Meta.fields + (
|
|
188
|
-
'content_type', 'media_url', 'object_id',
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
|
|
192
128
|
class GroupSerializer(serializers.HyperlinkedModelSerializer):
|
|
193
129
|
class Meta:
|
|
194
130
|
model = Group
|
|
@@ -221,6 +157,17 @@ class TagSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
221
157
|
)
|
|
222
158
|
|
|
223
159
|
|
|
160
|
+
class UserListSerializer(serializers.HyperlinkedModelSerializer):
|
|
161
|
+
content_type = ContentTypeField(read_only=True)
|
|
162
|
+
|
|
163
|
+
class Meta:
|
|
164
|
+
model = User
|
|
165
|
+
fields = (
|
|
166
|
+
'id', 'url', 'content_type', 'is_active', 'is_staff',
|
|
167
|
+
'email', 'first_name', 'last_name', 'full_name',
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
|
|
224
171
|
class ImageAttachmentImageSerializer(VersatileImageFieldSerializer):
|
|
225
172
|
def to_representation(self, value):
|
|
226
173
|
try:
|
|
@@ -253,6 +200,73 @@ class ImageAttachmentImageSerializer(VersatileImageFieldSerializer):
|
|
|
253
200
|
return image_info
|
|
254
201
|
|
|
255
202
|
|
|
203
|
+
# ------------------------------------------------------------------------------
|
|
204
|
+
#
|
|
205
|
+
# ------------------------------------------------------------------------------
|
|
206
|
+
class DocumentSerializer(serializers.HyperlinkedModelSerializer):
|
|
207
|
+
"""
|
|
208
|
+
Override the create method to automatically set the created_by field to the
|
|
209
|
+
authenticated user who issued the request
|
|
210
|
+
"""
|
|
211
|
+
created_by = UserListSerializer(read_only=True)
|
|
212
|
+
content_type = ContentTypeField(read_only=True)
|
|
213
|
+
path = DocumentPathField(max_length=100, read_only=True)
|
|
214
|
+
|
|
215
|
+
class Meta:
|
|
216
|
+
fields = (
|
|
217
|
+
'id', 'uuid', 'url', 'site', 'path', 'content_type',
|
|
218
|
+
'created_by', 'date_created', 'date_modified',
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
def create(self, validated_data):
|
|
222
|
+
"""
|
|
223
|
+
Override the create method to automatically set the created_by field to the
|
|
224
|
+
authenticated user who issued the request
|
|
225
|
+
"""
|
|
226
|
+
request = self.context.get('request')
|
|
227
|
+
if not request.user.is_authenticated:
|
|
228
|
+
raise exceptions.NotAuthenticated('Documents can only be created by an authenticated user')
|
|
229
|
+
|
|
230
|
+
validated_data['created_by_id'] = request.user.pk
|
|
231
|
+
validated_data['site'] = get_current_site(request)
|
|
232
|
+
|
|
233
|
+
return super().create(validated_data)
|
|
234
|
+
|
|
235
|
+
def save(self, **kwargs):
|
|
236
|
+
"""
|
|
237
|
+
Override the save method to create a new revision whenever a document
|
|
238
|
+
is created or updated
|
|
239
|
+
"""
|
|
240
|
+
with reversion.create_revision():
|
|
241
|
+
instance = super().save(**kwargs)
|
|
242
|
+
|
|
243
|
+
request = self.context.get('request')
|
|
244
|
+
if request:
|
|
245
|
+
reversion.set_user(request.user)
|
|
246
|
+
|
|
247
|
+
if request.method == 'POST':
|
|
248
|
+
reversion.set_comment('Initial version.')
|
|
249
|
+
|
|
250
|
+
if request.method == 'PATCH':
|
|
251
|
+
reversion.set_comment(','.join(self.validated_data.keys()))
|
|
252
|
+
|
|
253
|
+
return instance
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class AttachmentSerializer(DocumentSerializer):
|
|
257
|
+
content_type = serializers.PrimaryKeyRelatedField(
|
|
258
|
+
queryset=ContentType.objects.all()
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
media_url = AttachmentFileField(read_only=True)
|
|
262
|
+
|
|
263
|
+
class Meta(DocumentSerializer.Meta):
|
|
264
|
+
model = Attachment
|
|
265
|
+
fields = DocumentSerializer.Meta.fields + (
|
|
266
|
+
'content_type', 'media_url', 'object_id',
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
|
|
256
270
|
class ImageAttachmentSerializer(DocumentSerializer):
|
|
257
271
|
def __init__(self, sizes=None, **kwargs):
|
|
258
272
|
self.sizes = sizes if sizes else kwargs['context'].get('sizes')
|
|
@@ -273,20 +287,10 @@ class ImageAttachmentSerializer(DocumentSerializer):
|
|
|
273
287
|
return fields
|
|
274
288
|
|
|
275
289
|
|
|
290
|
+
|
|
276
291
|
# ------------------------------------------------------------------------------
|
|
277
292
|
# List Serializers
|
|
278
293
|
# ------------------------------------------------------------------------------
|
|
279
|
-
class UserListSerializer(serializers.HyperlinkedModelSerializer):
|
|
280
|
-
content_type = ContentTypeField(read_only=True)
|
|
281
|
-
|
|
282
|
-
class Meta:
|
|
283
|
-
model = User
|
|
284
|
-
fields = (
|
|
285
|
-
'id', 'url', 'content_type', 'is_active', 'is_staff',
|
|
286
|
-
'email', 'first_name', 'last_name', 'full_name',
|
|
287
|
-
)
|
|
288
|
-
|
|
289
|
-
|
|
290
294
|
class UserProfileListSerializer(DocumentSerializer):
|
|
291
295
|
user = UserListSerializer(read_only=True)
|
|
292
296
|
|
|
@@ -433,17 +437,21 @@ class ImageAttachmentEditSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
433
437
|
)
|
|
434
438
|
|
|
435
439
|
|
|
436
|
-
class
|
|
437
|
-
|
|
438
|
-
positions = IntegerListField()
|
|
439
|
-
|
|
440
|
-
def validate(self, data):
|
|
441
|
-
validated_data = super().validate(data)
|
|
440
|
+
class ImageAttachmentBulkDeleteSerializer(serializers.Serializer):
|
|
441
|
+
uuids = UUIDListField()
|
|
442
442
|
|
|
443
|
-
if len(validated_data['image_attachment_uuids']) != len(validated_data['positions']):
|
|
444
|
-
raise serializers.ValidationError('"image_attachment_uuids" and "positions" must be the same length')
|
|
445
443
|
|
|
446
|
-
|
|
444
|
+
class ImageAttachmentBulkRepositionSerializer(serializers.Serializer):
|
|
445
|
+
uuids = UUIDListField()
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
class ArrangementItemBulkRepositionSerializer(serializers.Serializer):
|
|
449
|
+
items = serializers.HyperlinkedRelatedField(
|
|
450
|
+
queryset=ArrangementItem.objects.all(),
|
|
451
|
+
view_name='arrangementitem-detail',
|
|
452
|
+
lookup_field='uuid',
|
|
453
|
+
many=True,
|
|
454
|
+
)
|
|
447
455
|
|
|
448
456
|
|
|
449
457
|
class ForcePasswordSerializer(serializers.Serializer):
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
from django.contrib.auth.models import Group
|
|
2
2
|
from django.core.exceptions import FieldError
|
|
3
3
|
|
|
4
|
-
from rest_framework import viewsets, status
|
|
4
|
+
from rest_framework import exceptions, viewsets, status
|
|
5
5
|
from rest_framework.decorators import action
|
|
6
|
-
from rest_framework.exceptions import APIException, ValidationError
|
|
7
6
|
from rest_framework.response import Response
|
|
8
7
|
from rest_framework.settings import api_settings
|
|
9
8
|
from rest_framework_simplejwt.serializers import (
|
|
@@ -218,7 +217,7 @@ class MasterDetailViewSet(
|
|
|
218
217
|
return self.serializers['default']
|
|
219
218
|
|
|
220
219
|
def get_detailed_response_context(self, request, instance):
|
|
221
|
-
return
|
|
220
|
+
return self.get_serializer_context()
|
|
222
221
|
|
|
223
222
|
def perform_create(self, serializer):
|
|
224
223
|
"""
|
|
@@ -231,7 +230,7 @@ class MasterDetailViewSet(
|
|
|
231
230
|
if filter_params:
|
|
232
231
|
try:
|
|
233
232
|
ModelClass.objects.get(**filter_params)
|
|
234
|
-
raise ValidationError({
|
|
233
|
+
raise exceptions.ValidationError({
|
|
235
234
|
api_settings.NON_FIELD_ERRORS_KEY: 'E_CREATE_DUPLICATE_RECORD',
|
|
236
235
|
})
|
|
237
236
|
except (FieldError, ModelClass.DoesNotExist):
|
|
@@ -248,12 +247,19 @@ class MasterDetailViewSet(
|
|
|
248
247
|
create_serializer.is_valid(raise_exception=True)
|
|
249
248
|
self.perform_create(create_serializer)
|
|
250
249
|
|
|
250
|
+
queryset = self.filter_queryset(self.get_queryset())
|
|
251
|
+
filter_kwargs = {self.lookup_field: getattr(create_serializer.instance, self.lookup_field)}
|
|
252
|
+
try:
|
|
253
|
+
obj = queryset.get(**filter_kwargs)
|
|
254
|
+
except ObjectDoesNotExist:
|
|
255
|
+
raise exceptions.NotFound()
|
|
256
|
+
|
|
251
257
|
DetailSerializerClass = self.get_detail_serializer_class()
|
|
252
258
|
detail_serializer = DetailSerializerClass(
|
|
253
|
-
instance=
|
|
259
|
+
instance=obj,
|
|
254
260
|
context=self.get_detailed_response_context(
|
|
255
261
|
request=create_serializer.context['request'],
|
|
256
|
-
instance=
|
|
262
|
+
instance=obj
|
|
257
263
|
)
|
|
258
264
|
)
|
|
259
265
|
headers = self.get_success_headers(detail_serializer.data)
|
|
@@ -321,7 +327,7 @@ class AttachmentViewSet(mixins.DocumentViewSetMixin, MasterDetailViewSet):
|
|
|
321
327
|
serializer_class = serializers.AttachmentSerializer
|
|
322
328
|
|
|
323
329
|
|
|
324
|
-
class ImageAttachmentViewSet(mixins.DocumentViewSetMixin,
|
|
330
|
+
class ImageAttachmentViewSet(mixins.DocumentViewSetMixin, MasterDetailViewSet):
|
|
325
331
|
queryset = ImageAttachment.objects.all()
|
|
326
332
|
serializers = {
|
|
327
333
|
'default': serializers.ImageAttachmentSerializer,
|
|
@@ -8,25 +8,37 @@ from django.urls import resolve, reverse
|
|
|
8
8
|
from django.urls.exceptions import NoReverseMatch
|
|
9
9
|
|
|
10
10
|
from appkit.shortcuts import mimetype_for_file
|
|
11
|
-
from rest_framework
|
|
11
|
+
from rest_framework import fields
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
class ContentTypeField(IntegerField):
|
|
14
|
+
class ContentTypeField(fields.IntegerField):
|
|
15
15
|
def get_attribute(self, instance):
|
|
16
16
|
return ContentType.objects.get_for_model(instance).id
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
class DocumentPathField(CharField):
|
|
19
|
+
class DocumentPathField(fields.CharField):
|
|
20
20
|
def __init__(self, **kwargs):
|
|
21
21
|
self.url_kwargs = kwargs.pop('url_kwargs', None)
|
|
22
22
|
super().__init__(**kwargs)
|
|
23
23
|
|
|
24
|
+
def get_detail_url_name(self, instance):
|
|
25
|
+
if hasattr(self.parent.Meta, 'detail_url_name'):
|
|
26
|
+
return self.parent.Meta.detail_url_name
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
return instance.get_detail_url_name()
|
|
30
|
+
except NotImplementedError:
|
|
31
|
+
return None
|
|
32
|
+
|
|
24
33
|
def get_namespaced_detail_url_name(self, instance, url_info):
|
|
25
|
-
|
|
34
|
+
detail_url_name = self.get_detail_url_name(instance)
|
|
35
|
+
if not detail_url_name:
|
|
36
|
+
return None
|
|
37
|
+
|
|
26
38
|
namespace = url_info.kwargs.get('namespace')
|
|
27
39
|
if namespace:
|
|
28
|
-
|
|
29
|
-
return
|
|
40
|
+
detail_url_name = '{}:{}'.format(namespace, detail_url_name)
|
|
41
|
+
return detail_url_name
|
|
30
42
|
|
|
31
43
|
def get_detail_url_info(self, instance, url_info):
|
|
32
44
|
namespace = url_info.kwargs['namespace']
|
|
@@ -36,11 +48,9 @@ class DocumentPathField(CharField):
|
|
|
36
48
|
'urlconf': f'app.{namespace}.urls',
|
|
37
49
|
}
|
|
38
50
|
|
|
39
|
-
|
|
40
51
|
def get_path(self, instance, url_info):
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
except NotImplementedError:
|
|
52
|
+
detail_url_name = self.get_detail_url_name(instance)
|
|
53
|
+
if not detail_url_name:
|
|
44
54
|
return None
|
|
45
55
|
|
|
46
56
|
detail_url_info = self.get_detail_url_info(instance, url_info)
|
|
@@ -69,7 +79,7 @@ class DocumentPathField(CharField):
|
|
|
69
79
|
return None
|
|
70
80
|
|
|
71
81
|
|
|
72
|
-
class AttachmentFileField(CharField):
|
|
82
|
+
class AttachmentFileField(fields.CharField):
|
|
73
83
|
def get_attribute(self, instance):
|
|
74
84
|
_, filename = os.path.split(instance.file.name)
|
|
75
85
|
|
|
@@ -87,7 +97,7 @@ class AttachmentFileField(CharField):
|
|
|
87
97
|
return file_url
|
|
88
98
|
|
|
89
99
|
|
|
90
|
-
class Base64ImageField(CharField):
|
|
100
|
+
class Base64ImageField(fields.CharField):
|
|
91
101
|
def __init__(self, source_attr, **kwargs):
|
|
92
102
|
super().__init__(**kwargs)
|
|
93
103
|
|
|
@@ -107,3 +117,7 @@ class Base64ImageField(CharField):
|
|
|
107
117
|
return prefix + str(base64_image, 'utf-8')
|
|
108
118
|
except FileNotFoundError:
|
|
109
119
|
return None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class UUIDListField(fields.ListField):
|
|
123
|
+
child = fields.UUIDField()
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from django.contrib.sites.models import Site
|
|
2
|
+
from django.conf import settings
|
|
3
|
+
from django.templatetags.static import static
|
|
4
|
+
|
|
5
|
+
from mail_templated import EmailMessage
|
|
6
|
+
|
|
7
|
+
from .settings import appkit_settings
|
|
8
|
+
from .shortcuts import site_url_base
|
|
9
|
+
|
|
10
|
+
get_current_site = appkit_settings.CURRENT_SITE_ACCESSOR
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AppkitEmailMessage(EmailMessage):
|
|
14
|
+
sender = settings.DEFAULT_FROM_EMAIL_SENDER
|
|
15
|
+
|
|
16
|
+
def __init__(self, template_name=None, site=None, context=None, *args, **kwargs):
|
|
17
|
+
email_context = dict(context) if context else {}
|
|
18
|
+
|
|
19
|
+
app_site_url = site_url_base(None)
|
|
20
|
+
email_context.update({
|
|
21
|
+
'app_name': settings.PROJECT_NAME,
|
|
22
|
+
'app_site_url': app_site_url,
|
|
23
|
+
'app_icon_url': f'{app_site_url}{static("images/icon/android-chrome-192x192.png")}',
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
if site:
|
|
27
|
+
email_context.update({
|
|
28
|
+
'site_name': site.name,
|
|
29
|
+
'site_url': site_url_base(site),
|
|
30
|
+
})
|
|
31
|
+
if site.profile.icon:
|
|
32
|
+
email_context['site_icon_url'] = site.profile.icon.image.thumbnail['192x192']
|
|
33
|
+
|
|
34
|
+
super().__init__(template_name, email_context, *args, **kwargs)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def send(self, *args, **kwargs):
|
|
38
|
+
if not self.sender and 'site' in self.context:
|
|
39
|
+
self.sender = self.context['site'].name
|
|
40
|
+
|
|
41
|
+
self.from_email = f"{self.sender} <{self.from_email}>"
|
|
42
|
+
self.cc = kwargs.pop('cc', [])
|
|
43
|
+
self.bcc = kwargs.pop('bcc', [])
|
|
44
|
+
self.reply_to = kwargs.pop('reply_to', [])
|
|
45
|
+
|
|
46
|
+
self.context['allow_reply'] = True if self.reply_to else False
|
|
47
|
+
|
|
48
|
+
super(AppkitEmailMessage, self).send(*args, **kwargs)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Generated by Django 4.0.5 on 2023-06-22 22:59
|
|
2
|
+
|
|
3
|
+
from django.db import migrations, models
|
|
4
|
+
import django.db.models.deletion
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
|
|
9
|
+
dependencies = [
|
|
10
|
+
('contenttypes', '0002_remove_content_type_name'),
|
|
11
|
+
('appkit', '0013_usergroup'),
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
operations = [
|
|
15
|
+
migrations.RemoveField(
|
|
16
|
+
model_name='note',
|
|
17
|
+
name='notes',
|
|
18
|
+
),
|
|
19
|
+
migrations.AddField(
|
|
20
|
+
model_name='note',
|
|
21
|
+
name='content_type',
|
|
22
|
+
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype'),
|
|
23
|
+
),
|
|
24
|
+
migrations.AddField(
|
|
25
|
+
model_name='note',
|
|
26
|
+
name='object_id',
|
|
27
|
+
field=models.PositiveIntegerField(null=True),
|
|
28
|
+
),
|
|
29
|
+
]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Generated by Django 4.0.5 on 2023-06-23 01:09
|
|
2
|
+
|
|
3
|
+
from django.db import migrations, models
|
|
4
|
+
import django.db.models.deletion
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
|
|
9
|
+
dependencies = [
|
|
10
|
+
('contenttypes', '0002_remove_content_type_name'),
|
|
11
|
+
('appkit', '0014_remove_note_notes_note_content_type_note_object_id'),
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
operations = [
|
|
15
|
+
migrations.AlterField(
|
|
16
|
+
model_name='note',
|
|
17
|
+
name='content_type',
|
|
18
|
+
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype'),
|
|
19
|
+
preserve_default=False,
|
|
20
|
+
),
|
|
21
|
+
migrations.AlterField(
|
|
22
|
+
model_name='note',
|
|
23
|
+
name='object_id',
|
|
24
|
+
field=models.PositiveIntegerField(),
|
|
25
|
+
preserve_default=False,
|
|
26
|
+
),
|
|
27
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Generated by Django 4.0.5 on 2023-06-28 10:06
|
|
2
|
+
|
|
3
|
+
import django.core.serializers.json
|
|
4
|
+
from django.db import migrations, models
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
|
|
9
|
+
dependencies = [
|
|
10
|
+
('appkit', '0015_alter_note_content_type_alter_note_object_id'),
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
operations = [
|
|
14
|
+
migrations.AlterUniqueTogether(
|
|
15
|
+
name='arrangementitem',
|
|
16
|
+
unique_together=set(),
|
|
17
|
+
),
|
|
18
|
+
migrations.AddField(
|
|
19
|
+
model_name='arrangement',
|
|
20
|
+
name='attributes',
|
|
21
|
+
field=models.JSONField(default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder),
|
|
22
|
+
),
|
|
23
|
+
migrations.AlterField(
|
|
24
|
+
model_name='arrangement',
|
|
25
|
+
name='type',
|
|
26
|
+
field=models.CharField(default='arrangement', max_length=20),
|
|
27
|
+
preserve_default=False,
|
|
28
|
+
),
|
|
29
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Generated by Django 4.0.5 on 2023-07-01 05:43
|
|
2
|
+
|
|
3
|
+
import appkit.storages
|
|
4
|
+
import appkit.util
|
|
5
|
+
from django.db import migrations
|
|
6
|
+
import versatileimagefield.fields
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Migration(migrations.Migration):
|
|
10
|
+
|
|
11
|
+
dependencies = [
|
|
12
|
+
('appkit', '0016_alter_arrangementitem_unique_together_and_more'),
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
operations = [
|
|
16
|
+
migrations.AlterField(
|
|
17
|
+
model_name='imageattachment',
|
|
18
|
+
name='image',
|
|
19
|
+
field=versatileimagefield.fields.VersatileImageField(max_length=255, storage=appkit.storages.MediaStorage(), upload_to=appkit.util.UploadImageAttachmentTo()),
|
|
20
|
+
),
|
|
21
|
+
]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Generated by Django 4.0.5 on 2023-08-18 10:21
|
|
2
|
+
|
|
3
|
+
import django.contrib.gis.db.models.fields
|
|
4
|
+
from django.db import migrations
|
|
5
|
+
|
|
6
|
+
from django.contrib.gis.geos import Point
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def populate_existing_place_geopositions(apps, schema_editor):
|
|
10
|
+
Place = apps.get_model('appkit', 'Place')
|
|
11
|
+
|
|
12
|
+
for place in Place.objects.all():
|
|
13
|
+
place_info = place.info
|
|
14
|
+
location = place_info['geometry']['location']
|
|
15
|
+
place.geoposition = Point(location['lng'], location['lat'])
|
|
16
|
+
place.save()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Migration(migrations.Migration):
|
|
20
|
+
|
|
21
|
+
dependencies = [
|
|
22
|
+
('appkit', '0017_alter_imageattachment_image'),
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
operations = [
|
|
26
|
+
migrations.AddField(
|
|
27
|
+
model_name='place',
|
|
28
|
+
name='geoposition',
|
|
29
|
+
field=django.contrib.gis.db.models.fields.PointField(blank=True, geography=True, null=True, srid=4326),
|
|
30
|
+
),
|
|
31
|
+
|
|
32
|
+
migrations.RunPython(populate_existing_place_geopositions, reverse_code=migrations.RunPython.noop)
|
|
33
|
+
]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Generated by Django 4.0.5 on 2023-08-18 10:53
|
|
2
|
+
|
|
3
|
+
import django.contrib.gis.db.models.fields
|
|
4
|
+
from django.db import migrations
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Migration(migrations.Migration):
|
|
8
|
+
|
|
9
|
+
dependencies = [
|
|
10
|
+
('appkit', '0018_place_geoposition'),
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
operations = [
|
|
14
|
+
migrations.AlterField(
|
|
15
|
+
model_name='place',
|
|
16
|
+
name='geoposition',
|
|
17
|
+
field=django.contrib.gis.db.models.fields.PointField(geography=True, srid=4326),
|
|
18
|
+
),
|
|
19
|
+
]
|
|
@@ -22,6 +22,7 @@ from treebeard.mp_tree import MP_Node
|
|
|
22
22
|
from versatileimagefield.fields import VersatileImageField
|
|
23
23
|
|
|
24
24
|
from .managers import DocumentManager
|
|
25
|
+
from .storages import MediaStorage
|
|
25
26
|
from .util import (
|
|
26
27
|
bumpy_case_words,
|
|
27
28
|
UploadImageAttachmentTo,
|
|
@@ -179,6 +180,7 @@ class ModelBase(models.Model):
|
|
|
179
180
|
|
|
180
181
|
class Place(ModelBase):
|
|
181
182
|
place_id = models.CharField(max_length=255, unique=True)
|
|
183
|
+
geoposition = PointField(geography=True)
|
|
182
184
|
info = models.JSONField()
|
|
183
185
|
|
|
184
186
|
def __str__(self):
|
|
@@ -265,13 +267,6 @@ class Document(ModelBase):
|
|
|
265
267
|
class Meta:
|
|
266
268
|
abstract = True
|
|
267
269
|
|
|
268
|
-
# DRY-rest-permissions
|
|
269
|
-
def has_object_read_permission(self, request):
|
|
270
|
-
return self.site == request.site
|
|
271
|
-
|
|
272
|
-
def has_object_write_permission(self, request):
|
|
273
|
-
return self.site == request.site
|
|
274
|
-
|
|
275
270
|
@staticmethod
|
|
276
271
|
def merge_strategy():
|
|
277
272
|
return {}
|
|
@@ -314,7 +309,7 @@ class ImageAttachment(Document):
|
|
|
314
309
|
object_id = models.PositiveIntegerField()
|
|
315
310
|
object = GenericForeignKey('content_type', 'object_id')
|
|
316
311
|
|
|
317
|
-
image = VersatileImageField(max_length=255, upload_to=UploadImageAttachmentTo())
|
|
312
|
+
image = VersatileImageField(max_length=255, storage=MediaStorage(), upload_to=UploadImageAttachmentTo())
|
|
318
313
|
width = models.IntegerField()
|
|
319
314
|
height = models.IntegerField()
|
|
320
315
|
|
|
@@ -346,11 +341,14 @@ class Note(Document):
|
|
|
346
341
|
class Meta:
|
|
347
342
|
ordering = ('-date_created',)
|
|
348
343
|
|
|
344
|
+
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
|
345
|
+
object_id = models.PositiveIntegerField()
|
|
346
|
+
object = GenericForeignKey('content_type', 'object_id')
|
|
347
|
+
|
|
349
348
|
subject = models.CharField(max_length=255)
|
|
350
349
|
text = models.TextField(blank=True, default='')
|
|
351
350
|
|
|
352
351
|
attachments = GenericRelation(Attachment)
|
|
353
|
-
notes = models.ManyToManyField('self', blank=True, symmetrical=True)
|
|
354
352
|
|
|
355
353
|
def __str__(self):
|
|
356
354
|
return self.subject
|
|
@@ -362,8 +360,9 @@ class Thing(models.Model):
|
|
|
362
360
|
description = models.TextField(blank=True)
|
|
363
361
|
|
|
364
362
|
attachments = GenericRelation(Attachment)
|
|
365
|
-
feature_image = models.OneToOneField(ImageAttachment, blank=True, null=True, on_delete=models.SET_NULL)
|
|
366
363
|
images = GenericRelation(ImageAttachment)
|
|
364
|
+
notes = GenericRelation(Note)
|
|
365
|
+
feature_image = models.OneToOneField(ImageAttachment, blank=True, null=True, on_delete=models.SET_NULL)
|
|
367
366
|
place = models.ForeignKey(Place, blank=True, null=True, on_delete=models.SET_NULL)
|
|
368
367
|
region = models.ForeignKey(Region, blank=True, null=True, on_delete=models.SET_NULL)
|
|
369
368
|
geoposition = PointField(geography=True, blank=True, null=True)
|
|
@@ -380,7 +379,6 @@ class Thing(models.Model):
|
|
|
380
379
|
class Product(Thing):
|
|
381
380
|
price = MoneyField(max_digits=14, decimal_places=2, blank=True, null=True, default_currency=None)
|
|
382
381
|
sku = models.CharField(max_length=64, blank=True, null=True)
|
|
383
|
-
notes = models.ManyToManyField(Note, blank=True, related_name='%(class)s_notes')
|
|
384
382
|
|
|
385
383
|
class Meta:
|
|
386
384
|
abstract = True
|
|
@@ -388,7 +386,8 @@ class Product(Thing):
|
|
|
388
386
|
|
|
389
387
|
class Arrangement(Document):
|
|
390
388
|
name = models.CharField(max_length=100)
|
|
391
|
-
type = models.CharField(max_length=20
|
|
389
|
+
type = models.CharField(max_length=20)
|
|
390
|
+
attributes = models.JSONField(default=dict, encoder=DjangoJSONEncoder)
|
|
392
391
|
|
|
393
392
|
def __str__(self):
|
|
394
393
|
return f'{self.name} ({self.type})' if self.type else self.name
|
|
@@ -407,7 +406,6 @@ class ArrangementItem(Document):
|
|
|
407
406
|
|
|
408
407
|
class Meta:
|
|
409
408
|
ordering = ('position',)
|
|
410
|
-
unique_together = ('arrangement', 'content_type', 'object_id',)
|
|
411
409
|
|
|
412
410
|
|
|
413
411
|
class SiteAlias(ModelBase):
|
|
@@ -28,11 +28,16 @@ def get_current_site(request):
|
|
|
28
28
|
return Site.objects.get(domain=url_info.netloc)
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
def site_url_base(site):
|
|
32
|
-
if site.aliases.exists():
|
|
33
|
-
site = site.aliases.first()
|
|
31
|
+
def site_url_base(site=None):
|
|
34
32
|
scheme = 'http' if settings.DEBUG else 'https'
|
|
35
|
-
|
|
33
|
+
|
|
34
|
+
if site:
|
|
35
|
+
if site.aliases.exists():
|
|
36
|
+
site = site.aliases.first()
|
|
37
|
+
domain = site.domain
|
|
38
|
+
else:
|
|
39
|
+
domain = settings.TLD
|
|
40
|
+
return f'{scheme}://{domain}'
|
|
36
41
|
|
|
37
42
|
|
|
38
43
|
def public_document_url(document):
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from django.conf import settings
|
|
2
|
+
|
|
3
|
+
from storages.backends.s3boto3 import S3Boto3Storage
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MediaStorage(S3Boto3Storage):
|
|
7
|
+
bucket_name = settings.AWS_MEDIA_STORAGE_BUCKET_NAME
|
|
8
|
+
|
|
9
|
+
def __init__(self, **settings):
|
|
10
|
+
super().__init__(**settings)
|
|
11
|
+
self.custom_domain = self.bucket_name
|
|
@@ -195,7 +195,7 @@ def value_for_attr_path(obj, attr_path):
|
|
|
195
195
|
return value
|
|
196
196
|
|
|
197
197
|
|
|
198
|
-
def value_for_key_path(object, keypath, default=None):
|
|
198
|
+
def value_for_key_path(object, keypath, default=None, raise_exception=False):
|
|
199
199
|
"""
|
|
200
200
|
Provide access to a property chain
|
|
201
201
|
"""
|
|
@@ -203,18 +203,15 @@ def value_for_key_path(object, keypath, default=None):
|
|
|
203
203
|
|
|
204
204
|
keys = keypath.split('.')
|
|
205
205
|
for key in keys:
|
|
206
|
-
if not target_object:
|
|
207
|
-
if default != None:
|
|
208
|
-
return default
|
|
209
|
-
raise KeyError('Keypath "{}" could not be resolved to a value'.format(keypath))
|
|
210
|
-
|
|
211
206
|
try:
|
|
212
207
|
if isinstance(target_object, dict):
|
|
213
208
|
target_object = target_object[key]
|
|
214
209
|
else:
|
|
215
210
|
target_object = target_object.__getitem__(key)
|
|
216
211
|
except (KeyError, AttributeError) as e:
|
|
217
|
-
|
|
212
|
+
if raise_exception:
|
|
213
|
+
raise KeyError('Keypath "{}" could not be resolved to a value'.format(keypath))
|
|
214
|
+
return default
|
|
218
215
|
|
|
219
216
|
return target_object
|
|
220
217
|
|
|
@@ -254,8 +251,7 @@ def hashed_filename(image_file):
|
|
|
254
251
|
with open(image_file, 'rb') as source_file:
|
|
255
252
|
hash.update(source_file.read())
|
|
256
253
|
else:
|
|
257
|
-
|
|
258
|
-
hash.update(chunk)
|
|
254
|
+
hash.update(image_file.tobytes())
|
|
259
255
|
return hash.hexdigest()
|
|
260
256
|
|
|
261
257
|
|
|
@@ -9,6 +9,7 @@ appkit/managers.py
|
|
|
9
9
|
appkit/models.py
|
|
10
10
|
appkit/settings.py
|
|
11
11
|
appkit/shortcuts.py
|
|
12
|
+
appkit/storages.py
|
|
12
13
|
appkit/util.py
|
|
13
14
|
appkit/views.py
|
|
14
15
|
appkit/api/__init__.py
|
|
@@ -49,6 +50,12 @@ appkit/migrations/0010_arrangement_name.py
|
|
|
49
50
|
appkit/migrations/0011_alter_sitealias_options.py
|
|
50
51
|
appkit/migrations/0012_alter_sitealias_site.py
|
|
51
52
|
appkit/migrations/0013_usergroup.py
|
|
53
|
+
appkit/migrations/0014_remove_note_notes_note_content_type_note_object_id.py
|
|
54
|
+
appkit/migrations/0015_alter_note_content_type_alter_note_object_id.py
|
|
55
|
+
appkit/migrations/0016_alter_arrangementitem_unique_together_and_more.py
|
|
56
|
+
appkit/migrations/0017_alter_imageattachment_image.py
|
|
57
|
+
appkit/migrations/0018_place_geoposition.py
|
|
58
|
+
appkit/migrations/0019_alter_place_geoposition.py
|
|
52
59
|
appkit/migrations/__init__.py
|
|
53
60
|
drf_appkit.egg-info/PKG-INFO
|
|
54
61
|
drf_appkit.egg-info/SOURCES.txt
|
drf-appkit-0.9.1/appkit/email.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
from django.contrib.sites.models import Site
|
|
2
|
-
from django.conf import settings
|
|
3
|
-
from django.templatetags.static import static
|
|
4
|
-
|
|
5
|
-
from mail_templated import EmailMessage
|
|
6
|
-
|
|
7
|
-
from .settings import appkit_settings
|
|
8
|
-
from .shortcuts import site_url_base
|
|
9
|
-
|
|
10
|
-
get_current_site = appkit_settings.CURRENT_SITE_ACCESSOR
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class AppkitEmailMessage(EmailMessage):
|
|
14
|
-
def __init__(self, template_name=None, context=dict, *args, **kwargs):
|
|
15
|
-
if not 'site' in context and 'request' in context:
|
|
16
|
-
context['site'] = get_current_site(context['request'])
|
|
17
|
-
|
|
18
|
-
site = context.get('site')
|
|
19
|
-
if not isinstance(site, Site):
|
|
20
|
-
raise ValueError('Site could not be resolved from given context')
|
|
21
|
-
|
|
22
|
-
if site.profile.icon:
|
|
23
|
-
icon_url = site.profile.icon.image.thumbnail['192x192']
|
|
24
|
-
else:
|
|
25
|
-
icon_url = f'{site_url_base(site)}{static("images/icon/android-chrome-192x192.png")}'
|
|
26
|
-
context['icon_url'] = icon_url
|
|
27
|
-
|
|
28
|
-
if 'user' not in context and 'request' in context:
|
|
29
|
-
context['user'] = context['request'].user
|
|
30
|
-
|
|
31
|
-
super().__init__(template_name, context, *args, **kwargs)
|
|
32
|
-
|
|
33
|
-
@property
|
|
34
|
-
def from_email_address(self):
|
|
35
|
-
return settings.DEFAULT_FROM_EMAIL
|
|
36
|
-
|
|
37
|
-
def send(self, *args, **kwargs):
|
|
38
|
-
from_email_sender = self.from_email_sender if hasattr(self, 'from_email_sender') else self.context['site'].name
|
|
39
|
-
self.from_email = f'"{from_email_sender}" <{self.from_email_address}>'
|
|
40
|
-
|
|
41
|
-
self.cc = kwargs.pop('cc', [])
|
|
42
|
-
self.bcc = kwargs.pop('bcc', [])
|
|
43
|
-
self.reply_to = kwargs.pop('reply_to', [])
|
|
44
|
-
|
|
45
|
-
super(AppkitEmailMessage, self).send(*args, **kwargs)
|
|
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
|
|
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
|