Code Duplication    Length = 50-50 lines in 2 locations

oe_geoutils/validation/validators_location_elements.py 1 location

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

oe_geoutils/validation/validators_address.py 1 location

@@ 200-249 (lines=50) @@
197
                    pycountry.countries.get(alpha2=land)
198
                except KeyError:
199
                    pycountry.countries.get(alpha_2=land)
200
            except KeyError:
201
                raise colander.Invalid(
202
                    node,
203
                    'ongeldige landcode %s, dit is geen ISO 3166 code' %
204
                    land
205
                )
206
            if land == 'BE':
207
                gemeente = adres.get('gemeente', None)
208
                gemeente_id = adres.get('gemeente_id', None)
209
                straat_id = adres.get('straat_id', None)
210
                huisnummer_id = adres.get('huisnummer_id', None)
211
                postcode = adres.get('postcode', None)
212
                subadres_id = adres.get('subadres_id', None)
213
                if gemeente_id is None:
214
                    raise colander.Invalid(
215
                        node,
216
                        'geen correcte gemeente_id gevonden voor de gemeente {0}'.format(gemeente)
217
                    )
218
                if gemeente is None:
219
                    raise colander.Invalid(
220
                        node,
221
                        'ongeldig gemeente_id {0}'.format(gemeente_id)
222
                    )
223
                if straat_id is not None:
224
                    gemeente = crab_gateway.get_gemeente_by_id(gemeente_id)
225
                    try:
226
                        straat = crab_gateway.get_straat_by_id(straat_id)
227
                    except (GatewayRuntimeException, GatewayResourceNotFoundException, AttributeError):
228
                        raise colander.Invalid(
229
                            node,
230
                            'ongeldig straat_id'
231
                        )
232
                    if straat.gemeente_id != gemeente_id:
233
                        raise colander.Invalid(
234
                            node,
235
                            'de straat %s met id %s ligt niet in gemeente %s' %
236
                            (adres.get('straat', ''), straat_id, gemeente.naam)
237
                        )
238
                    if huisnummer_id is not None:
239
                        try:
240
                            huisnummer = crab_gateway.get_huisnummer_by_id(huisnummer_id)
241
                        except (GatewayRuntimeException, GatewayResourceNotFoundException, AttributeError):
242
                            raise colander.Invalid(
243
                                node,
244
                                'ongeldig huisnummer_id'
245
                            )
246
                        if huisnummer.straat_id != straat_id:
247
                            raise colander.Invalid(
248
                                node,
249
                                'het huisnummer %s met id %s ligt niet in straat %s' %
250
                                (adres.get('huisnummer', ''), huisnummer_id, straat.label)
251
                            )
252
                        if postcode is not None: