]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/mirrors.py
mirrors: Divide list by country
[ipfire.org.git] / src / backend / mirrors.py
index a49ff8588aa27aab63fd850bcc7fee73004e5b86..5c30a0b0ff20c955cad9257185709348f6d1aeab 100644 (file)
@@ -2,6 +2,7 @@
 
 import datetime
 import logging
+import iso3166
 import math
 import os.path
 import random
@@ -68,6 +69,17 @@ class Mirrors(Object):
                return self._get_mirror("SELECT * FROM mirrors \
                        WHERE hostname = %s", hostname)
 
+       def get_by_countries(self):
+               mirrors = {}
+
+               for m in self:
+                       try:
+                               mirrors[m.country].append(m)
+                       except KeyError:
+                               mirrors[m.country] = [m]
+
+               return mirrors
+
 
 class Mirror(Object):
        def init(self, id, data=None):
@@ -140,6 +152,10 @@ class Mirror(Object):
                if self.location:
                        return self.location.longitude
 
+       @lazy_property
+       def country(self):
+               return iso3166.countries.get(self.country_code)
+
        @property
        def country_code(self):
                return self.data.country_code