3
3
import uuid
4
4
from dataclasses import dataclass
5
5
from datetime import timedelta
6
- from typing import ClassVar , Iterable , Literal , NotRequired , Protocol , Self , Sequence
6
+ from typing import (
7
+ ClassVar ,
8
+ Iterable ,
9
+ Literal ,
10
+ NotRequired ,
11
+ Protocol ,
12
+ Self ,
13
+ Sequence ,
14
+ cast ,
15
+ )
7
16
8
17
from django .conf import settings
9
18
from django .core .exceptions import ImproperlyConfigured
19
+ from django .http import HttpRequest
10
20
from django .urls import reverse
11
21
from django .utils import timezone
12
22
from django .utils .translation import gettext_lazy as _
@@ -102,10 +112,11 @@ class Question(TypedDict):
102
112
103
113
class KlantenService (Protocol ):
104
114
service_config : ServiceConfig
115
+ supports_anonymous_questions : ClassVar [bool ]
105
116
106
117
def get_fetch_parameters (
107
118
self ,
108
- request = None ,
119
+ request : HttpRequest | None = None ,
109
120
user : User | None = None ,
110
121
use_vestigingsnummer : bool = False ,
111
122
) -> FetchParameters | None :
@@ -125,10 +136,10 @@ def get_fetch_parameters(
125
136
kvk_or_rsin = user .rsin
126
137
127
138
if use_vestigingsnummer :
128
- if not getattr (request , "session" , None ):
139
+ if not ( session := getattr (request , "session" , None ) ):
129
140
raise ValueError ("`request` does not contain a session" )
130
141
131
- vestigingsnummer = get_kvk_branch_number (request . session )
142
+ vestigingsnummer = get_kvk_branch_number (session )
132
143
if vestigingsnummer :
133
144
return {
134
145
"user_kvk_or_rsin" : kvk_or_rsin ,
@@ -139,25 +150,25 @@ def get_fetch_parameters(
139
150
140
151
return None
141
152
142
- supports_anonymous_questions : ClassVar [bool ]
143
153
144
-
145
- class eSuiteKlantenService (KlantenService ):
154
+ class eSuiteKlantenService (
155
+ KlantenService ,
156
+ ):
146
157
config : ESuiteKlantConfig
147
158
client : APIClient
148
159
service_config : ServiceConfig
149
160
supports_anonymous_questions = True
150
161
151
162
def __init__ (self , config : ESuiteKlantConfig | None = None ):
152
- self .config = config or ESuiteKlantConfig .get_solo ()
163
+ self .config = cast ( ESuiteKlantConfig , config or ESuiteKlantConfig .get_solo () )
153
164
if not self .config :
154
165
raise ImproperlyConfigured (
155
166
"eSuiteKlantenService instance needs a configuration"
156
167
)
157
168
158
169
if not self .config .klanten_service :
159
170
raise ImproperlyConfigured (
160
- "eSuiteKlantenService instance needs a servivce configuration"
171
+ "eSuiteKlantenService instance needs a service configuration"
161
172
)
162
173
163
174
self .service_config = self .config .klanten_service
@@ -407,17 +418,19 @@ class eSuiteVragenService(KlantenService):
407
418
def __init__ (self , config : ESuiteKlantConfig | None = None ):
408
419
self .config = config or ESuiteKlantConfig .get_solo ()
409
420
if not self .config :
410
- raise RuntimeError ("eSuiteVragenService instance needs a configuration" )
421
+ raise ImproperlyConfigured (
422
+ "eSuiteVragenService instance needs a configuration"
423
+ )
411
424
412
425
self .service_config = self .config .contactmomenten_service
413
426
if not self .service_config :
414
- raise RuntimeError (
427
+ raise ImproperlyConfigured (
415
428
"eSuiteVragenService instance needs a servivce configuration"
416
429
)
417
430
418
431
self .client = build_zgw_client (service = self .service_config )
419
432
if not self .client :
420
- raise RuntimeError ("eSuiteVragenService instance needs a client" )
433
+ raise ImproperlyConfigured ("eSuiteVragenService instance needs a client" )
421
434
422
435
#
423
436
# contactmomenten
@@ -765,9 +778,9 @@ def retrieve_question(
765
778
def list_questions_for_zaak (self , zaak : Zaak , user : User ) -> list [Question ]:
766
779
objectcontactmomenten = self .retrieve_objectcontactmomenten_for_zaak (zaak )
767
780
768
- contactmomenten = []
781
+ contactmomenten : list [ ContactMoment ] = []
769
782
for ocm in objectcontactmomenten :
770
- question = getattr (ocm , "contactmoment" , None )
783
+ question : ContactMoment | None = getattr (ocm , "contactmoment" , None )
771
784
if question :
772
785
contactmomenten .append (question )
773
786
contactmomenten .sort (key = lambda q : q .registratiedatum , reverse = True )
@@ -780,13 +793,13 @@ def list_questions_for_zaak(self, zaak: Zaak, user: User) -> list[Question]:
780
793
]
781
794
782
795
kcm_answer_mapping = get_kcm_answer_mapping (contactmomenten , user )
783
- questions = []
796
+ questions : list [ Question ] = []
784
797
for contactmoment in contactmomenten :
785
798
new_answer_available = contactmoment_has_new_answer (
786
799
contactmoment , kcm_answer_mapping
787
800
)
788
801
questions .append (
789
- Question (
802
+ dict (
790
803
identification = contactmoment .identificatie ,
791
804
api_source_url = contactmoment .url ,
792
805
api_source_uuid = contactmoment .uuid ,
@@ -870,7 +883,10 @@ def from_klantcontact_and_answer(
870
883
)
871
884
872
885
873
- class OpenKlant2Service (LogMixin , KlantenService ):
886
+ class OpenKlant2Service (
887
+ LogMixin ,
888
+ KlantenService ,
889
+ ):
874
890
config : OpenKlant2Config
875
891
client : OpenKlant2Client
876
892
supports_anonymous_questions = False
@@ -1439,7 +1455,7 @@ def retrieve_question(
1439
1455
fetch_params : FetchParameters ,
1440
1456
question_uuid : str ,
1441
1457
user : User ,
1442
- ) -> tuple [Question | None , Zaak | None ]: # noqa: E704
1458
+ ) -> tuple [Question | None , ZaakWithApiGroup | None ]: # noqa: E704
1443
1459
if bsn := fetch_params .get ("user_bsn" ):
1444
1460
partij = self .find_persoon_for_bsn (bsn )
1445
1461
elif kvk_or_rsin := fetch_params .get ("user_kvk_or_rsin" ):
0 commit comments