From: Michael Tremer Date: Fri, 21 Aug 2020 09:36:21 +0000 (+0000) Subject: location: Use country name from location database X-Git-Url: http://git.ipfire.org/?p=ipfire.org.git;a=commitdiff_plain;h=e929ed926c54bd10e9387755b66add47795e6e50 location: Use country name from location database https://lists.ipfire.org/pipermail/location/2020-August/000131.html Signed-off-by: Michael Tremer --- diff --git a/src/backend/accounts.py b/src/backend/accounts.py index 2c9f4608..a3c8297b 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -924,7 +924,7 @@ class Account(LDAPObject): @property def country_name(self): if self.country_code: - return countries.get_name(self.country_code) + return self.backend.get_country_name(self.country_code) @property def email(self): diff --git a/src/backend/base.py b/src/backend/base.py index c1d4cbb1..00497a29 100644 --- a/src/backend/base.py +++ b/src/backend/base.py @@ -177,6 +177,12 @@ class Backend(object): def location(self): return location.Database("/var/lib/location/database.db") + def get_country_name(self, country_code): + country = self.location.get_country(country_code) + + if country: + return country.name + @lazy_property def ratelimiter(self): return ratelimit.RateLimiter(self) diff --git a/src/backend/fireinfo.py b/src/backend/fireinfo.py index d02d774f..d7f78456 100644 --- a/src/backend/fireinfo.py +++ b/src/backend/fireinfo.py @@ -5,7 +5,6 @@ import iso3166 import logging import re -from . import countries from . import database from . import hwdata from . import util @@ -576,7 +575,7 @@ class Profile(Object): @property def location_string(self): - return countries.get_name(self.location) + return self.backend.get_country_name(self.location) or self.location # Devices diff --git a/src/web/__init__.py b/src/web/__init__.py index 45efa6f0..676e6edb 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -336,7 +336,7 @@ class Application(tornado.web.Application): logging.info("Successfully initialied application") def format_country_name(self, handler, country_code): - return ipfire.countries.get_name(country_code) + return self.backend.get_country_name(country_code) def format_language_name(self, handler, language): _ = handler.locale.translate