commonground-api-common 1.12.2__py3-none-any.whl → 1.13.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: commonground-api-common
3
- Version: 1.12.2
3
+ Version: 1.13.1
4
4
  Summary: Commonground API tooling
5
5
  Home-page: https://github.com/maykinmedia/commonground-api-common
6
6
  Author: Maykin Media, VNG-Realisatie
@@ -10,22 +10,22 @@ Keywords: openapi,swagger,django
10
10
  Classifier: Development Status :: 5 - Production/Stable
11
11
  Classifier: Framework :: Django
12
12
  Classifier: Framework :: Django :: 3.2
13
- Classifier: Framework :: Django :: 4.1
13
+ Classifier: Framework :: Django :: 4.2
14
14
  Classifier: Intended Audience :: Developers
15
15
  Classifier: Operating System :: Unix
16
16
  Classifier: Operating System :: MacOS
17
17
  Classifier: Operating System :: Microsoft :: Windows
18
18
  Classifier: Programming Language :: Python :: 3
19
19
  Classifier: Programming Language :: Python :: 3 :: Only
20
- Classifier: Programming Language :: Python :: 3.7
21
20
  Classifier: Programming Language :: Python :: 3.8
22
21
  Classifier: Programming Language :: Python :: 3.9
23
22
  Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
24
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
- Requires-Dist: django <4.2,>=3.2.0
25
+ Requires-Dist: django >=3.2.0
26
26
  Requires-Dist: django-filter >=2.0
27
27
  Requires-Dist: django-solo
28
- Requires-Dist: djangorestframework ~=3.12.0
28
+ Requires-Dist: djangorestframework >=3.11.0
29
29
  Requires-Dist: djangorestframework-camel-case >=1.2.0
30
30
  Requires-Dist: django-rest-framework-condition
31
31
  Requires-Dist: drf-yasg >=1.20.0
@@ -36,7 +36,6 @@ Requires-Dist: isodate
36
36
  Requires-Dist: notifications-api-common >=0.2.2
37
37
  Requires-Dist: oyaml
38
38
  Requires-Dist: PyJWT >=2.0.0
39
- Requires-Dist: pyyaml
40
39
  Requires-Dist: requests
41
40
  Requires-Dist: coreapi
42
41
  Provides-Extra: coverage
@@ -1,7 +1,7 @@
1
- commonground_api_common-1.12.2.data/scripts/generate_schema,sha256=UKhznmbHX1zUjPx8G3XtxUPQiqnyd3TOIXs27Tnjl7U,952
2
- commonground_api_common-1.12.2.data/scripts/patch_content_types,sha256=dpGpYrZOZe8O5CHWd0F0QnP6Wk_7lK6DyuVZpBPr4mY,319
3
- commonground_api_common-1.12.2.data/scripts/use_external_components,sha256=xvvbngO2aDUagVXv4xRUqPaVtH_eOaVMWLQ8lyAPhEA,369
4
- vng_api_common/__init__.py,sha256=iqOGXbKmT9gJTZlaRWM7sRQNzvTVrBLpyBifku0F4lY,23
1
+ commonground_api_common-1.13.1.data/scripts/generate_schema,sha256=UKhznmbHX1zUjPx8G3XtxUPQiqnyd3TOIXs27Tnjl7U,952
2
+ commonground_api_common-1.13.1.data/scripts/patch_content_types,sha256=dpGpYrZOZe8O5CHWd0F0QnP6Wk_7lK6DyuVZpBPr4mY,319
3
+ commonground_api_common-1.13.1.data/scripts/use_external_components,sha256=xvvbngO2aDUagVXv4xRUqPaVtH_eOaVMWLQ8lyAPhEA,369
4
+ vng_api_common/__init__.py,sha256=zhPH25OUBo2L3LBdVqP8SV3q3YQ1dipZEOhCyWPDJcw,23
5
5
  vng_api_common/admin.py,sha256=oWKpUl5yjeYOIsh60ruCmBDyPURGq4ALle4zGhlUQsE,902
6
6
  vng_api_common/apps.py,sha256=wOQuxUImMpH39R0JrDdCZp5ADaUM8jU8vFPFW9froSs,3458
7
7
  vng_api_common/checks.py,sha256=tOyfV7MMLGh4anrd_W30LvJCxiyQ4sFs1mGd9mtrEc0,1175
@@ -21,7 +21,7 @@ vng_api_common/generators.py,sha256=tD7ZyyFgCQ3KiktpBFtn5YiVdl3jioGxzyvkEZFYdQQ,
21
21
  vng_api_common/geo.py,sha256=AZbrw0rwGYOmaSUk8JJSkx-4_tVrfT_cgggh9omRwhU,1862
22
22
  vng_api_common/middleware.py,sha256=DhdGA_9_bk7bYr-keHEt4F_VS6IkYJmzzAhkjqnzeYw,8857
23
23
  vng_api_common/mocks.py,sha256=JjpJyVmHReRUXbwDi2cnmuq4NYI1hLRr_W962TIhN6Y,6118
24
- vng_api_common/models.py,sha256=XXNpoOjSuA_9Ep2hIAm3jEELj6i66QFWHqdJbt5v4do,4810
24
+ vng_api_common/models.py,sha256=JmUfkM1PuiqW3wuTA-chMtcDGvohy4j0JsB95s7VK4Q,5041
25
25
  vng_api_common/oas.py,sha256=FiqBZ3n36q-fPRZEgpmLDxjnqmoAKmaTKZ-FlFcuRp0,2712
26
26
  vng_api_common/permissions.py,sha256=ayDxk9Wt8j0yO57FhZ8XaRkPET4lAqd8SSw3m4o3EGs,7562
27
27
  vng_api_common/polymorphism.py,sha256=N-x39pG2unD4N0ZbxFvuhE8ibPaJ0eKeqfvAJW3NnEU,6623
@@ -32,7 +32,7 @@ vng_api_common/search.py,sha256=yehS6boCOk1JXLCqAMU-B62hWtbTBSf_WKIVGPgp0Mg,1045
32
32
  vng_api_common/serializers.py,sha256=7_7IotlRfVb0woe6Wy79l_el3sPzrSY8-bfiYLbEUqs,10162
33
33
  vng_api_common/urls.py,sha256=9IWHYLlEIIHNaZ_Zq02qNQ2HJpETb7o-89r7yBM_tQs,270
34
34
  vng_api_common/utils.py,sha256=CFmG4xVabUA4GcWiOEbGSaL5mdFi8njsspTXRl8yjCY,9057
35
- vng_api_common/validators.py,sha256=GllGWCZwioXAMpwEj8V_9BfN3BpA_xHNvTvgN_6cnbk,12924
35
+ vng_api_common/validators.py,sha256=T93C2rdNA4vFBi33mGlE2Cb5cQZaMPTsMvcFRz3igYU,12009
36
36
  vng_api_common/version.py,sha256=yJV9_yTM7Qnzg0zGNkJQkN9Uai3I_ZUkcyseJRPRk5I,129
37
37
  vng_api_common/views.py,sha256=2fraDBtq9x2hMauRuOKkn6cDUw0IYdzfPKTxFFRRFXk,7309
38
38
  vng_api_common/viewsets.py,sha256=z5pzvSymFiiuCjP_-uuW-3OJKZY_psPAt8fWeWySU0c,2278
@@ -75,9 +75,9 @@ vng_api_common/audittrails/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCe
75
75
  vng_api_common/audittrails/migrations/_operations.py,sha256=UOMv0zAK8CIQ73cSu6wwQG_hkW46Isdy7JCnljn8GII,3280
76
76
  vng_api_common/authorizations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
77
  vng_api_common/authorizations/admin.py,sha256=BmJQgNH7KlDB3flAXrSMm_w0NowpJrDYWDY61RZcKCI,795
78
- vng_api_common/authorizations/models.py,sha256=n1hJci5dQQ_TmcPTAD34QVrBoHR9_z-hloQ0VXi2bzI,3657
78
+ vng_api_common/authorizations/models.py,sha256=ahwEMG5R6ILTlrnKo5TggYp52Z7dAJMk2QSZyZW8Qa0,4236
79
79
  vng_api_common/authorizations/serializers.py,sha256=3HeKWEqhI3UWwI8SttC4rEID-Epbk7SWsC-bEjolbaw,5151
80
- vng_api_common/authorizations/validators.py,sha256=ZD0Lidt2PT7FayhV1NPQ-mwXeu2SsxhAtN4gqH6G9EQ,3035
80
+ vng_api_common/authorizations/validators.py,sha256=u7fKm0QgGy8fiAeYmIEB9Gy-yIE9C-tC2ZpnNQBXPso,2816
81
81
  vng_api_common/authorizations/migrations/0001_initial.py,sha256=ooAZtQeDtWgDxXzAP-KnSyyFYLRPM-PMrK5RgOnTPjQ,4360
82
82
  vng_api_common/authorizations/migrations/0002_authorizationsconfig.py,sha256=m4taH6ClHI-YHYGGOKaq_qYXGx9lq1InXOGLQKg9MSw,1364
83
83
  vng_api_common/authorizations/migrations/0003_auto_20190502_0409.py,sha256=96ioRD1O54dxt6l96rSnnF06bTmQIL4S8kJ0dzUhsHo,526
@@ -96,7 +96,7 @@ vng_api_common/authorizations/migrations/0015_auto_20220318_1608.py,sha256=jR1MD
96
96
  vng_api_common/authorizations/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
97
97
  vng_api_common/caching/__init__.py,sha256=v_FC6HaHESwr_J94TWzaQBKtIjDLnsQADvqHylEW7g8,687
98
98
  vng_api_common/caching/decorators.py,sha256=lU5dnBjD9aHjoYaV32FlYxY7VFZPdMZe26fVDa_h3Q4,1804
99
- vng_api_common/caching/etags.py,sha256=NYICwDyyJEzteTu_DiZWTSmXa9vXMboaxrpJqLHuKwQ,7295
99
+ vng_api_common/caching/etags.py,sha256=3zY0DTdwt19QHsxFLK1wqQ3K98JfO6Uxr6tFuixichg,7337
100
100
  vng_api_common/caching/introspection.py,sha256=JKeEuTiyWp1oN1Fg27j5-2btROz9NcLxxfzSZuVVJ9w,575
101
101
  vng_api_common/caching/models.py,sha256=RroS9HFiKNXDV59Odh0x8BO8Az8E81v4gwuprF1A1qg,988
102
102
  vng_api_common/caching/registry.py,sha256=mY1r99x7m0DQ1BN9lZF2zMjFj_oDNq7urxDkOH7-8Yg,6205
@@ -111,7 +111,7 @@ vng_api_common/inspectors/fields.py,sha256=XgD6K-KKzWVbxKb0kG92bNOsqLuuS_ywjidP3
111
111
  vng_api_common/inspectors/files.py,sha256=kedBFCLS0H8lopVgIa7SpBrwXgk6E7Hd8xZT65P0TOE,4385
112
112
  vng_api_common/inspectors/geojson.py,sha256=Vs6PsY5hY_zlkEko-5nvj_QIO0UKuoSlu2ONpW5Z65s,12575
113
113
  vng_api_common/inspectors/polymorphic.py,sha256=4U_wjmcBwWCbTPvd0ojFCdmtuyJShy7ORChO2JqKjvs,2627
114
- vng_api_common/inspectors/query.py,sha256=ZhdD5VENxNcHtrETKOt8bJM7AxVxFH8S9umGIpoD8ik,3911
114
+ vng_api_common/inspectors/query.py,sha256=pl_M84BCtgVtBbc_5YtmsImU8c416hYOuDTo91ApFX4,3802
115
115
  vng_api_common/inspectors/utils.py,sha256=uLyB_Giw7B2flMiBB_HwCpxOs-QcTUIHjHkE0xUmPfo,1481
116
116
  vng_api_common/inspectors/view.py,sha256=f28MFNqHUE3LSWgYHuJB2PwjRszIAqPU_fBk75Utl3w,20425
117
117
  vng_api_common/locale/nl/LC_MESSAGES/django.mo,sha256=w1sFqpNIcpHWbNOFpKjVUmA3idit-Q1SH2wE5h0nXPU,6211
@@ -136,7 +136,7 @@ vng_api_common/notifications/handlers.py,sha256=-r52nIKbHdFUxE7hob9PiFRe0D3cizhk
136
136
  vng_api_common/notifications/models.py,sha256=Ez3JYeM7BNSiFYtxAtVxWUWDc8t7jOFQlRTjrtE6SlI,2942
137
137
  vng_api_common/notifications/api/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
138
138
  vng_api_common/notifications/api/urls.py,sha256=c1T_6tuRpgN0V80Xg_ehZzGGlF1FNMmHdBEPAjR736I,164
139
- vng_api_common/notifications/api/views.py,sha256=nUqqAANsxzWx5zDbW0Mbi5CONRdeAirvPrwjSXiP6ao,2312
139
+ vng_api_common/notifications/api/views.py,sha256=8LMh4XU_qCQURx7BLn6HnaFt1auUXlF7PHlOrcJSZ0w,2303
140
140
  vng_api_common/notifications/migrations/0001_initial.py,sha256=zEIVIB--6FStaTl3r9GCXxHL1cSCWRO3T90rEpJr3hY,3049
141
141
  vng_api_common/notifications/migrations/0002_subscription__subscription.py,sha256=eqaj6-FAl7vuCswdvin9Lf8nzjP8U6WqVQO4opNKKCc,550
142
142
  vng_api_common/notifications/migrations/0003_auto_20190319_1048.py,sha256=C-ccYUwQPNCjTctpDDFhnQbm_OcpAlTjYQbEuiEi-ys,987
@@ -187,7 +187,7 @@ vng_api_common/tests/auth.py,sha256=IKDWTEFv4Bign4F70-ibsFcnJqRxEJaXvqaPQJWa1xY,
187
187
  vng_api_common/tests/caching.py,sha256=zfIw5cRRvO9cekHZZKfRqZc8cx5IfJUYNmcH6cuIMg4,624
188
188
  vng_api_common/tests/schema.py,sha256=9LFgEXzcYGkHZtlpCiHNCWywR5lF7Pl0S43cwlwKDgQ,1954
189
189
  vng_api_common/tests/urls.py,sha256=PFrYzQbBC0TFPMEn3uPhcBG0IQs9JsEPqckicJT1UA4,2159
190
- commonground_api_common-1.12.2.dist-info/METADATA,sha256=4Sl9zxdvvUxYkViUIpOXlRJEvqRTNQ9d_H9gK3z4FtI,6682
191
- commonground_api_common-1.12.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
192
- commonground_api_common-1.12.2.dist-info/top_level.txt,sha256=vPismc83zPzWXTmlNCCwfDlFV9iygJYxNJW5iDjKTgw,15
193
- commonground_api_common-1.12.2.dist-info/RECORD,,
190
+ commonground_api_common-1.13.1.dist-info/METADATA,sha256=6wYbwNsTe9kfHYazuocao9q9j7EQT4ShgqGfhUDkEvM,6656
191
+ commonground_api_common-1.13.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
192
+ commonground_api_common-1.13.1.dist-info/top_level.txt,sha256=vPismc83zPzWXTmlNCCwfDlFV9iygJYxNJW5iDjKTgw,15
193
+ commonground_api_common-1.13.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: bdist_wheel (0.43.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1 +1 @@
1
- __version__ = "1.12.2"
1
+ __version__ = "1.13.1"
@@ -23,6 +23,11 @@ class AuthorizationsConfig(ClientConfig):
23
23
  verbose_name = _("Autorisatiecomponentconfiguratie")
24
24
 
25
25
 
26
+ class ApplicatieManager(models.Manager):
27
+ def get_by_natural_key(self, uuid):
28
+ return self.get(uuid=uuid)
29
+
30
+
26
31
  class Applicatie(APIMixin, models.Model):
27
32
  """
28
33
  Client level of authorization
@@ -52,10 +57,20 @@ class Applicatie(APIMixin, models.Model):
52
57
  ),
53
58
  )
54
59
 
60
+ objects = ApplicatieManager()
61
+
62
+ def natural_key(self):
63
+ return (str(self.uuid),)
64
+
55
65
  def __str__(self):
56
66
  return f"Applicatie ({self.label})"
57
67
 
58
68
 
69
+ class AutorisatieManager(models.Manager):
70
+ def get_by_natural_key(self, applicatie, component, scopes):
71
+ return self.get(applicatie=applicatie, component=component, scopes=scopes)
72
+
73
+
59
74
  class Autorisatie(APIMixin, models.Model):
60
75
  applicatie = models.ForeignKey(
61
76
  "Applicatie",
@@ -109,6 +124,15 @@ class Autorisatie(APIMixin, models.Model):
109
124
  blank=True,
110
125
  )
111
126
 
127
+ objects = AutorisatieManager()
128
+
129
+ def natural_key(self):
130
+ return (
131
+ self.applicatie,
132
+ self.component,
133
+ self.scopes,
134
+ )
135
+
112
136
  def satisfy_vertrouwelijkheid(self, vertrouwelijkheidaanduiding: str) -> bool:
113
137
  max_confid_level = VertrouwelijkheidsAanduiding.get_choice(
114
138
  self.max_vertrouwelijkheidaanduiding
@@ -15,20 +15,14 @@ class UniqueClientIDValidator:
15
15
  message = _(
16
16
  "The clientID(s) {client_id} are already used in application(s) {app_id}"
17
17
  )
18
+ requires_context = True
18
19
 
19
- def set_context(self, serializer_field):
20
- """
21
- This hook is called by the serializer instance,
22
- prior to the validation call being made.
23
- """
24
- # Determine the existing instance, if this is an update operation.
25
- self.instance = getattr(serializer_field.parent, "instance", None)
26
-
27
- def __call__(self, value: List[str]):
20
+ def __call__(self, value: List[str], serializer_field):
21
+ instance = getattr(serializer_field.parent, "instance", None)
28
22
  qs = Applicatie.objects.all()
29
23
 
30
- if self.instance:
31
- qs = qs.exclude(id=self.instance.id)
24
+ if instance:
25
+ qs = qs.exclude(id=instance.id)
32
26
 
33
27
  existing = qs.filter(client_ids__overlap=value).values_list(
34
28
  "uuid", "client_ids"
@@ -157,7 +157,8 @@ class EtagUpdate:
157
157
  connection = transaction.get_connection(using)
158
158
 
159
159
  func = MethodCallback(etag_update.calculate_new_value)
160
- for _, _func in connection.run_on_commit:
160
+ for run_on_commit in connection.run_on_commit:
161
+ _func = run_on_commit[1]
161
162
  if func == _func:
162
163
  logger.debug(
163
164
  "Update for model instance %r with pk %s was already scheduled",
@@ -1,10 +1,5 @@
1
1
  from django.db import models
2
-
3
- try:
4
- from django.utils.encoding import force_str
5
- except ImportError: # Django < 4.0
6
- from django.utils.encoding import force_text as force_str
7
-
2
+ from django.utils.encoding import force_str
8
3
  from django.utils.translation import gettext as _
9
4
 
10
5
  from django_filters.filters import BaseCSVFilter, ChoiceFilter
vng_api_common/models.py CHANGED
@@ -34,6 +34,11 @@ class APIMixin:
34
34
  return url
35
35
 
36
36
 
37
+ class JWTSecretManager(models.Manager):
38
+ def get_by_natural_key(self, identifier):
39
+ return self.get(identifier=identifier)
40
+
41
+
37
42
  class JWTSecret(models.Model):
38
43
  """
39
44
  Store credentials of clients that want to access our API.
@@ -53,6 +58,11 @@ class JWTSecret(models.Model):
53
58
  _("secret"), max_length=255, help_text=_("Secret belonging to the client ID.")
54
59
  )
55
60
 
61
+ objects = JWTSecretManager()
62
+
63
+ def natural_key(self):
64
+ return (self.identifier,)
65
+
56
66
  class Meta:
57
67
  verbose_name = _("client credential")
58
68
  verbose_name_plural = _("client credentials")
@@ -21,9 +21,7 @@ class NotificationBaseView(APIView):
21
21
  swagger_schema = None
22
22
 
23
23
  permission_classes = (AuthScopesRequired,)
24
- required_scopes = Scope(
25
- SCOPE_NOTIFICATIES_PUBLICEREN_LABEL
26
- ) # FIXME: this should be standalone!
24
+ required_scopes = Scope(SCOPE_NOTIFICATIES_PUBLICEREN_LABEL, private=True)
27
25
 
28
26
  def get_serializer(self, *args, **kwargs):
29
27
  return NotificatieSerializer(*args, **kwargs)
@@ -55,7 +53,9 @@ class NotificationBaseView(APIView):
55
53
  class NotificationView(NotificationBaseView):
56
54
  action = "create"
57
55
  permission_classes = (AuthScopesRequired,)
58
- required_scopes = {"create": Scope(SCOPE_NOTIFICATIES_PUBLICEREN_LABEL)}
56
+ required_scopes = {
57
+ "create": Scope(SCOPE_NOTIFICATIES_PUBLICEREN_LABEL, private=True)
58
+ }
59
59
 
60
60
  def create(self, request, *args, **kwargs):
61
61
  return self.post(request, *args, **kwargs)
@@ -206,20 +206,18 @@ class ResourceValidator(URLValidator):
206
206
 
207
207
 
208
208
  class InformatieObjectUniqueValidator(validators.UniqueTogetherValidator):
209
+ requires_context = True
210
+
209
211
  def __init__(self, parent_field, field: str):
210
212
  self.parent_field = parent_field
211
213
  self.field = field
212
214
  super().__init__(None, (parent_field, field))
213
215
 
214
- def set_context(self, serializer_field):
215
- serializer = serializer_field.parent
216
- super().set_context(serializer)
217
-
218
- self.queryset = serializer.Meta.model._default_manager.all()
219
- self.parent_object = serializer.context["parent_object"]
220
-
221
- def __call__(self, informatieobject: str):
222
- attrs = {self.parent_field: self.parent_object, self.field: informatieobject}
216
+ def __call__(self, informatieobject: str, serializer):
217
+ attrs = {
218
+ self.parent_field: serializer.context["parent_object"],
219
+ self.field: informatieobject,
220
+ }
223
221
  super().__call__(attrs)
224
222
 
225
223
 
@@ -232,17 +230,12 @@ class ObjectInformatieObjectValidator:
232
230
  "Het informatieobject is in het DRC nog niet gerelateerd aan dit object."
233
231
  )
234
232
  code = "inconsistent-relation"
233
+ requires_context = True
235
234
 
236
- def set_context(self, serializer):
237
- """
238
- This hook is called by the serializer instance,
239
- prior to the validation call being made.
240
- """
241
- self.parent_object = serializer.context["parent_object"]
242
- self.request = serializer.context["request"]
243
-
244
- def __call__(self, informatieobject: str):
245
- object_url = self.parent_object.get_absolute_api_url(self.request)
235
+ def __call__(self, informatieobject: str, serializer):
236
+ object_url = serializer.context["parent_object"].get_absolute_api_url(
237
+ self.request
238
+ )
246
239
 
247
240
  # dynamic so that it can be mocked in tests easily
248
241
  client = get_client(informatieobject)
@@ -311,40 +304,33 @@ class UniekeIdentificatieValidator:
311
304
 
312
305
  message = _("Deze identificatie bestaat al binnen de organisatie")
313
306
  code = "identificatie-niet-uniek"
307
+ requires_context = True
314
308
 
315
309
  def __init__(self, organisatie_field: str, identificatie_field="identificatie"):
316
310
  self.organisatie_field = organisatie_field
317
311
  self.identificatie_field = identificatie_field
318
312
 
319
- def set_context(self, serializer):
320
- """
321
- This hook is called by the serializer instance,
322
- prior to the validation call being made.
323
- """
324
- # Determine the existing instance, if this is an update operation.
325
- self.instance = getattr(serializer, "instance", None)
326
- self.model = serializer.Meta.model
327
-
328
- def __call__(self, attrs: dict):
313
+ def __call__(self, attrs: dict, serializer):
314
+ instance = getattr(serializer, "instance", None)
329
315
  identificatie = attrs.get(self.identificatie_field)
330
316
  if not identificatie:
331
- if self.instance:
317
+ if instance:
332
318
  # In case of a partial update
333
- identificatie = self.instance.identificatie
319
+ identificatie = instance.identificatie
334
320
  else:
335
321
  # identification is being generated, and the generation checks for
336
322
  # uniqueness
337
323
  return
338
324
 
339
325
  organisatie = attrs.get(self.organisatie_field)
340
- pk = self.instance.pk if self.instance else None
326
+ pk = instance.pk if instance else None
341
327
 
342
328
  # if we're updating an instance, setting the current values will not
343
329
  # trigger an error because the instance-to-be-updated is excluded from
344
330
  # the queryset. If either bronorganisatie or identificatie changes,
345
331
  # and it already exists, it will raise a validation error
346
332
  combination_exists = (
347
- self.model.objects
333
+ serializer.Meta.model.objects
348
334
  # in case of an update, exclude the current object. for a create, this
349
335
  # will be None
350
336
  .exclude(pk=pk)
@@ -370,22 +356,15 @@ class IsImmutableValidator:
370
356
 
371
357
  message = _("Dit veld mag niet gewijzigd worden.")
372
358
  code = "wijzigen-niet-toegelaten"
359
+ requires_context = True
373
360
 
374
- def set_context(self, serializer_field):
375
- """
376
- This hook is called by the serializer instance,
377
- prior to the validation call being made.
378
- """
379
- # Determine the existing instance, if this is an update operation.
380
- self.serializer_field = serializer_field
381
- self.instance = getattr(serializer_field.parent, "instance", None)
382
-
383
- def __call__(self, new_value):
361
+ def __call__(self, new_value, serializer_field):
362
+ instance = getattr(serializer_field.parent, "instance", None)
384
363
  # no instance -> it's not an update
385
- if not self.instance:
364
+ if not instance:
386
365
  return
387
366
 
388
- current_value = getattr(self.instance, self.serializer_field.field_name)
367
+ current_value = getattr(instance, serializer_field.field_name)
389
368
 
390
369
  if new_value != current_value:
391
370
  raise serializers.ValidationError(self.message, code=self.code)