drf-appkit 0.5.3__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.
Files changed (66) hide show
  1. {drf-appkit-0.5.3/drf_appkit.egg-info → drf-appkit-1.1.2}/PKG-INFO +1 -5
  2. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/filters.py +17 -1
  3. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/mixins.py +35 -39
  4. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/serializers.py +143 -91
  5. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/tests.py +67 -47
  6. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/views.py +29 -28
  7. drf-appkit-1.1.2/appkit/auth/email.py +46 -0
  8. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/debug.py +12 -4
  9. drf-appkit-1.1.2/appkit/drf/authentication.py +29 -0
  10. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/fields.py +30 -22
  11. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/serializers.py +1 -1
  12. drf-appkit-1.1.2/appkit/email.py +48 -0
  13. drf-appkit-1.1.2/appkit/migrations/0006_sitealias.py +26 -0
  14. drf-appkit-1.1.2/appkit/migrations/0007_auto_20211021_1901.py +18 -0
  15. drf-appkit-1.1.2/appkit/migrations/0008_update_autofields.py +46 -0
  16. drf-appkit-1.1.2/appkit/migrations/0009_alter_arrangement_unique_together_and_more.py +41 -0
  17. drf-appkit-1.1.2/appkit/migrations/0010_arrangement_name.py +19 -0
  18. drf-appkit-1.1.2/appkit/migrations/0011_alter_sitealias_options.py +17 -0
  19. drf-appkit-1.1.2/appkit/migrations/0012_alter_sitealias_site.py +20 -0
  20. drf-appkit-1.1.2/appkit/migrations/0013_usergroup.py +35 -0
  21. drf-appkit-1.1.2/appkit/migrations/0014_remove_note_notes_note_content_type_note_object_id.py +29 -0
  22. drf-appkit-1.1.2/appkit/migrations/0015_alter_note_content_type_alter_note_object_id.py +27 -0
  23. drf-appkit-1.1.2/appkit/migrations/0016_alter_arrangementitem_unique_together_and_more.py +29 -0
  24. drf-appkit-1.1.2/appkit/migrations/0017_alter_imageattachment_image.py +21 -0
  25. drf-appkit-1.1.2/appkit/migrations/0018_place_geoposition.py +33 -0
  26. drf-appkit-1.1.2/appkit/migrations/0019_alter_place_geoposition.py +19 -0
  27. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/models.py +77 -55
  28. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/settings.py +2 -1
  29. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/shortcuts.py +26 -4
  30. drf-appkit-1.1.2/appkit/storages.py +11 -0
  31. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/util.py +5 -9
  32. {drf-appkit-0.5.3 → drf-appkit-1.1.2/drf_appkit.egg-info}/PKG-INFO +1 -5
  33. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/drf_appkit.egg-info/SOURCES.txt +16 -0
  34. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/setup.cfg +1 -1
  35. drf-appkit-0.5.3/appkit/auth/email.py +0 -36
  36. drf-appkit-0.5.3/appkit/email.py +0 -50
  37. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/LICENSE +0 -0
  38. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/README.md +0 -0
  39. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/__init__.py +0 -0
  40. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/__init__.py +0 -0
  41. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/metadata.py +0 -0
  42. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/pagination.py +0 -0
  43. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/relations.py +0 -0
  44. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/api/renderers.py +0 -0
  45. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/auth/__init__.py +0 -0
  46. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/auth/backends.py +0 -0
  47. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/auth/decorators.py +0 -0
  48. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/auth/permissions.py +0 -0
  49. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/__init__.py +0 -0
  50. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/backends.py +0 -0
  51. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/exceptions.py +0 -0
  52. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/filters.py +0 -0
  53. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/metadata.py +0 -0
  54. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/mixins.py +0 -0
  55. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/drf/permissions.py +0 -0
  56. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/managers.py +0 -0
  57. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/migrations/0001_initial.py +0 -0
  58. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/migrations/0002_arrangement_tags.py +0 -0
  59. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/migrations/0003_auto_20210221_0852.py +0 -0
  60. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/migrations/0004_auto_20210309_0655.py +0 -0
  61. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/migrations/0005_auto_20210324_1046.py +0 -0
  62. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/migrations/__init__.py +0 -0
  63. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/appkit/views.py +0 -0
  64. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/drf_appkit.egg-info/dependency_links.txt +0 -0
  65. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/drf_appkit.egg-info/top_level.txt +0 -0
  66. {drf-appkit-0.5.3 → drf-appkit-1.1.2}/setup.py +0 -0
@@ -1,11 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: drf-appkit
3
- Version: 0.5.3
3
+ Version: 1.1.2
4
4
  Summary: A Django app providing generic CRUD functionality
5
- Home-page: UNKNOWN
6
5
  Author: Allan Hart
7
6
  License: BSD
8
- Platform: UNKNOWN
9
7
  Classifier: Environment :: Web Environment
10
8
  Classifier: Framework :: Django
11
9
  Classifier: Framework :: Django :: 3.1
@@ -23,5 +21,3 @@ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
23
21
  License-File: LICENSE
24
22
 
25
23
  # drf-appkit
26
-
27
-
@@ -1,5 +1,6 @@
1
1
  from django.contrib.auth import get_user_model
2
2
  from django.contrib.auth.models import Group
3
+ from django.contrib.sites.models import Site
3
4
 
4
5
  import rest_framework_filters as filters
5
6
 
@@ -30,13 +31,15 @@ def choices_for_region():
30
31
 
31
32
  class DocumentFilter(FilterSet):
32
33
  date_created = filters.DateFromToRangeFilter()
34
+ date_modified = filters.DateFromToRangeFilter()
33
35
 
34
36
 
35
37
  class GroupFilter(FilterSet):
36
38
  class Meta:
37
39
  model = Group
38
40
  fields = {
39
- 'name': ('exact', 'in',)
41
+ 'id': ('exact', 'in',),
42
+ 'name': ('exact', 'in',),
40
43
  }
41
44
 
42
45
 
@@ -49,6 +52,7 @@ class NoteFilter(FilterSet):
49
52
  'text': ('icontains',),
50
53
  }
51
54
 
55
+
52
56
  class RegionFilter(FilterSet):
53
57
  class Meta:
54
58
  model = Region
@@ -59,6 +63,16 @@ class RegionFilter(FilterSet):
59
63
  }
60
64
 
61
65
 
66
+ class SiteFilter(FilterSet):
67
+ class Meta:
68
+ model = Site
69
+ fields = {
70
+ 'id': ('exact', 'in',),
71
+ 'name': ('exact',),
72
+ 'domain': ('exact',),
73
+ }
74
+
75
+
62
76
  class TagFilter(FilterSet):
63
77
  class Meta:
64
78
  model = Tag
@@ -82,6 +96,7 @@ class UserFilter(FilterSet):
82
96
  fields = {
83
97
  'id': ('exact', 'in',),
84
98
  'is_active': ('exact',),
99
+ 'is_staff': ('exact',),
85
100
  'first_name': ('exact', 'startswith', 'icontains'),
86
101
  'last_name': ('exact', 'startswith', 'icontains'),
87
102
  'username': ('exact', 'startswith', 'icontains'),
@@ -95,6 +110,7 @@ class ArrangementFilter(DocumentFilter):
95
110
  fields = {
96
111
  'id': ('exact', 'in',),
97
112
  'type': ('exact',),
113
+ 'name': ('exact',),
98
114
  }
99
115
 
100
116
 
@@ -8,29 +8,31 @@ from django.conf import settings
8
8
  from django.contrib.auth import get_user_model
9
9
  from django.contrib.contenttypes.models import ContentType
10
10
  from django.core.files.uploadedfile import InMemoryUploadedFile
11
+ from django.db import transaction
11
12
 
12
- from rest_framework import status
13
+ from rest_framework import status, serializers
13
14
  from rest_framework.decorators import action
14
15
  from rest_framework.response import Response
15
16
  from rest_framework.serializers import ValidationError
16
17
 
18
+ from filedepot.mixins import FlowFileUploadMixin
19
+
17
20
  from ..models import (
18
21
  Attachment,
19
- ImageAttachment,
20
22
  Tag,
21
23
  )
22
24
  from ..util import hashed_filename
23
- from ..shortcuts import get_current_site
24
-
25
- from filedepot.mixins import FlowFileUploadMixin
25
+ from ..settings import appkit_settings
26
+ from . import serializers
26
27
 
27
28
  User = get_user_model()
29
+ get_current_site = appkit_settings.CURRENT_SITE_ACCESSOR
28
30
 
29
31
 
30
32
  # ------------------------------------------------------------------------------
31
33
  # ViewSet Mixins
32
34
  # ------------------------------------------------------------------------------
33
- class DocumentViewSetMixin:
35
+ class DocumentViewSetMixin(object):
34
36
  def get_queryset(self):
35
37
  queryset = super().get_queryset()
36
38
  current_site = get_current_site(self.request)
@@ -39,16 +41,15 @@ class DocumentViewSetMixin:
39
41
 
40
42
  class AttachmentMixin(FlowFileUploadMixin):
41
43
  @action(detail=True, methods=['delete'])
42
- def delete_attachment(self, request, pk, **kwargs):
44
+ def delete_attachment(self, request, uuid, **kwargs):
43
45
  attachment = Attachment.objects.get(uuid=request.data['item_uuid'])
44
46
  attachment.delete()
45
47
 
46
48
  serializer = self.get_serializer(self.get_object())
47
49
  return Response(serializer.data)
48
50
 
49
-
50
51
  @action(detail=True, methods=['get', 'post'])
51
- def add_attachment(self, request, pk, **kwargs):
52
+ def add_attachment(self, request, uuid, **kwargs):
52
53
  result = self.handle_flow_request(request)
53
54
 
54
55
  response_data = {}
@@ -74,34 +75,20 @@ class AttachmentMixin(FlowFileUploadMixin):
74
75
 
75
76
  return Response(response_data, status=result['status'])
76
77
 
78
+ """
77
79
  @action(detail=True, methods=['delete'])
78
- def delete_image(self, request, pk, **kwargs):
80
+ def delete_image(self, request, uuid, **kwargs):
79
81
  image_attachment = ImageAttachment.objects.get(uuid=request.data['item_uuid'])
80
82
  image_attachment.delete()
81
83
 
82
84
  serializer = self.get_serializer(self.get_object())
83
85
  return Response(serializer.data)
84
86
 
85
-
86
87
  @action(detail=True, methods=['post'])
87
- def add_image(self, request, pk, **kwargs):
88
+ def add_image(self, request, uuid, **kwargs):
88
89
  obj = self.get_object()
89
- request_params = self.get_request_params(request)
90
-
91
- # Distinguish if request was issued by flow.js.
92
- # If it was, and if it is finished, process the file.
93
- flow_file = None
94
- flow_identifier = request_params.get('flowIdentifier')
95
- if flow_identifier:
96
- result = self.handle_flow_request(request)
97
- if not result['finished']:
98
- return Response({}, status=result['status'])
99
-
100
- flow_file = result['file']
101
- image_file = flow_file.django_file()
102
- else:
103
- image_file = request.FILES['image']
104
90
 
91
+ image_file = request.FILES['image']
105
92
  with image_file.open() as image_stream:
106
93
  # First off, verify that the uploaded file is in fact an image
107
94
  try:
@@ -112,7 +99,6 @@ class AttachmentMixin(FlowFileUploadMixin):
112
99
  # Let the final image filename be determined as a hash the bytes
113
100
  # of the originally uploaded image file
114
101
  image_hash = hashed_filename(image_file)
115
- image_filename = '{}.jpg'.format(image_hash)
116
102
 
117
103
  # Since we're always writing out to JPEG, discard alpha channel, if any (ex: PNG images)
118
104
  if not image.mode == 'RGB':
@@ -134,7 +120,7 @@ class AttachmentMixin(FlowFileUploadMixin):
134
120
  resized_image_file = InMemoryUploadedFile(
135
121
  file=image_bytes,
136
122
  field_name='image',
137
- name=image_filename,
123
+ name=f'{image_hash}.jpg',
138
124
  content_type='image/jpeg',
139
125
  size=sys.getsizeof(image_bytes),
140
126
  charset=None
@@ -142,9 +128,10 @@ class AttachmentMixin(FlowFileUploadMixin):
142
128
 
143
129
  # Position the newly uploaded image at the end of the collection
144
130
  image_position = 0
145
- images = obj.images.all()
146
- if obj.images.count():
147
- image_position = images.last().position + 1
131
+ if hasattr(obj, 'images'):
132
+ images = obj.images.all()
133
+ if images.count():
134
+ image_position = images.last().position + 1
148
135
 
149
136
  image_attachment = ImageAttachment.objects.create(
150
137
  content_type=ContentType.objects.get_for_model(obj),
@@ -162,13 +149,22 @@ class AttachmentMixin(FlowFileUploadMixin):
162
149
  obj.feature_image = image_attachment
163
150
  obj.save()
164
151
 
165
- # An image attachment has been generated from the constructed file
166
- # so the flow_file can be safely be discarded
167
- if flow_file:
168
- flow_file.delete()
169
-
170
152
  serializer = self.get_serializer(obj)
171
- return Response(serializer.data, status=status.HTTP_201_CREATED)
153
+ serialized_data = serializer.data
154
+ serialized_data['image_attachment_uuid'] = image_attachment.uuid
155
+
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)
172
168
 
173
169
 
174
170
  # ------------------------------------------------------------------------------
@@ -204,7 +200,7 @@ class TaggableMixin(object):
204
200
  return Response(serializer.data)
205
201
 
206
202
  @action(detail=True, methods=['post'])
207
- def update_tags(self, request, pk, **kwargs):
203
+ def update_tags(self, request, uuid, **kwargs):
208
204
  obj = self.get_object()
209
205
 
210
206
  ids_to_add = request.data.get('ids_to_add')
@@ -14,9 +14,11 @@ from django.contrib.auth.password_validation import validate_password
14
14
  from django.core import exceptions as django_exceptions
15
15
 
16
16
  from rest_framework import serializers
17
+ from rest_framework import exceptions
17
18
 
18
- from djoser.conf import settings as djoser_settings
19
+ from rest_framework_recursive.fields import RecursiveField
19
20
 
21
+ from djoser.conf import settings as djoser_settings
20
22
  from djoser.serializers import (
21
23
  ActivationSerializer as DjoserActivationSerializer,
22
24
  UserCreateSerializer as DjoserUserCreateSerializer,
@@ -27,33 +29,36 @@ from phonenumber_field.serializerfields import PhoneNumberField
27
29
  from versatileimagefield.serializers import VersatileImageFieldSerializer
28
30
 
29
31
  from ..auth import get_userprofile_model
30
- from ..shortcuts import get_current_site
31
32
 
32
- from ..drf.serializers import (
33
- IntegerListField,
34
- StringListField,
33
+ from ..drf.fields import (
34
+ UUIDListField,
35
35
  )
36
36
 
37
37
  from ..drf.fields import (
38
38
  AttachmentFileField,
39
39
  DocumentPathField,
40
- DocumentTypeField,
40
+ ContentTypeField,
41
41
  )
42
42
 
43
43
  from ..models import (
44
+ ArrangementItem,
44
45
  Attachment,
45
46
  ImageAttachment,
46
47
  Note,
47
48
  Place,
48
49
  Region,
50
+ SiteAlias,
49
51
  Tag,
50
52
  )
51
53
 
54
+ from ..settings import appkit_settings
52
55
  from ..shortcuts import image_variation_size
53
56
 
54
57
  User = get_user_model()
55
58
  UserProfile = get_userprofile_model()
56
59
 
60
+ get_current_site = appkit_settings.CURRENT_SITE_ACCESSOR
61
+
57
62
 
58
63
  class PermissionsMixin(object):
59
64
  def get_permissions(self, obj):
@@ -93,76 +98,31 @@ class PermissionSerializer(serializers.Serializer):
93
98
  return attrs
94
99
 
95
100
 
96
- class SiteSerializer(serializers.ModelSerializer):
101
+ class SiteAliasSerializer(serializers.ModelSerializer):
97
102
  class Meta:
98
- model = Site
99
- fields = (
100
- 'id', 'domain', 'name',
101
- )
103
+ model = SiteAlias
104
+ fields = ('domain',)
102
105
 
103
106
 
104
- class DocumentSerializer(serializers.HyperlinkedModelSerializer):
105
- """
106
- Override the create method to automatically set the created_by field to the
107
- authenticated user who issued the request
108
- """
109
- document_type = DocumentTypeField(read_only=True)
110
- path = DocumentPathField(max_length=100)
107
+ class SiteSerializer(serializers.ModelSerializer):
108
+ aliases = SiteAliasSerializer(many=True)
109
+ public_url = serializers.SerializerMethodField('get_public_url')
111
110
 
112
111
  class Meta:
112
+ model = Site
113
113
  fields = (
114
- 'id', 'uuid', 'url',
115
- 'date_created', 'document_type', 'path',
116
- )
117
-
118
- def create(self, validated_data):
119
- """
120
- Override the create method to automatically set the created_by field to the
121
- authenticated user who issued the request
122
- """
123
- request = self.context.get('request')
124
- if request:
125
- user = request.user
126
- if user and user.is_authenticated:
127
- validated_data['created_by_id'] = user.pk
128
-
129
- validated_data['site'] = get_current_site(request)
130
-
131
- return super().create(validated_data)
132
-
133
- def save(self, **kwargs):
134
- """
135
- Override the save method to create a new revision whenever a document
136
- is created or updated
137
- """
138
- with reversion.create_revision():
139
- instance = super().save(**kwargs)
140
-
141
- request = self.context.get('request')
142
- if request:
143
- reversion.set_user(request.user)
144
-
145
- if request.method == 'POST':
146
- reversion.set_comment('Initial version.')
147
-
148
- if request.method == 'PATCH':
149
- reversion.set_comment(','.join(self.validated_data.keys()))
150
-
151
- return instance
152
-
153
-
154
- class AttachmentSerializer(DocumentSerializer):
155
- content_type = serializers.PrimaryKeyRelatedField(
156
- queryset=ContentType.objects.all()
157
- )
158
-
159
- media_url = AttachmentFileField(read_only=True)
160
-
161
- class Meta(DocumentSerializer.Meta):
162
- model = Attachment
163
- fields = DocumentSerializer.Meta.fields + (
164
- 'content_type', 'media_url', 'object_id',
114
+ 'aliases', 'domain', 'name', 'public_url',
165
115
  )
116
+
117
+ def get_public_url(self, instance):
118
+ request = self.context['request']
119
+
120
+ if instance.aliases.exists():
121
+ site_alias = instance.aliases.first()
122
+ domain = site_alias.domain
123
+ else:
124
+ domain = instance.domain
125
+ return f'{request.scheme}://{domain}'
166
126
 
167
127
 
168
128
  class GroupSerializer(serializers.HyperlinkedModelSerializer):
@@ -177,13 +137,15 @@ class PlaceSerializer(serializers.ModelSerializer):
177
137
 
178
138
  class Meta:
179
139
  model = Place
180
- fields = ('info', 'place_id',)
140
+ fields = ('city', 'info', 'place_id',)
181
141
 
182
142
 
183
143
  class RegionSerializer(serializers.HyperlinkedModelSerializer):
144
+ children = serializers.ListSerializer(child=RecursiveField())
145
+
184
146
  class Meta:
185
147
  model = Region
186
- fields = ('id', 'url', 'name', 'full_name', 'root_name',)
148
+ fields = ('id', 'url', 'name', 'full_name', 'root_name', 'children')
187
149
 
188
150
 
189
151
  class TagSerializer(serializers.HyperlinkedModelSerializer):
@@ -195,6 +157,17 @@ class TagSerializer(serializers.HyperlinkedModelSerializer):
195
157
  )
196
158
 
197
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
+
198
171
  class ImageAttachmentImageSerializer(VersatileImageFieldSerializer):
199
172
  def to_representation(self, value):
200
173
  try:
@@ -227,6 +200,73 @@ class ImageAttachmentImageSerializer(VersatileImageFieldSerializer):
227
200
  return image_info
228
201
 
229
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
+
230
270
  class ImageAttachmentSerializer(DocumentSerializer):
231
271
  def __init__(self, sizes=None, **kwargs):
232
272
  self.sizes = sizes if sizes else kwargs['context'].get('sizes')
@@ -235,27 +275,22 @@ class ImageAttachmentSerializer(DocumentSerializer):
235
275
  class Meta(DocumentSerializer):
236
276
  model = ImageAttachment
237
277
  fields = DocumentSerializer.Meta.fields + (
238
- 'position', 'label', 'width', 'height',
278
+ 'image', 'position', 'label', 'width', 'height',
239
279
  )
240
280
 
241
281
  def get_fields(self):
242
282
  fields = super().get_fields()
243
- fields['image'] = ImageAttachmentImageSerializer(sizes=self.sizes)
283
+
284
+ if self.sizes:
285
+ fields['image'] = ImageAttachmentImageSerializer(sizes=self.sizes)
286
+
244
287
  return fields
245
288
 
246
289
 
290
+
247
291
  # ------------------------------------------------------------------------------
248
292
  # List Serializers
249
293
  # ------------------------------------------------------------------------------
250
- class UserListSerializer(serializers.HyperlinkedModelSerializer):
251
- class Meta:
252
- model = User
253
- fields = (
254
- 'id', 'url', 'is_active',
255
- 'email', 'first_name', 'last_name', 'full_name', 'profile',
256
- )
257
-
258
-
259
294
  class UserProfileListSerializer(DocumentSerializer):
260
295
  user = UserListSerializer(read_only=True)
261
296
 
@@ -276,6 +311,16 @@ class NoteListSerializer(DocumentSerializer):
276
311
  )
277
312
 
278
313
 
314
+ class UserSetSerializer(serializers.Serializer):
315
+ users = serializers.PrimaryKeyRelatedField(
316
+ queryset=User.objects.all(),
317
+ many=True,
318
+ )
319
+
320
+ class Meta:
321
+ fields = ('users',)
322
+
323
+
279
324
  # ------------------------------------------------------------------------------
280
325
  # Detail & Update Serializers
281
326
  # ------------------------------------------------------------------------------
@@ -288,6 +333,9 @@ class GroupDetailSerializer(PermissionsMixin, GroupSerializer):
288
333
  'permissions', 'user_set',
289
334
  )
290
335
 
336
+ def managed_model_classes(self, group):
337
+ return []
338
+
291
339
 
292
340
  class UserDetailSerializer(PermissionsMixin, UserListSerializer):
293
341
  groups = GroupDetailSerializer(read_only=True, many=True)
@@ -389,17 +437,21 @@ class ImageAttachmentEditSerializer(serializers.HyperlinkedModelSerializer):
389
437
  )
390
438
 
391
439
 
392
- class ImageAttachmentBulkRepositionSerializer(serializers.Serializer):
393
- image_attachment_uuids = StringListField()
394
- positions = IntegerListField()
440
+ class ImageAttachmentBulkDeleteSerializer(serializers.Serializer):
441
+ uuids = UUIDListField()
395
442
 
396
- def validate(self, data):
397
- validated_data = super().validate(data)
398
443
 
399
- if len(validated_data['image_attachment_uuids']) != len(validated_data['positions']):
400
- raise serializers.ValidationError('"image_attachment_uuids" and "positions" must be the same length')
401
-
402
- return validated_data
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
+ )
403
455
 
404
456
 
405
457
  class ForcePasswordSerializer(serializers.Serializer):