]> git.ipfire.org Git - ipfire.org.git/commitdiff
location: Use country name from location database
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Aug 2020 09:36:21 +0000 (09:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 21 Aug 2020 09:36:21 +0000 (09:36 +0000)
https://lists.ipfire.org/pipermail/location/2020-August/000131.html

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/accounts.py
src/backend/base.py
src/backend/fireinfo.py
src/web/__init__.py

index 2c9f460871c03876738cb96a7a26646e69a9b34b..a3c8297bc65e9082a478b4999df748c4833f7b77 100644 (file)
@@ -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):
index c1d4cbb174d4b64300f2eea45250eda81b4cb5bf..00497a298cfa6ce8c3e2d3909ff7e366415f59ad 100644 (file)
@@ -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)
index d02d774f8201a75c7a2c24775cab91e8139ea6ee..d7f78456b9119f97523979168e3f510947069ac2 100644 (file)
@@ -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
 
index 45efa6f031575c9ce3ba55ea66a775168bc5f5df..676e6edb8a60fc3dcd64283401c438fdb4eb5684 100644 (file)
@@ -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