Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with (geo)zones with the same postal code #382

Merged
merged 1 commit into from
Mar 14, 2016
Merged

Deal with (geo)zones with the same postal code #382

merged 1 commit into from
Mar 14, 2016

Conversation

davidbgk
Copy link
Member

No description provided.

try:
return GeoZone.objects.get(code=query, level='fr/town')
except GeoZone.DoesNotExist:
try:
return GeoZone.objects.get(
keys__postal__contains=query, level='fr/town')
return GeoZone.objects.filter(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter is optionnal (I know you like the Django way ;))

To avoid long lines, you can factorize:

qs = GeoZone.objects(level=fr/town)
try:
    return qs.get(code=query)
except GeoZone.DoesNotExist:
    try:
        return qs(keys__postal__contains=query).first()
    except:
        #...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or if you want to keep the filter:

qs = GeoZone.objects.filter(level=fr/town)
try:
    return qs.get(code=query)
except GeoZone.DoesNotExist:
    try:
        return qs.filter(keys__postal__contains=query).first()
    except:
        #...

@noirbizarre
Copy link
Contributor

r+wc

@davidbgk
Copy link
Member Author

@noirbizarre I refactored the whole function, thanks!

@noirbizarre
Copy link
Contributor

great ! r+ ;)

davidbgk added a commit that referenced this pull request Mar 14, 2016
Deal with (geo)zones with the same postal code
@davidbgk davidbgk merged commit ea28dbc into opendatateam:master Mar 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants