Skip to content

Commit

Permalink
Améliore l’affichage de la géoposition des membres
Browse files Browse the repository at this point in the history
Avant, quand le pays était connu mais pas la ville, les administrateurs
voyaient des choses comme `None, France` sur les pages des membres. Ce commit
fait en sorte que seul `France` soit affiché.

Rien ne change quand le pays et la ville sont connus.
  • Loading branch information
motet-a authored and gllmc committed Nov 28, 2017
1 parent a449083 commit 0a18bf2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions zds/member/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def get_absolute_url(self):
def get_city(self):
"""
Uses geo-localization to get physical localization of a profile through its last IP address.
This works relatively good with IPv4 addresses (~city level), but is very imprecise with IPv6 or exotic internet
This works relatively well with IPv4 addresses (~city level), but is very imprecise with IPv6 or exotic internet
providers.
:return: The city and the country name of this profile.
"""
Expand All @@ -108,9 +108,12 @@ def get_city(self):

geo = gic.record_by_addr(self.last_ip_address)

if geo is not None:
return '{0}, {1}'.format(geo['city'], geo['country_name'])
return ''
if geo is None:
return ''

city = geo['city']
country = geo['country_name']
return ', '.join(i for i in [city, country] if i)

def get_avatar_url(self):
"""Get the avatar URL for this profile.
Expand Down

0 comments on commit 0a18bf2

Please sign in to comment.