Code Duplication    Length = 50-50 lines in 2 locations

oe_geoutils/validation/validators_location_elements.py 1 location

@@ 336-385 (lines=50) @@
333
        huisnummer_id = locatie_element.get('huisnummer_id', None)
334
        postcode = locatie_element.get('postcode', None)
335
        subadres_id = locatie_element.get('subadres_id', None)
336
        if straat_id is not None:
337
            gemeente = crab_gateway.get_gemeente_by_id(gemeente_id)
338
            try:
339
                straat = crab_gateway.get_straat_by_id(straat_id)
340
            except (GatewayRuntimeException, AttributeError):
341
                raise colander.Invalid(
342
                    node,
343
                    'ongeldig straat_id'
344
                )
345
            if straat.gemeente_id != gemeente_id:
346
                raise colander.Invalid(
347
                    node,
348
                    'de straat %s met id %s ligt niet in gemeente %s' %
349
                    (locatie_element.get('straat', ''), straat_id, gemeente.naam)
350
                )
351
            if huisnummer_id is not None:
352
                try:
353
                    huisnummer = crab_gateway.get_huisnummer_by_id(huisnummer_id)
354
                except (GatewayRuntimeException, AttributeError):
355
                    raise colander.Invalid(
356
                        node,
357
                        'ongeldig huisnummer_id'
358
                    )
359
                if huisnummer.straat_id != straat_id:
360
                    raise colander.Invalid(
361
                        node,
362
                        'het huisnummer %s met id %s ligt niet in straat %s' %
363
                        (locatie_element.get('huisnummer', ''), huisnummer_id, straat.label)
364
                    )
365
                if postcode is not None:
366
                    postkanton = crab_gateway.get_postkanton_by_huisnummer(huisnummer_id)
367
                    if postcode != str(postkanton.id):
368
                        raise colander.Invalid(
369
                            node,
370
                            'postcode %s is niet correct voor dit adres, mogelijke postcode is %s' %
371
                            (postcode, postkanton.id)
372
                        )
373
                if subadres_id is not None:
374
                    try:
375
                        subadres = crab_gateway.get_subadres_by_id(subadres_id)
376
                    except (GatewayRuntimeException, AttributeError):
377
                        raise colander.Invalid(
378
                            node,
379
                            'ongeldig subadres_id'
380
                        )
381
                    if subadres.huisnummer_id != huisnummer_id:
382
                        raise colander.Invalid(
383
                            node,
384
                            'het subadres %s met id %s ligt niet op huisnummer %s' %
385
                            (locatie_element.get('subadres', ''), subadres_id, huisnummer.huisnummer)
386
                        )
387
        if straat_id is None and huisnummer_id is not None:
388
            raise colander.Invalid(

oe_geoutils/validation/validators_address.py 1 location

@@ 197-246 (lines=50) @@
194
                        node,
195
                        'ongeldig gemeente_id {0}'.format(gemeente_id)
196
                    )
197
                if straat_id is not None:
198
                    gemeente = crab_gateway.get_gemeente_by_id(gemeente_id)
199
                    try:
200
                        straat = crab_gateway.get_straat_by_id(straat_id)
201
                    except (GatewayRuntimeException, AttributeError):
202
                        raise colander.Invalid(
203
                            node,
204
                            'ongeldig straat_id'
205
                        )
206
                    if straat.gemeente_id != gemeente_id:
207
                        raise colander.Invalid(
208
                            node,
209
                            'de straat %s met id %s ligt niet in gemeente %s' %
210
                            (adres.get('straat', ''), straat_id, gemeente.naam)
211
                        )
212
                    if huisnummer_id is not None:
213
                        try:
214
                            huisnummer = crab_gateway.get_huisnummer_by_id(huisnummer_id)
215
                        except (GatewayRuntimeException, AttributeError):
216
                            raise colander.Invalid(
217
                                node,
218
                                'ongeldig huisnummer_id'
219
                            )
220
                        if huisnummer.straat_id != straat_id:
221
                            raise colander.Invalid(
222
                                node,
223
                                'het huisnummer %s met id %s ligt niet in straat %s' %
224
                                (adres.get('huisnummer', ''), huisnummer_id, straat.label)
225
                            )
226
                        if postcode is not None:
227
                            postkanton = crab_gateway.get_postkanton_by_huisnummer(huisnummer_id)
228
                            if postcode != str(postkanton.id):
229
                                raise colander.Invalid(
230
                                    node,
231
                                    'postcode %s is niet correct voor dit adres, mogelijke postcode is %s' %
232
                                    (postcode, postkanton.id)
233
                                )
234
                        if subadres_id is not None:
235
                            try:
236
                                subadres = crab_gateway.get_subadres_by_id(subadres_id)
237
                            except (GatewayRuntimeException, AttributeError):
238
                                raise colander.Invalid(
239
                                    node,
240
                                    'ongeldig subadres_id'
241
                                )
242
                            if subadres.huisnummer_id != huisnummer_id:
243
                                raise colander.Invalid(
244
                                    node,
245
                                    'het subadres %s met id %s ligt niet op huisnummer %s' %
246
                                    (adres.get('subadres', ''), subadres_id, huisnummer.huisnummer)
247
                                )
248
                if straat_id is None and huisnummer_id is not None:
249
                    raise colander.Invalid(